我想包裝一個固定位置的子元素在父div沒有它打破了div。我如何使一個固定位置的子div包裝在一個固定寬度的父div內
我希望它的行爲像不是固定的div,但我需要修復子元素並自動換行或調整大小,因爲我將需要它作爲響應站點。所以這就是爲什麼我真的不希望做一個溢出的情況,如果有可能,我會在有固定的div
HTML
<div class="parent">
<div class="child">I am a child div with a 100% width</div>
</div>
<div class="parent">
<div class="child-unfixed">I am a child div that is unfixed (this is the desired affect I am after but using a fixed position if possible)</div>
</div>
CSS
.parent {
background:green;
padding:20px;
margin-bottom:20px;
margin-right:100px;
width:200px
}
.child {
background:yellow;
position:fixed;
width:100%;
text-align:right;
}
.child-unfixed {
background:pink;
}
Here is the JSfiddle右對齊內容
除去母體div的最大寬度? – nCore 2014-12-04 14:35:00
固定位置與絕對位置相似。他們需要頂部,左側,右側,底部。這可能不是你想要的。我會看看這篇關於職位的文章http://css-tricks.com/absolute-relative-fixed-positioining-how-do-they-differ/ – 2014-12-04 14:36:27
和其他人一樣,使用「固定」定位的問題是它將元素從流中取出。因此,你不能將它的父母放在它的周圍,因爲它好像沒有它。 – Marcelo 2014-12-04 14:38:22