V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Can I use?
http://caniuse.com/
Less
http://lesscss.org
Cool Libraries
Bootstrap from Twitter
Jetstrap
51300520
V2EX  ›  CSS

请问这种情况我该怎么实现?

  •  
  •   51300520 · 2017-11-27 17:46:58 +08:00 · 2964 次点击
    这是一个创建于 2313 天前的主题,其中的信息可能已经有所发展或是发生改变。
    有没有办法在不知道父 div 高度的时候,子 div 自动上下顶满父 div,如图



    我要黄色那个 div 上下顶满红色的父 div

    代码是这样

    <div class="clearfix parent" style="background-color: red;">
    <div style="background-color: green;float:left">
    <div>123</div>
    <div>456</div>
    <div>789</div>
    </div>
    <div style="background-color: yellow;float:left">000</div>
    </div>
    目前不知道父窗口高度没设置,如果设 height:100%直接把浏览器顶满了
    6 条回复    2018-01-18 09:10:54 +08:00
    51300520
        1
    51300520  
    OP
       2017-11-27 17:47:22 +08:00
    图怎么不行
    <img src=" ">
    stillsilly
        2
    stillsilly  
       2017-11-27 18:07:55 +08:00
    用绝对定位可以
    ```
    <div class="clearfix parent" style="background-color: red;overflow: hidden;position: relative">
    <div style="background-color: green;float:left">
    <div>123</div>
    <div>456</div>
    <div>789</div>
    </div>
    <div style="background-color: yellow;position: absolute;right: 0;top: 0;bottom: 0;">000</div>
    </div>
    ```
    stillsilly
        3
    stillsilly  
       2017-11-27 18:08:46 +08:00
    不是很懂这个社区怎么用 markdown 格式……
    rabbbit
        4
    rabbbit  
       2017-11-27 18:38:36 +08:00
    <script async src="//jsfiddle.net/AaronBird/v1Lv41fm/embed/"></script>
    rabbbit
        5
    rabbbit  
       2017-11-27 18:39:24 +08:00
    cacocola
        6
    cacocola  
       2018-01-18 09:10:54 +08:00
    什么都不变的情况下,给父级 div 加一个 overflow: hidden;就可以了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5389 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 07:02 · PVG 15:02 · LAX 00:02 · JFK 03:02
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.