我有一个像这样的html
<div class="container">
<div class="content-1"></div>
<div class="content-2"></div>
</div>我希望它的工作原理是,如果content-1的高度为480px,则content-2将跟随content-1的高度。我的宽度还不错,但我的身高跟不上。
如何在css中做到这一点?
我的css代码是
.container{
clear: both;
}
.content-1{
width:66.66%;
position: static;
background-image: url("../images/path1");
background-repeat: no-repeat;
background-size: cover;
}
.content-2{
width:33.33%;
position: static;
background-image: url("../images/path2");
background-repeat: no-repeat;
background-size: cover;
}发布于 2016-07-05 13:25:44
.flex-container {
padding: 0;
margin: 0;
list-style: none;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-flex-flow: row wrap;
justify-content: space-around;
}
.flex-item {
background: tomato;
padding: 5px;
width: 200px;
margin-top: 10px;
color: white;
font-weight: bold;
font-size: 3em;
text-align: center;
word-break: break-all;
}<div class="container flex-container">
<div class="content-1 flex-item">orem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s</div>
<div class="content-2 flex-item">1</div>
</div>
发布于 2016-07-05 12:50:37
你能试试这段代码吗:
.container {
display: table;
}
.content-1, .content-2 {
display: table-cell;
}发布于 2016-07-05 12:58:29
在这种情况下,您可以使用CSS3 Flexbox。container类将具有display:flex,并且所有的子类都将设置为相同的高度。
.container {
display:flex;
}
.content-1 {
border:1px solid #000000;
width:50%;
height:480px;
}
.content-2 {
border:1px solid #ff0000;
width:50%;
}<div class="container">
<div class="content-1">Content 1</div>
<div class="content-2">Content 2</div>
</div>
https://stackoverflow.com/questions/38195295
复制相似问题