Usage: after you clear the div. Does this work correctly?

I have the following HTML:

<div class="selfClear" style="float: left; border: 1px solid black;">
      ...floated stuff in here...
</div>
<span style="margin-top: 10px; border: 1px solid purple;">hello world</span>

I wish there was a 10px gap between the gap and the range, around the edge. But, since the div above floats, it will not look like this. Fix to make sure something clear the DIV. To do this with pure CSS, it seems that one shoudl uses the ": after" method to insert content, which is then set to clear:

.selfClear:after {
content: ".";
display: block;
height: 0px;
clear: both;
visibility: hidden;
}   
.selfClear {
    display: inline-block;
}

However, this is not quite what I think he should do. If I do not include height / visibility styles so that I can see the period when it is inserted, I see that it actually renders inside the div (the black border closes it), and not after the div (so between div and span). I do not understand how this should work?

EDIT:

Here is a simpler example:

CSS:

#theDiv {
border: 1px solid green;
}

#theDiv:after {
content: ".";
}   

#theOtherDiv {
border: 1px solid orange;
}

HTML:

<div id="theDiv">
    Hello
</div>
<div id="theOtherDiv">
   World
</div>

, "Hello", div.

, : after : before , . ?

+3
3

, . div, div, : , .

+3

div "overflow: auto". .

+3

clearfix - , surronding clearfix.

. .

+2

Source: https://habr.com/ru/post/1719739/


All Articles