为什么Twitter Bootstrap添加:: before和:: after?

时间:2016-10-17 13:04:54

标签: html css twitter-bootstrap pseudo-element

我注意到当我检查使用bootstrap类生成的代码时,CSS中的属性往往会有很多:: after和:: before。下面是一个例子(来自w3schools网站)。

有人可以广泛地解释这些额外属性的设计目标,以及为什么它们似乎出现在几乎所有元素上?

据我所知,他们将所有被排除的元素放入表格元素并添加一个空白的文本空间。我假设这是出于布局目的,但我想更多地了解它的原因。

<!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>

1 个答案:

答案 0 :(得分:-1)

那些::after::before被称为伪元素。它们允许您设置文档的某些部分的样式。

请查看以下链接供您参考。

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/