I want to add clear: both to specific element by using ::after, I expect it to be like this.
.name {
width: 120px;
float: left;
}
.value {
width: 200px;
float: left;
}
.clear {
clear: both;
}
<div>
<div class="name">Name</div>
<div class="value">Value</div>
<div class="clear"></div>
<div class="name">Name</div>
<div class="value">Value</div>
<div class="clear"></div>
</div>
But when I delete empty div and add pseudo element :after to .value it doesn't work as I expect.
.name {
width: 120px;
float: left;
}
.value {
width: 200px;
float: left;
}
.value:after {
content: '';
display: block;
clear: both;
}
<div>
<div class="name">Name</div>
<div class="value">Value</div>
<div class="name">Name</div>
<div class="value">Value</div>
</div>
So why it doesn't work?