css中的各种选择器的用法

/*标签选择器*/
		div{
            width: 100px;
            height: 100px;
            background: cornflowerblue;
        }
给所有的指定标签设定样式
缺点:会产生冲突
/*class选择器*/
		.public_div{
            width:100%;
        }
        .side{
            width:1000px;
        }
<div id="main" class="public_div side"></div>
side中的width会覆盖public_div中的width
/*id选择器*/
<style>
        #top{
            width:100%;
            height: 32px;
            background:yellow;
        }
        #head{
            width:100%;
            height:100px;
            background:greenyellow;
        }
</style>
<div id="top"></div>
<div id="head"></div>
可以给网页划分结构,但一般给js使用
/*伪类选择器*/
		a:hover{
            color:yellow;
            /*移入*/
        }
        a:link{
            /*一般,清除浏览器缓存时才能看到*/
            color:turquoise;
        }
        a:active{
            /*点击时*/
            color:red;
        }
        a:visited{
            /*访问过(点击过)*/
            color:brown;
        }
/*群组选择器*/

        #head{
            height:100px;
            background:greenyellow;
        }
        #nav{           
            height:130px;
            background: yellow;
        }
        /* #main{           
            height:1000px;
            background:rosybrown;
        } */
        .main{
            height: 1000px;
            background: rosybrown;
        }
        #footer{           
            height:110px;
            background:salmon
        }
        #head,#nav,#footer,.main,p{
            width:1000px;
        }
        p{
            height: 100px;
            background: red;
        }
    
    <div id="head"></div>
    <div id="nav"></div>
    <div class="main"></div>
    <div id="footer"></div>
    <p></p>
		给原有的id选择器,标签选择器和class选择器增加属性
/*通配符选择器*/
		*{
            margin:0px;
            padding:0px;
        }
/*属性选择器*/
		input[type="text"]{
            background:yellowgreen;
        } 
/*包含选择器*/
	div p{
            width:100px;
            height:100px;
            background:purple;
            color:white;
        }
div div p{
            width:100px;
            height:100px;
            background:purple;
            color:white;
        }
包含选择器另一种用法

	#hourse #room .desk p{
            color:white;
    }
	/*#hourse p{
            color:white;
    }*/
	也可
	<div id="hourse">
        <span id="room">
            <div class="desk">
                <p>Powerful</p>
            </div>
        </span>
    </div>

包含选择器可以准确定位元素
/*child选择器*/
		input:first-child{
            background:lawngreen;
        }
        input:last-child{
            background:lightcoral;
        }
		input[name="username"]:last-child{
            background: lightcoral;
        }

有不全面的地方欢迎大家给出指导,希望能给新手带来帮助

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值