我想将div内的DIV-Container拉伸到100%的高度。我想要拉伸的DIV-Container在里面有一个图像
<img src="http://thisisatestforstack.com/image.png"/>
我还想在之后垂直居中。我准备了一张让我的愿望更清晰的照片:
这是我的代码:
<div id="master">
<div id="text" style="width: 60%; float: left;">
This is an example.<br/>
This is an example.<br/>
This is an example.<br/>
This is an example.<br/>
This is an example.<br/>
This is an example.<br/>
This is an example.<br/>
This is an example.<br/>
This is an example.<br/>
This is an example.<br/>
This is an example.<br/>
This is an example.
</div>
<div id="image" style="width: 40%; float: left;">
<img src="http://thisisatestforstack.com/image.png"/>
</div>
</div>
答案 0 :(得分:3)
使用flexbox
布局,您可以实现:
#master {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
}
#text {
-webkit-box-flex: 1;
-webkit-flex: 1;
-ms-flex: 1;
flex: 1;
}
#image {
-webkit-box-flex: 1;
-webkit-flex: 1;
-ms-flex: 1;
flex: 1;
}
.item-top {
width: 60%;
float: left;
-webkit-align-self: flex-start;
-ms-flex-item-align: start;
align-self: flex-start;
}
<div id="master">
<div id="text" class="item-top">
This is an example.
<br/>This is an example.
<br/>This is an example.
<br/>This is an example.
<br/>This is an example.
<br/>This is an example.
<br/>This is an example.
<br/>This is an example.
<br/>This is an example.
<br/>This is an example.
<br/>This is an example.
<br/>This is an example.
</div>
<div id="image" style="width: 40%; float: left;">
<img src="https://www.google.co.in/logos/doodles/2016/teachers-day-2016-india-6215218130583552-res.png" />
</div>
</div>
答案 1 :(得分:0)
尝试使用vertical-align: middle;
图片div。