我正在尝试让标头div从其父级继承其宽度。标头div为position: fixed
。父级包含在引导容器中。
但是,正如您在我创建的代码中所看到的那样,它没有正确继承其父级的宽度-它是从某处添加了一些额外的宽度。
这一切都很烦人!任何想法如何解决这个问题?
.category-body {
margin-left: 17% !important;
width: 67%;
background-color: red;
height: 500px;
}
.category-header {
position: fixed;
top: 51px;
width: inherit;
background-color: green;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="category-body">We are in the category-body
<div class="category-header">We are in the category-header</div>
</div>
</div>
问题源于在父级上使用百分比值width
。浏览器似乎对此有问题。(已在Chrome,FF和IE11上测试。)
如果使用像素值,问题将消失。
从另一个答案:
好像静态值(250px)可以通过常规继承传播。而当使用相对值(90%)时,固定div已经被淘汰,现在继承了,它的父级是视口。
在此处了解更多信息:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句