在CSS中,有两种选择器:ID选择器和类选择器。/* ID选择器 */ #header { background-color: blue; height: 100px; } /* 类选择器 */ .m
在CSS中,有两种选择器:ID选择器和类选择器。
/* ID选择器 */ #header { background-color: blue; height: 100px; } /* 类选择器 */ .menu { list-style: none; padding: 0; margin: 0; background-color: gray; }
ID选择器使用“#”符号来指定某个元素的ID属性,只能用于标识唯一的元素。在上面的例子中,我们给ID为“header”的元素定义了蓝色的背景颜色和高度为100像素。
类选择器使用“.”符号来指定某个元素的类属性,可以用于标识多个元素。在上面的例子中,我们给所有类为“menu”的元素定义了无序列表样式、零边距和灰色背景色。
ID选择器和类选择器的使用经常会被混淆。一般来说,ID选择器用于标识特定的元素,类选择器用于标识一组元素。
粉丝
0
关注
0
收藏
0