html - 同时定位一个 id 和一个类

标签 html css

我有两个单独的 HTML 页面:

<!-- in the body of page1.html -->
<div class="foo">
    <!-- content goes here -->
</div>

和:

<!-- in the body of page2.html -->
<div id="bar">
    <!-- some other content goes here -->
</div>

目前我使用一些常见的 CSS 定位这些 div 元素:

.foo {
    width: 680px !important;
}
#bar {
    margin: auto;
    width: 680px !important;
}

是否有更短的(DRY - 不要重复你自己)方法来做到这一点?

最佳答案

你可以这样试试:

.foo, #bar {
  width: 680px !important;
}

关于html - 同时定位一个 id 和一个类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43722746/

相关文章:

html - 表格单元格内的 CSS 100% 宽度滚动条 (overflow-x)

html - CSS使div卡在 Bootstrap 列的底部

jquery - JqG​​rid 排序图标显示不正确

javascript - 在标签中 append div 作为帮助文本。在每个 radio 组及其包装器 div 中

javascript - 停止滚动 anchor 击

html - 从 Twig 模板生成 pdf 文件

javascript - 单击元素获取子隐藏输入字段的值

javascript - 我需要我的 javascript 代码来通过代码块检索 id

javascript - 向表中添加新数据

html - 使用 CSS 在 div 中保留 float 图像