CSS3选择器是一种强大的工具,它允许你根据HTML元素的属性、结构和状态来定位和样式化元素。以下是一些常用的CSS3选择器及其使用方法:
p {
color: red;
}
.classname {
font-weight: bold;
}
#idname {
background-color: yellow;
}
* {
margin: 0;
padding: 0;
}
[type] {
border: 1px solid black;
}
[type="text"] {
background-color: lightblue;
}
[type*="text"] {
font-style: italic;
}
[type^="submit"] {
color: green;
}
[type$="button"] {
font-weight: bold;
}
div p {
color: blue;
}
div > p {
color: red;
}
h1 + p {
font-size: 20px;
}
h1 ~ p {
font-size: 16px;
}
a:link { /* 未访问的链接 */ }
a:visited { /* 已访问的链接 */ }
a:hover { /* 鼠标悬停时的链接 */ }
a:active { /* 被点击的链接 */ }
input:focus { /* 获得焦点的输入框 */ }
input:invalid { /* 无效的输入框 */ }
:first-child { /* 第一个子元素 */ }
:last-child { /* 最后一个子元素 */ }
:nth-child(n) { /* 第n个子元素 */ }
:nth-of-type(n) { /* 第n个特定类型的子元素 */ }
p::before { content: "Note: "; }
p::after { content: "."; }
p::first-letter { font-size: 200%; }
p::first-line { line-height: 1.5; }
div p {
color: blue;
}
div > p {
color: red;
}
h1 + p {
font-size: 20px;
}
h1 ~ p {
font-size: 16px;
}
[type="text"] {
background-color: lightblue;
}
[type*="text"] {
font-style: italic;
}
[type^="submit"] {
color: green;
}
[type$="button"] {
font-weight: bold;
}
a:hover::after {
content: " (visited)";
}
通过熟练掌握这些选择器,你可以更精确地控制网页的样式和布局。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。