7

I've noticed that when I inspect code made with bootstrap classes, there tends to be lots of ::after and ::before properties in the CSS. An example is below (from w3schools site).

Could someone please explain in broad terms what these extra properties are designed to achieve, and why they seem to appear on almost all elements?

From what I can tell, they are making all excluded elements into table elements and adding an empty space of text. I assume this if for layout purposes, but I'd love to learn more about the reasons it's done.

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h1>Grid</h1>
  <p>This example demonstrates a 50%/50% split on small, medium and large devices. On extra small devices, it will stack (100% width).</p>
  <p>Resize the browser window to see the effect.</p>
  <div class="row">
    <div class="col-sm-6" style="background-color:yellow;">
      Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.<br>
      Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
    </div>
    <div class="col-sm-6" style="background-color:pink;">
      Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto.
    </div>
  </div>
</div>

</body>
</html>
Minal Chauhan
  • 6,025
  • 8
  • 21
  • 41
Robin Andrews
  • 3,514
  • 11
  • 43
  • 111
  • 2
    As far as I know, I think Bootstrap uses the pseudo-elements as a `clearfix`. See this link http://stackoverflow.com/questions/211383/what-methods-of-clearfix-can-i-use/1633170#1633170. See if it helps. – Aakash Thakur Oct 17 '16 at 13:17
  • I'm not sure how this question is a duplicate of the suggested question. Perhaps as a related question that might provide more insight, the other answer is useful, once readers know that the pseudo elements in Bootstrap have something to do with clearfix. – Robin Andrews Oct 17 '16 at 14:51

1 Answers1

-1

Those ::after and ::before are called pseudo elements. They allow you to style certain part of a document.

Please find the below links for your reference.

https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-elements https://developer.mozilla.org/en-US/docs/Web/CSS/::after https://css-tricks.com/almanac/selectors/a/after-and-before/

Kishore Kumar
  • 12,675
  • 27
  • 97
  • 154
  • 5
    The OP is asking why those elements are added by Bootstrap so much as well, you're just giving a super simple explanation and providing some links. Could you perhaps elaborate further on why Bootstrap adds so many of these pseudo classes? – erol_smsr Nov 13 '17 at 11:09