html - 'left' - 'right' - 'bottom' - 'top' 属性使用哪个 bem 单位?
问题描述
我坚持根据 BEM 方法对 CSS进行放置left
和属性。top
我的结构是
<body class="page-content">
<div class="page-content__calculator-container page-content__calculator-container_shift_left calculator-container">
<div class="calculator_container__button calculator_container__button-close"></div>
<div class="calculator-container __content calculator-content">
</div>
</div>
</body>
<style>
.page-content__calculator-container {
position: fixed;
top: 5vh;
left: 3vw;
}
.page-content__calculator-container_shift_left {
left: -3vw;
}
在某些情况下,使用 js 逻辑我将为page-content__calculator-container_shift_left
重新定位元素添加类。
在 BEM 文档中
在带有 BEM 的 CSS 中,负责外部几何形状和定位的样式是通过父块设置的。
Bem 建议使用page-content__calculator-container
- 进行定位。但是,如果我想用 js 类重新定位这个元素,我需要用当前块元素替换
page-content__calculator-container-repositioned
还是需要添加修饰符
page-content__calculator-container_shift_left
- 然后在修饰符 CSS 中使用left
和top
CSS 属性?但是修饰符不需要用于定位。如果我使用修饰符,那么我的top
和left
属性将同时 inpage-content__calculator-container
和 in page-content__calculator-container_shift_left
。
在这种情况下使用什么?也许我想错了吗?
解决方案
答案取决于您项目的语义。
但常见的答案是您不需要将初始实体替换为page-content__calculator-container-repositioned
. 随意添加修饰符,但要注意它们在 CSS 中的顺序:_shift_*
修饰符应该具有优先级,以便它们始终可以覆盖page-content__calculator-container
.
推荐阅读
- c# - 以 STAThread 身份打开新窗口
- laravel - 翻译页面 - 缺少 Route 所需的参数
- razor - .NET Core Razor 页面中的级联下拉菜单(无 MVC/控制器)
- javascript - React Native - 如何使用 StackNavigator 和 DrawerNavigator 管理每页的标题
- c# - 如何创建特定编号的 ListView。WPF 中的列数?
- javascript - 将图像拖放到angularjs的框中
- vba - 如何测试 pdf 是否已打开 - 使用 Excel 宏
- java - 将 ClickListener 分配给第二个布局中的按钮
- json - JSON解析在ruby中没有以相同的顺序转换
- ruby - 从 Ruby 列表中删除/删除备用号码