我想包装一个固定位置的子元素在父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