【问题标题】:override parent overflow:hidden with child overflow:visible覆盖父溢出:用子溢出隐藏:可见
【发布时间】:2014-04-19 09:00:44
【问题描述】:

我有一个标题,它是导航和徽标的父级。我已将父级设置为溢出:隐藏,因此我能够将 margin-top 添加到导航以使其位于底部。但是,它也会剪辑徽标 div。我正在尝试关注这个问题...Overriding overflow: hidden

因此尝试将徽标设置为溢出:可见,但这也不起作用。除了徽标不在父容器中之外,我不确定其他任何解决方案。

这是我的代码

CSS:

.container {
width: 960px;
margin:0 auto;
background-color: blue;
}

header {
height: 100px;
background-color: #001D5D;
position: relative;
overflow: hidden;

}

#logo {
height:100px;
width:100px;
z-index:10;
top:0px;
position: absolute;
overflow: visible;
}

nav {
    background-color:#1CCEAE;
    margin-top:63px; 
}

nav ul {
width:100%;
line-height: 37px;
    text-align:right;
    background-color:#1CCEAE; 

 }

ul li {
display: inline-block;
margin-right: 20px;
}

ul li a {
text-decoration: none;
font-size: 1em;
color:white;    
}

这是一个小提琴 http://jsfiddle.net/XS3Zs/

【问题讨论】:

    标签: html css overflow parent-child


    【解决方案1】:

    将width:100% 删除为ul 或将padding 重置为0 为ul。

    <ul> 并不真正需要width:100%;,因为它是一个block 元素,它将使用所有width 可用。宽度设置为100% 可能太多了。不会估计边框、边距和内边距。

    【讨论】:

    • 好的,但我将如何让徽标延伸到导航框之外?由于存在溢出:隐藏应用于父标题。看来导航栏需要这个属性。
    • 那么它应该在底部的绝对位置导航:0; jsfiddle.net/XS3Zs/3 所以标题随着徽标的高度而增长。
    • 好吧,我以前也有过这样的情况,但我试图找到绝对定位的其他替代方案,我想这是我会尝试的唯一解决方案。
    【解决方案2】:

    UL 元素默认具有padding-left:40px;,因此如果将其设置为 0 就可以了。

    我更新了你的[FIDDLE]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-29
      • 2015-04-17
      • 2011-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多