设置容器的响应高度,同时垂直居中内容



我正在尝试解决当有人最小化浏览器窗口时容器的高度应该响应的问题。该容器中的内容也应保持真实中心。

以下是我目前在CodePen中的内容:http://codepen.io/anon/pen/PNZzoe

容器是包含一些文本的蓝色框。调整浏览器窗口大小时,蓝色框应与虚拟图像的高度相同。

提前感谢您的帮助!

CodePen 中的代码:

.HTML

<html>
<head>
</head>
<body>
  <div class="grid_12 alpha omega" id="LLcontentCont">
    <!-- Row 1 -->
    <div class="LLrow" id="LLrow1">
      <div class="LLcontent">
        <div class="grid_4 LLFR alpha">
          <div class="LLtext">
            <h3>HEADER</h3>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam hendrerit tristique sem, dictum ornare lectus.</p>
          </div>
        </div>
        <div class="grid_8 omega">
          <a href="" title=""><img src="http://dummyimage.com/868x500/00e1ff/000.gif&text=dummy+image" alt=""></a>
        </div>
      </div>
    </div>
    <!-- /Row 1 -->
    <!-- Row 2 -->
    <div class="LLrow" id="LLrow2">
      <div class="LLcontent">
        <div class="grid_8 alpha">
          <a href="" title=""><img src="http://dummyimage.com/868x500/00e1ff/000.gif&text=dummy+image" alt=""></a>
        </div>
        <div class="grid_4 LLFL omega">
          <div class="LLtext">
            <h3>HEADER</h3>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam hendrerit tristique sem, dictum ornare lectus.</p>
          </div>
        </div>
      </div>
    </div>
    <!-- /Row 2 -->
  </div>
</body>
</html>

.CSS

body {
  width: 100%;
  background: #ccc;
}
#LLcontentCont {width: 100%;}
#LLcontentCont,
.LLrow,
.grid_4,
.grid_8 {
  float: left;
  display: inline;
  position: relative;
}
.LLrow {
  width: 100%;
  margin: 10px 0 0;
}
.LLcontent {
  min-width: 976px;
  margin: 0 auto;
  max-width: 1200px;
  width: 100%;
}
.LLcontent .grid_4 {
  display: table;
  height: 100%;
  background: #0091ff;
  width: 26%;
}
.LLcontent .grid_8 {
  height: 100%;
  width: 72.3%;
}
.LLcontent .grid_8 img {
  width: 100%;
}
.LLtext {
  display: table-cell;
  vertical-align: middle;
}

删除所有其他显示属性,并将display: flex;交给.LLcontent.LLcontent .grid_4align-items: center; .LLcontent .grid_4将为您服务。

Css:

.LLcontent {
  min-width: 976px;
  margin: 0 auto;
  max-width: 1200px;
  width: 100%;
  display: flex;
}
.LLcontent .grid_4 {
  background: #0091ff;
  width: 26%;
  display: flex;
  align-items: center;
}
.LLcontent .grid_8 {
  width: 72.3%;
}
.LLcontent .grid_8 img {
  width: 100%;
}

工作小提琴

最新更新