子边框低于父边框 [英] Child border goes below parent one

查看:72
本文介绍了子边框低于父边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我注意到一个我无法解释的示例时,我正在查看列表的一些示例.这是我正在查看的网站 http://css.maxdesign.com.au/listamatic/horizo​​ntal05.htm ,这是它的代码:

I was looking at some examples of lists when noticed one example which I couldn't explain. This is website I was looking at http://css.maxdesign.com.au/listamatic/horizontal05.htm and this is code from it:

<div id="navcontainer">
    <ul id="navlist">
        <li id="active"><a href="#" id="current">Item one</a></li>
        <li><a href="#">Item two</a></li>
        <li><a href="#">Item three</a></li>
        <li><a href="#">Item four</a></li>
        <li><a href="#">Item five</a></li>
    </ul>
</div>

#navlist {
    padding: 3px 0;
    margin-left: 0;
    border-bottom: 1px solid #778;
    font: bold 12px Verdana, sans-serif;
}
#navlist li {
    list-style: none;
    margin: 0;
    display: inline;
}
#navlist li a {
    padding: 3px 0.5em;
    margin-left: 3px;
    border: 1px solid #778;
    border-bottom: none;
    background: #DDE;
    text-decoration: none;
}
#navlist li a:link {
    color: #448;
}
#navlist li a:visited {
    color: #667;
}
#navlist li a:hover {
    color: #000;
    background: #AAE;
    border-color: #227;
}
#navlist li a#current {
    background: white;
    border-bottom: 1px solid white;
}

我没有得到的是将父#navlist元素的填充设置为3px,而列表项仍直接置于其边框,例如其填充为0px.当我设置以下内容时:

What I don't get is the padding of parent #navlist element being set to 3px while still list items lay directly to its border like if it has padding of 0px. When I set following:

#navlist {
    padding: 0;
}

列表项的边界位于#navlist元素的边框下方.为什么会这样,是不是应该在#navlist边界上方1px处?我找不到解释这种行为的规则?

borders of list items go below the border of #navlist element. Why is that, shouldn't it then 1px above #navlist border? I cant find rule explaining this behavior?

推荐答案

垂直填充在嵌入式元素上的作用不同.考虑以下示例:

The vertical padding works differently on inline elements. Consider this example:

青色区域表示父元素,黄色区域表示带填充的块/行内元素.请注意,内联元素的顶部和底部填充不会影响父级的高度.如有必要,它会在父级外部渲染.

The cyan area represents parent element while the yellow area represents block/inline element with padding. Notice that the top and bottom padding of the inline element does not affect the height of the parent; it renders outside the parent if necessary.

现在这是埃里克·迈耶(Eric Meyer)的选项卡式导航栏示例的明细:

Now here is a breakdown of the Eric Meyer's tabbed navbar example:

  • 有一个垂直填充为3px的列表
  • 此列表包含一个高14像素的行框,其中包含行内列表项
  • 列表项包含带有3px垂直填充的链接(此填充使选项卡按钮显得更宽,更高和更好)

如上所述,垂直填充不会使线框向下移动,而是会在有意添加的3px填充上方的线框外部绘制.结果是像素完美的标签菜单.

As mentioned above, vertical padding does not move the line box down, instead, the padding draws outside the line box over the 3px padding that was added intentionally. The result is a pixel perfect tab menu.

这篇关于子边框低于父边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆