You can simply solve this by applying a negative margin equal to the width or height of the element.
For an element with a height of 100 pixels, which is located above, you will apply margin-bottom: -100px;
For an element with a height of 100 pixels, which is located below, you apply margin-top: -100px;
For an element with a width of 100 pixels, which is located on the left, you apply margin-right: -100px;
For an element with a width of 100 pixels, which is located on the right, you will use margin-left: -100px;
cut and paste css snippets:
.top { postion:relative; top:-100px; height:25px; margin-bottom:-25px; } .bottom { postion:relative; top:100px; height:25px; margin-top:-25px; } .left { postion:relative; left:-100px; width:25px; margin-right:-25px; } .right { postion:relative; left:100px; width:25px; margin-left:-25px; }
And the code with the reworked example will then:
.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; margin-bottom:-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"> </div>
http://jsfiddle.net/qqXQn/1/
Tschallacka Dec 05 2018-12-12T00: 00Z
source share