我不时看到这个按字母顺序排列的 css 选择器。为什么有人会使用这样的选择器?它从哪里来的?为什么我们不能只使用 * 选择器
来选择所有?
------更新------
现在看到 2 个答案后,问题变成了遗漏了什么元素,即什么元素不需要标准化?
谢谢。
a, abbr, acronym, address, applet, article, aside, audio, b, big, blockquote, body, canvas,
caption,center, cite,code, dd, del, details, dfn, div, dl, dt, em,embed, fieldset, figcaption,
figure, footer, form, h1, h2, h3, h4, h5, h6, header, hgroup, html, i, iframe, img, ins,
kbd, label, legend, li, mark, menu, nav, object, ol, output, p,pre, q, ruby, s, samp,
section,small, span, strike, strong,sub, summary, sup, table, tbody, td, tfoot, th, thead,
time, tr, tt, u, ul, var, video {
margin:0;
padding:0;
border:0;
font: inherit;
...
}
最佳答案
这称为规范化,每个元素在不同的浏览器中可能具有默认属性,规范化使浏览器更一致地呈现所有元素。
h1,h2,.....,a {
my rules;
}
例如,h1...h5
元素默认有一些 margin
。我们不需要这个 margin
,所以改变它。看这个例子:
h1,h2 {
background-color: orange;
border: 1px solid;
}
.def {
margin: 0;
}
Default without change <b>margin</b>.<i>h1</i> and <i>h2</i> have margin as default:
<h1>Default H1</h1>
<h2>Default H2</h2>
Changed:
<h1 class="def">Default H1</h1>
<h2 class="def">Default H2</h2>
*
选择器,选择所有东西,但我们必须选择需要更改其默认属性的元素。
关于html - 这个按字母顺序排列的 css 选择器是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50459321/