博客列表 >2019年7月4日作业(二) -熟悉基本选择器的用法: 属性, 兄弟, 类型, 伪类等

2019年7月4日作业(二) -熟悉基本选择器的用法: 属性, 兄弟, 类型, 伪类等

杜强_上海_315106编程学习
杜强_上海_315106编程学习原创
2019年07月07日 15:49:43894浏览

以下代码为基本选择器的用法: 属性, 兄弟, 类型, 伪类的应用

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="static/css/style2.css">
    <title>Title</title>
</head>
<body>
<ul>
    <li class="bg-green">1</li>
    <li id="bg-blue">2</li>
    <li class="bg-green">3</li>
    <li class="bg-green">4</li>
    <li>5</li>
    <li>6</li>
    <li>7</li>
    <li>8</li>
    <li>9</li>
    <li>10</li>
</ul>

<div>
    <p>大家好</p>
    <li>你好</li>
    <p>家乡好</p>
</div>
<div>
    <p>新闻</p>
    <li>今日新闻</li>
</div>
</body>
</html>
ul{
    margin-top: 0;
    margin-bottom: 0;
    padding-left: 0;
    border: 1px solid red;

}

ul li{
    list-style: none;
    width: 40px;
    height: 40px;
    background-color: beige;
    border: 1px solid green;
    text-align: center;
    line-height: 40px;
    border-radius: 50%;
    display: inline-block;
    margin-left: 5px;
    box-shadow: 2px 2px 2px #888;
}
#bg-blue {
    background-color: rosybrown;
}

.bg-green{
    background-color: #888888;
}

li[id]{
    border: 1px solid red;
}
#bg-blue,.bg-green{
    border: 2px solid royalblue;
}

#bg-blue + .bg-green{
    background-color: yellow;
}

.bg-green ~ *{
    background-color: royalblue;
}

ul :first-child{
    background-color: red;
}
ul :nth-child(6){
    background-color: beige;
}
ul :nth-last-child(2){
    background-color: red;
}

ul li:first-of-type{
    background-color: rosybrown;
}

ul li:nth-of-type(7){
    background-color: green;
}
/*nth-child 关注的是位置*/

div :nth-child(2){
    background-color: green;
}

/*div:first-of-type :nth-child(3){*/
    /*background-color: red;*/
/*}*/

p:nth-of-type(2){
    background-color: blue;
}

以上代码执行结果截图

0704-2.png

总结:学习完基本选择器的用法: 属性, 兄弟, 类型, 伪类等应该注意:

各种选择器的具体用法

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议