web选择器

1基本选择器

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    /* 标签选择器 选中所有的p标签*/
    p{
      color: aqua;
    }
    /* id选择器 */
    #box1{
      color: pink;
    }
    /* 类选择器 */
    .box2{
      color: blueviolet;
    }
    /* 通配符选择器 */
    *{
      background-color:pink;
    }
  </style>
</head>
<body>
  <p>我是一段文字</p>
  <p>我是一段文字</p>
  <div id="box1">我是一个盒子</div>
  <div class="box2">我是一个盒子</div>
</body>
</html>

2.包含选择器

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    /* 子代选择器 选中亲生儿子*/
    .a>li{
      background-color: pink;
    }
    /* 后代选择器 找到后代所有要找的元素*/
    .a li{
      color: aqua;
    }
  </style>
</head>
<body>
  <div>
    <ul class="a">
      <li>1</li>
      <li>1</li>
      <li>1</li>
      <li>1</li>
      <ul>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
      </ul>
    </ul>
  </div>
  
</body>
</html>

3.复合选择器

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    /* 复合选择器 */
   div,
   p,
   span{
    color:red;
   }

  </style>
</head>
<body>
  <div>asdasfaf</div>
  <p>safafewaaf</p>
  <span>rgewgwq</span>
  <ul>
    <li>拆的花朵</li>
  </ul>
</body>
</html>

4.属性选择器

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    input[type="password"]{
      background-color: aquamarine;
    }
    div[id]{
      width: 200px;
      height: 300px;
       background-color: black;
    }
    /* type^="te" 以te开头 */
    input[type^="te"]{
      background-color: aquamarine;
    }
    /* type$="l" 以l结尾*/
    input[type$="l"]{
      background-color: green;
    }
    /* type*="e" type值里包含e的*/
    input[type*="e"]{
      background-color: green;
    }
  </style>
</head>
<body>
  <input type="text"> <br/>
  <input type="password"> <br/>
  <input type="search"> <br/>
  <input type="url"> <br/>
  <input type="number"> <br/>


  <div id="aquamarine">1</div>
  
</body>
</html>

5.伪类选择器

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    a:link{
      color:pink;
    }
    a:visited{
      color:black;
    }
    /* hover 鼠标悬停 */
    a:hover{
      /* 鼠标样式 */
      cursor:cell;
      font-size:40px;
    }
    /* 长按 */
    a:active{
      font-size:70px;
    }
    a:hover+div{
      /* 元素消失 */
      display: none;
    }

    
  </style>
</head>
<body>
  <a href="#">去百度</a>
  <div> </div>
</body>
</html>

结构伪类选择器

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <!-- 父元素 子元素:nth-child(n):父元素第n个子元素  -->
  <style>
    ul li:first-child{
      background-color: pink;
    }
    ul li:last-child{
      background-color: green;
    }
    ul li:nth-child(4){
      background-color: blue;
    }
  </style>
</head>
<body>
  <ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
    <li>6</li>
  </ul>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    ul li:nth-child(2){
      background-color: pink;
    }
    ul li:nth-of-type(2){
      background-color: green;
    }
  </style>
</head>
<body>
  <ul>
    <p>我是一段文字</p>
    <li>1</li>
    <li>2</li>
    <li>3</li>
  </ul>
  
</body>
</html>

6.伪元素选择器

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    ul li::before{
      /* content 必有属性 */
          content: "~";
    }
    ul li::after{
          content: "<";
    }
    /* 表单提示词 */
    input::placeholder{
      color:red;
    }
    /* selection 选中时 */
    ul li:nth-child(4)::selection {
      color: pink;
    }
  </style>
</head>
<body>
  用户名:<input type="text" name="user" value="" placeholder="请输入用户名:" maxlength="4">
 <ul>
  <li>asfafs</li>
  <li>gegsg</li>
  <li>asfafs</li>
  <li>hdrrhd</li>
 </ul>
</body>
</html>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值