Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

css3 选择器

作者:我说°走了就别回来   发布日期:2025-04-17   浏览:122

/* 示例代码:CSS3 选择器 */

/* 1. 属性选择器 */
input[type="text"] {
    border: 1px solid blue;
}

/* 解释:选择所有 type 属性等于 "text" 的 input 元素,并设置边框样式。 */

/* 2. 伪类选择器 :nth-child */
li:nth-child(odd) {
    background-color: #f0f0f0;
}

/* 解释:选择每个 li 元素中奇数位置的元素,并设置背景颜色。 */

/* 3. 伪类选择器 :not */
p:not(.intro) {
    color: red;
}

/* 解释:选择所有不包含 .intro 类的 p 元素,并设置文本颜色为红色。 */

/* 4. 伪元素选择器 ::before 和 ::after */
p::before {
    content: "Before ";
}

p::after {
    content: " After";
}

/* 解释:在每个 p 元素的内容前插入 "Before",在内容后插入 "After"。 */

/* 5. 结构化伪类选择器 :first-child */
ul li:first-child {
    font-weight: bold;
}

/* 解释:选择每个 ul 中的第一个 li 元素,并设置字体加粗。 */

/* 6. 相邻兄弟选择器 + */
h2 + p {
    color: green;
}

/* 解释:选择紧跟在 h2 元素之后的 p 元素,并设置文本颜色为绿色。 */

上一篇:css 横线

下一篇:css 绝对定位居中

大家都在看

css 红色

css文字超长省略号

css 渐变字体

css背景图片等比例缩放

css文字删除线

css 自定义滚动条

css flex gap

css上一个兄弟元素怎么找到

css文字超出隐藏变省略号鼠标上去展示完整

css文字不允许换行

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站