0

This is the definition of bootstrap 4's clearfix,

.clearfix::after {
    display: block;
    clear: both;
    content: "";
} 

I understand what clear does but not the other two.

Why do we need to add an empty string and make it block?

I've sometimes seem display set to table as well, what does that do?

nshunz
  • 253
  • 1
  • 11

1 Answers1

0

content: ""; means that you are forcing the clearfix element to have empty content. It is similar to the difference between 0 and null— without the empty content, it defaults back to content:none; which is not what we want here, as it won’t apply the style.

Similarly, the default value of the :before or :after pseudo-elements is actually display: inline. Giving them block is what will render them in the desired place.

Sujan Sundareswaran
  • 2,324
  • 2
  • 11
  • 25