与 BEM 混淆:如何使用 BEM 处理 body 元素?
Confused with BEM: How to address body element with BEM?
在我最近的项目中,我有这样的 scss 文件:
CSS
body {
background: url('https://...jpg') bottom center no-repeat;
background-size: cover;
min-height: 100vh;
h2 {
font-family: 'Work Sans', sans-serif;
font-weight: 700;
margin-bottom: 24px;
}
[rest of code]
}
现在我正在尝试重写为 BEM。我想解决全身元素。也许这违反了 BEM 原则,我不应该那样做?
<body class="body"></body>
没问题。
实际上通常用于 body
BEM 中的标签使用 class "page"
。所以你会有 <body class="page"></body>
。
听起来更大,因为通常在 body 内部我们有 <header class="header page__header"></header>
、<main class="content page__content"></main>
和 <footer class="footer page__footer"></footer>
。
在我最近的项目中,我有这样的 scss 文件:
CSS
body {
background: url('https://...jpg') bottom center no-repeat;
background-size: cover;
min-height: 100vh;
h2 {
font-family: 'Work Sans', sans-serif;
font-weight: 700;
margin-bottom: 24px;
}
[rest of code]
}
现在我正在尝试重写为 BEM。我想解决全身元素。也许这违反了 BEM 原则,我不应该那样做?
<body class="body"></body>
没问题。
实际上通常用于 body
BEM 中的标签使用 class "page"
。所以你会有 <body class="page"></body>
。
听起来更大,因为通常在 body 内部我们有 <header class="header page__header"></header>
、<main class="content page__content"></main>
和 <footer class="footer page__footer"></footer>
。