prioritize one style over another - zilongxuan001/LearnFreecode GitHub Wiki
在CSS中,class的优先级,会高于body的优先级。
样式如下:
<style>
body {
background-color: black;
font-family: Monospace;
color: green;
}
.pink-text{
color: pink;
}
</style>
<h1 class="pink-text">Hello World!</h1>
classpink-text
设置字体为粉色,body设置字体颜色为绿色,由于class的优先级比较高,h1的颜色为粉色。
浏览器显示如下
Basic CSS: Prioritize One Style Over Another | Learn freeCodeCamp