拓冰建站拓冰建站
首页 / 资讯中心 / 正文

HoRain云--CSS 分组 和 嵌套 选择器

分组选择器在样式表中有很多具有相同样式的元素。h1 { color:green; } h2 { color:green; } p { color:green; }为了尽量减少代码你可以使用分组选择器。每个选择器用逗号分隔。在下面的例子中我们对以上代码使用分组选择器实例h1,h2,p { color:green; }嵌套选择器它可能适用于选择器内部的选择器的样式。在下面的例子设置了四个样式p{ }: 为所有p元素指定一个样式。.marked{ }: 为所有classmarked的元素指定一个样式。.marked p{ }: 为所有classmarked元素内的p元素指定一个样式。p.marked{ }: 为所有classmarked的p元素指定一个样式。实例p { color:blue; text-align:center; } .marked { background-color:red; } .marked p { color:white; } p.marked{ text-decoration:underline; }
分享:

看完干货,该让你的企业上线了

免费需求沟通 · 48 小时内出具建站方案 · 河南本地可上门