我一直在尋找這個問題的範圍很廣,最終在谷歌的第10頁的一些不起眼的論壇上找到了解決方案。解決方法是在答案如何刪除與CSS相對定位元素後出現的空白
發生的問題如下: 在用CSS相對定位一個元素後,我得到了元素的空白處......我不想要空白!
.thetext
{
width:400px;
background:yellow;
border: 1px dashed red;
margin:50px;
padding:5px;
font-weight:bold;
}
.whiteblob
{
position:relative;
top:-140px;
left:70px;
width:200px;
height:50px;
border: 4px solid green;
background:white;
font-size:2.5em;
color:red;
}
.footerallowedwhitespaceinblue
{
height:10px;
background-color:blue;
}
.footer
{
background-color:grey;
height:200px;
}
<div class="thetext"><script type="text/javascript">for(c=0;c<50;c++){document.write("Lorem ipsum dolor est, ");}</script>
</div>
<div class="whiteblob">
buy this!
</div>
<div class="footerallowedwhitespaceinblue">
</div>
<div class="footer">
The whitespace above is way to big! The buy this still takes up space whilst it is moved.
</div>
的jsfiddle:http://jsfiddle.net/qqXQn/
正如你所看到的例子,我想唯一的空白是由由50像素的保證金thetext塊的空白;和藍色的足跡空白的間距(變成藍色使其可見)。 問題是...現在空白太大,因爲「買這個」div仍然佔據了相對定位後的空間。
我該如何解決這個問題?
絕對我在找,謝謝你的回答:-) – olo
這是非常有用的,它正是我需要擺脫我的div下方的空白/填充(位置:相對) – user256604