样式覆盖
解决的问题:在开发中,我们可以结合自己的实际情况,借助CSS样式的权重来覆盖框架的样式,做出符合本项目要求的样式。
先复习一下相关的CSS知识。
样式的继承
定义:父元素设置了某属性,子属性也会有该属性
以下是会被继承的CSS样式属性
azimuth, border-collapse, border-spacing,caption-side, color, cursor, direction, elevation,empty-cells, font-family, font-size, font-style,font-variant, font-weight, font, letter-spacing,line-height, list-style-image, list-style-position,list-style-type, list-style, orphans, pitch-range,pitch, quotes, richness, speak-header, speaknumeral,speak-punctuation, speak, speechrate,stress, text-align, text-indent, texttransform,visibility, voice-family, volume, whitespace,widows, word-spacing/* 文本相关属性 */font-family, font-size, font-style,font-variant, font-weight, font, letter-spacing,line-height, text-align, text-indent, texttransform,word-spacing/* 列表相关属性 */list-style-image, list-style-position,list-style-type, list-style
样式的覆盖
覆盖规则:
- 根据引入方式确定优先级
优先级由高到低依次为:内联样式 → 内部样式表 → 外部样式表 → 浏览器缺省
- 同一级别的,后写的覆盖先写的
就是文件上代码行号更靠下的优先级更高
- 加有”!important”的样式,优先级最高
即无论哪一种情况,只要在样式上加了important,那么该样式的优先级最高。
- 选择器优先级
在选择器不同的情况下,给每种选择器制定一个权值,计算命中的一个元素的所有选择器的总权值,值高的获胜。
元素选择器: 1
类选择器: 10
ID选择器: 100
内联选择器: 1000
