博主信息
博文 16
粉丝 1
评论 0
访问量 17221
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
2019年7月4日作业(二) -熟悉基本选择器的用法: 属性, 兄弟, 类型, 伪类等
杜强_上海_315106编程学习
原创
1044人浏览过

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

<!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举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学