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

這個例子中, outer 比 container 高出幾個像素, 這個高度差是如何產生的? 如何消除?

  •  
  •   013231 · 2014-05-13 21:23:52 +08:00 · 3786 次点击
    这是一个创建于 3637 天前的主题,其中的信息可能已经有所发展或是发生改变。
    http://jsfiddle.net/6tE9z/

    <div id="outer">
    <div id="container">
    <div id="element">
    some text
    </div>
    </div>
    </div>

    #container {
    display: inline-block;
    position: relative;
    width: 50%;
    }
    #container:after {
    content: '';
    display: block;
    margin-top: 100%;
    }
    #element {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: silver;
    }

    div {
    margin: 0;
    padding: 0;
    }

    #outer {
    background-color: blue;
    }
    3 条回复    2014-12-05 12:28:44 +08:00
    nijux
        1
    nijux  
       2014-05-13 22:22:51 +08:00   ❤️ 2
    http://css-tricks.com/fighting-the-space-between-inline-block-elements/

    #container {
    display: inline-block;
    position: relative;
    width: 50%;
    font-size:14px;
    }
    #container:after {
    content: '';
    display: block;
    margin-top: 100%;
    }
    #element {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: silver;
    }

    div {
    margin: 0;
    padding: 0;
    }

    #outer {
    background-color: blue;
    font-size:0;
    }
    belin520
        2
    belin520  
       2014-05-13 23:33:26 +08:00 via Android
    inline-block产生的
    10yearsme
        3
    10yearsme  
       2014-12-05 12:28:44 +08:00
    @belin520 Hi~我是广志,十年后(10years.me)的运营经理。我刚刚看到你的回答和v2ex上的其他交流,感觉和我们的技术和团队风格都挺合拍 ,希望可以聊聊。十年后是一个基于梦想的社交网络,我们想用它让年轻人的生活更有未来性,网站是去年年末上线的。我们上个月刚拿到创新谷VC百万元天使轮融资,现在在招募Web前端开发的人才。可以加我的微信lgz715314聊聊,交个朋友也不错:)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   920 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 22:25 · PVG 06:25 · LAX 15:25 · JFK 18:25
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.