@media screen and (min-width: 768px) {
*{
padding: 0;
margin: 0;
}
.container {
width: 750px;
/* background-color: aqua; */
margin: 0 auto;
}
.container ul li {
float: left;
/* display: inline-block; */
/* list-style: none; */
width: 93.75px;
height: 30px;
background-color: tomato;
}
}
设置了
*{
padding: 0;
margin: 0;
}
但是没有用,仍然有padding
解决:
这里是因为先导入了bootstrapt.js文件,里面有一个预设置的类,类名叫做container
在bootstrapt.js文件里有提前设置过:
.container {
padding-right: 15px;
padding-left: 15px;
margin-right: auto;
margin-left: auto;
}
CSS(层叠样式表)优先级:(大——>小)
- 内联样式:style
- ID 选择器(例如,#example)
- 类选择器 (例如,.example),属性选择器(例如,[type=“radio”])和伪类(例如,:hover)
- 类型选择器(例如,h1)和伪元素(例如,::before)
- 通配选择符(universal selector)(*)关系选择符(combinators)(+, >, ~, ’ ', ||)和 否定伪类(negation pseudo-class)(:not())
- 通配选择符(universal selector)(*)关系选择符(combinators)(+, >, ~, ’ ', ||)和 否定伪类(negation pseudo-class)(:not())对优先级没有影响。(但是,在 :not() 内部声明的选择器会影响优先级)。
- 给元素添加的内联样式 (例如,style=“font-weight:bold”) 总会覆盖外部样式表的任何样式 ,因此可看作是具有最高的优先级。
- 当在一个样式声明中使用一个 !important 规则时,此声明将覆盖任何其他声明。虽然,从技术上讲,!important 与优先级无关,但它与最终的结果直接相关。使用 !important 是一个坏习惯,应该尽量避免,因为这破坏了样式表中的固有的级联规则 使得调试找bug变得更加困难了。当两条相互冲突的带有 !important 规则的声明被应用到相同的元素上时,拥有更大优先级的声明将会被采用。
所以虽然设置了*{通用选择器的样式}却没有用处,因为类选择器已经设置了,会覆盖