我对定位元素有一个讨厌的问题: 所以我有一个孩子,需要有全屏宽度,而不是相对父母的。设置相对父宽度较小时的绝对元素全宽度为100%
body{
padding: 10px;
}
.container{
position:relative;
width: 400px;
border: 1px solid red;
padding: 15px;
}
.panel{
position:relative;
width:200px;
margin: 0 auto;
height:40px;
}
.panel-body{
position: absolute;
width:100%;
}
<div class="container">
<div class="panel panel-warning">
<div class="panel-body">
A Basic Panel
</div>
</div>
</div>
所以问题是如何使panel-body
中的所有其他元素的前面,并从屏幕不从父相对设置宽度100%,但是100%。 The html structure cannot be modified.
'如何将面板主体放在所有其他元素前面,请使用[css z-index](http://www.w3schools.com/cssref/pr_pos_z-index.asp)。至于使一个孩子比它的父母检查更广泛[this](http://stackoverflow.com/questions/5581034/is-there-are-way-to-make-a-child-divs-width-wider-than -the-parent-div-using-css)链接。 –
你可以在'.panel-body'上设置'position:fixed'而不是'absolute'。 –
@MuhammadUsman这将工作,直到你必须滚动 – Keith