随笔 - 139  文章 - 0 评论 - 0 阅读 - 33825
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

1、伪类选择器

伪类选择器一般会用在超链接a标签中,使用a标签的伪类选择器,我们一定要遵循"爱恨准则" LoVe HAte

复制代码
/*没有被访问的a标签的样式*/
.box ul li.item1 a:link{
    
    color: #666;
}
/*访问过后的a标签的样式*/
.box ul li.item2 a:visited{
    
    color: yellow;
}
/*鼠标悬停时a标签的样式*/
.box ul li.item3 a:hover{
    
    color: green;
}
/*鼠标摁住的时候a标签的样式*/
.box ul li.item4 a:active{
    
    color: yellowgreen;
}
复制代码

2、隔行选择器nth-child()

复制代码
/*选中第一个元素*/
div ul li:first-child{
    font-size: 20px;
    color: red;
}
/*选中最后一个元素*/
div ul li:last-child{
    font-size: 20px;
    color: yellow;
}

/*选中当前指定的元素  数值从1开始*/
div ul li:nth-child(3){
    font-size: 30px;
    color: purple;
}

/*n表示选中所有,这里面必须是n, 从0开始的  0的时候表示没有选中*/
div ul li:nth-child(n){
    font-size: 40px;
    color: red;
}

/*偶数*/
div ul li:nth-child(2n){
    font-size: 50px;
    color: gold;
}
/*奇数*/
div ul li:nth-child(2n-1){
    font-size: 50px;
    color: yellow;
}
/*隔几换色  隔行换色
     隔4换色 就是5n+1,隔3换色就是4n+1
    */

div ul li:nth-child(5n+1){
    font-size: 50px;
    color: red;
}
复制代码

例子:

复制代码
<style>
    table{
        border:1px solid;
        width:300px;
    }
    tr:nth-child(2n){
        background-color: #f00;
    }
    td{
        border: 1px solid;
    }
</style>
复制代码

</style>        
ul li:nth-child(2n){
   color: red
}
</style>

3、伪元素选择器

复制代码
/*设置第一个首字母的样式*/
        p:first-letter{
            color: red;
            font-size: 30px;

        }
        
/* 在....之前 添加内容,这个属性使用不是很频繁,仅作了解,使用此伪元素选择器一定要结合content属性*/
        p:before{
            content:'tom';
        }
        
        
/*在....之后 添加内容,使用非常频繁 通常与咱们后面要讲到布局有很大的关联(清除浮动)*/
        p:after{
            content:'&';
            color: red;
            font-size: 40px;
        }
复制代码

 

posted on   longfei2021  阅读(105)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
点击右上角即可分享
微信分享提示