N
N
Nikola242016-11-06 21:22:38
css
Nikola24, 2016-11-06 21:22:38

::after only works on 'content', why?

I tried to test one thing, after two float blocks, set :after with clear:both, but for some reason nothing happens if I add content: "text"; then everything works right away. Why is this happening?

<main class="clear">
    <div class="first"></div>
    <div class="second"></div>
  </main>
  <div class="three"></div>

.first,.second,.three{
    background-color: red;
    display: block;
    width: 50px;
    height: 50px;
    margin: 20px;
  }
  .first{
    float: left;
  }
  .second{
    float: right;
  }
  .three{
    background-color: blue;
  }
  .clear{
    width: 200px;
  }
  main:after{
    clear: both;
  }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Elwen, 2016-11-06
@Nikola24

:before and :after are only used in conjunction with content. To create an empty pseudo element add content: " "orcontent: "\00a0"

K
KlassT, 2016-11-06
@KlassT

css standard

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question