我想把一个元素放在一个内部div的底部(距离底部5像素),这个内部div又在另一个div中,且设置了overflow属性。当内部div比父div大时,滚动条出现。
我还需要将一个按钮放在内部div的底部,使其保持在底部,因此我将div的position属性设置为relative,将按钮的position属性设置为absolute。
当div没有超过外部div时,它能正常工作。但是当它有overflow时,按钮不会停留在它的底部,而是距离外部div底部5像素的位置,并且当我滚动溢出的div时,按钮也会随之滚动。可以在这里看到更明显的效果:
Fiddle link
如何解决这个问题,使得按钮在溢出时始终距内部div底部5像素,并且当文本很短时也距外部div底部5像素?同时,我正在寻找一种解决方案,不需要明确设置按钮上方div部分的高度约为70%,因为我的按钮可能具有可变高度(从20像素到200像素)。非常感谢。
https://dl.dropboxusercontent.com/u/10039660/whatiwant.png
我还需要将一个按钮放在内部div的底部,使其保持在底部,因此我将div的position属性设置为relative,将按钮的position属性设置为absolute。
当div没有超过外部div时,它能正常工作。但是当它有overflow时,按钮不会停留在它的底部,而是距离外部div底部5像素的位置,并且当我滚动溢出的div时,按钮也会随之滚动。可以在这里看到更明显的效果:
Fiddle link
<div class="mainDiv">
<div class="innerDiv">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
<button class="btn">Edit</button>
</div>
</div>
<br>
<div class="mainDiv">
<div class="innerDiv">
<p>Short text.</p>
<button class="btn">Edit</button>
</div>
</div>
.mainDiv {
border: 1px solid green;
width: 200px;
height: 200px;
}
.innerDiv {
border: 1px solid red;
background: lightcoral;
max-height: 200px;
height:100%;
overflow: auto;
position:relative;
}
.btn {
position:absolute;
bottom: 5px;
}
}
如何解决这个问题,使得按钮在溢出时始终距内部div底部5像素,并且当文本很短时也距外部div底部5像素?同时,我正在寻找一种解决方案,不需要明确设置按钮上方div部分的高度约为70%,因为我的按钮可能具有可变高度(从20像素到200像素)。非常感谢。
https://dl.dropboxusercontent.com/u/10039660/whatiwant.png