цель использования :: before как способ создания пространства? - PullRequest
0 голосов
/ 08 декабря 2018

Я недавно видел в Google Material Design использование псевдоэлемента :before для создания вертикального пространства перед заголовками диалогов.

<h2>
  :before { content:''; height: 40px; width:0; display:inline-block; vertical-align: 0 }
  Some Text
</h2>

Вместо padding/margin-top или оболочки с необходимымипространство.Мне любопытно, что за обоснование, возможно, стояло за этим и есть ли польза от этого подхода?

  /* as seen on mdc's alertdialog headings: https://material-components.github.io/material-components-web-catalog/#/component/dialog */

.title {
  /* prefixes & repeat styles removed for easier reading */
  line-height: normal;
  font-family: Roboto, sans-serif;
  -moz-osx-font-smoothing: grayscale;
  -webkit-font-smoothing: antialiased;
  font-size: 1.25rem;
  line-height: 2rem;
  font-weight: 500;
  letter-spacing: .0125em;
  text-decoration: inherit; /* none */
  text-transform: inherit; /* none */
  display: block;
  position: relative;
  flex-shrink: 0;
  box-sizing: border-box;
  margin: 0;
  padding: 0 24px 9px;
  border-bottom: 1px solid transparent;
}

.title:before{
  content:'';
  height:40px;
  width:0;
  display:inline-block; /* is left of the element */
  vertical-align: 0; /* baseline */
}
<h2 class="title">Heading</h2>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...