博主信息
博文 20
粉丝 0
评论 0
访问量 17350
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
常用选择器的使用-2019年1月15日23点39分
kszyd的博客
原创
800人浏览过

主要是对集中常用选择器的使用实践:

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="static/css/style01.css">
    <title>CSS常用选择器</title>
</head>
<body>
    <ul>
        <li>1</li>
        <li class="beigg">2</li>
        <li id="beig">3</li>
        <li>4</li>
        <li>5</li>
        <li>6</li>
        <li>7</li>
        <li>8</li>
        <li>9</li>
        <li>10</li>
    </ul>
    <hr>
    <div>
        <p>测试</p>
        <li>测试2</li>
        <p>测试3</p>
    </div>
    <hr>
    <div>
        <p>大写</p>
        <li>大写1</li>
    </div>
    <hr>
    <form action="">
        <label for="email">邮箱</label>
        <input type="email">
        <br>
        <label for="password">密码</label>
        <input type="password">
        <br>
        <input type="radio" id="week" name="save" value="7" checked>
        <label for="week">保存七天</label>
        <input type="radio" id="month" name="save" value="30">
        <label for="month">保存30天</label>
        <br>
        <button>登陆</button>
    </form>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

实例

/* 标签选择器 */
ul {
    border: 1px dashed red;
    margin-top: 0;
    margin-bottom: 0;
    padding-left: 0;
    overflow: hidden;
    padding: 10px;
}

/* 层级选择器 */
ul li {
    list-style-type: none;
    width: 40px;
    height: 40px;
    background-color: lawngreen;
    /* 浮动 */
    float: left;
    border-radius: 50px;
    /* 文本居中 */
    text-align: center;
    line-height: 40px;
    box-shadow: 2px 2px 1px #888;
    margin-left: 10px;
}

/* id选择器 */
#beig {
    background-color: rgb(129, 117, 141);
}

/* class选择器 */
.beigg {
    background-color: tomato;
}

/* 属性(特征)选择器 */
li[id="beig"] {
    border: 3px solid red;
}

/* 伪类 子元素选择器 */
ul :first-child {
    background-color: aquamarine;
}

/* 伪类 类型选择器 */
ul li:last-of-type {
    background-color: blue;
}

/* div子元素 */
div :nth-child(1) {
    background-color: aqua;
}

/*伪类 表单选择器 */
form :enabled {
    background-color:lightcoral;
}

form :checked+* {
    background-color: blueviolet;
}

form :focus {
    background-color: #888;
}
button:hover {
    width: 70px;
    height: 80px;
    background-color: blue;
    color: darkmagenta;
}

form :invalid {
    color: darkviolet;
}

运行实例 »

点击 "运行实例" 按钮查看在线实例

1547625512219067.jpg

 可了解使用几种常用选择器。

批改状态:未批改

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系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+教程免费学