You can achieve the result you are looking for by using css to insert a dummy element. This method means you do not need to position your <div class="abs">
within the middle of the content of that div. This may be of use if you are not able to control what the content is (in the case of content being entered in a cms).
HTML:
<div class="all">
<div class="abs">ABS</div>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
</div>
CSS:
.all {
display: block;
width: 250px;
min-height: 180px;
height: auto;
position: relative;
background: #fa65fc;
}
.all:before {
content: "";
float: right;
height: 80px;
width: 0;
}
.abs {
clear: both;
float: right;
width: 50px;
height: 100px;
background: #4542df;
}
Link to JSFiddle.
.all:before
inserts a dummy element which is floated right, no width and 80px high at the very beginning of <div class="all">
.
Because .abs
is floated right (but not positioned absolute), it will now try and stay floated right at the top of the div. Adding clear: both
forces it drop below any other floated elements, so it ends up moving 80px down to clear the dummy float before it.