易学问答
  • 首页
  • 话题
  • 动态
  • 专家
  • 文章
  • 作者
  • 公告
  • 更多
    • 积分规则
登录 或 注册
  • 首页
  • 话题
  • 动态
  • 专家
  • 文章
  • 作者
  • 公告
  • 积分规则
 发表新帖
发表新帖

HTML/CSS set div to height of sibling

后端 未结
关注
 10  2163
南旧
南旧 2020-12-03 00:43

I have 2 div\'s contained in a third. One of the contained div\'s is floated left, the other floated right. I would like the 2 sibling div\'s to always be at the same heig

10条回答
  •  萌比男神i
    萌比男神i (楼主)
    2020-12-03 00:59

    If you know which of the inner div's you want to set the height of the page layout you can do something like this: http://codepen.io/anon/pen/vOEepW

    Setting the containing div to position: relative and then setting one of the inner divs to position absolute allows the other, "un-styled" div to effectively control the height of both.

    .container {
      position: relative;
    }
    .main-content {
      width: 80%;
      margin-left: 20%;
      height: 300px;
      background-color: red;
    }
    .secondary-content {
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      width: 20%;
      overflow-y: scroll;
    }
    

    It is also possible to do this, and perhaps easier using flexbox, but that has some browser support issues.

    0 讨论(0)
    查看其它10个回答
    提交评论

    •  加载中...
 看不清?
提交回复
热议问题