首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何让CSS中的高度响应?

如何让CSS中的高度响应?
EN

Stack Overflow用户
提问于 2016-07-05 12:42:16
回答 6查看 38.4K关注 0票数 1

我有一个像这样的html

代码语言:javascript
复制
<div class="container">
   <div class="content-1"></div>
   <div class="content-2"></div>
</div>

我希望它的工作原理是,如果content-1的高度为480px,则content-2将跟随content-1的高度。我的宽度还不错,但我的身高跟不上。

如何在css中做到这一点?

我的css代码是

代码语言:javascript
复制
.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;
}
EN

回答 6

Stack Overflow用户

回答已采纳

发布于 2016-07-05 13:25:44

代码语言:javascript
复制
.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;
}
代码语言:javascript
复制
<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>

票数 -1
EN

Stack Overflow用户

发布于 2016-07-05 12:50:37

你能试试这段代码吗:

代码语言:javascript
复制
.container {
    display: table;
}
.content-1, .content-2 {
    display: table-cell;
}
票数 0
EN

Stack Overflow用户

发布于 2016-07-05 12:58:29

在这种情况下,您可以使用CSS3 Flexboxcontainer类将具有display:flex,并且所有的子类都将设置为相同的高度。

代码语言:javascript
复制
.container {
  display:flex; 
 
}

.content-1 {
  border:1px solid #000000;
  width:50%;
   height:480px;
  }

.content-2 {
  border:1px solid #ff0000;
  width:50%;
  }
代码语言:javascript
复制
<div class="container">
   <div class="content-1">Content 1</div>
   <div class="content-2">Content 2</div>
</div>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38195295

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档