本文介绍了身体和*之间的差异在css的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之间的区别

  body {
background:#4b4b4b;
}

  * {
background:#4b4b4b;
}

其优先级较高?

body 选择器具有更高的优先级,但 * 选择器应用更广泛,因此在< body> foo< p> bar< / p>< / body> 正文选择器将确定文本的背景 foo ,但 * 选择器将确定< p> 元素。



请注意,许多浏览器会在 < body> 包括其边距和滚动条,因此 * 选择器也可以确定该区域的颜色。


what is the difference between

body{
  background: #4b4b4b;
}

and

*{
    background: #4b4b4b;
 }

which has higher priority?

解决方案

The body selector has higher priority, but the * selector applies more broadly, so in <body>foo<p>bar</p></body> the body selector will determine the background of the text foo, but the * selector will determine the background of the <p> element.

Note, also that many browsers create an element around the <body> that includes its margins and scrollbars, so the * selector may also determine the color of that region.

这篇关于身体和*之间的差异在css的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 22:15