css之属性选择器

属性选择器

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <style type="text/css">
    .demo a{
      float: left;
      display: block;
      height: 50px;
      width: 50px;
      border-radius: 10px;
      background: blue;
      text-align: center;
      color: gainsboro;
      text-decoration: none;
      margin-right: 5px;
      font: bold 20px/50px Arial;
    }
    /*a[id]{*/
    /*  background: red;*/
    /*}*/
    /*相等*/
    a[id=first]{
      background: yellow;
    }
    /*包含*/
    a[class*="links"]{
      background: red;
    }
    /*以什么开头*/
    a[href^="http"]{
      background: white;
    }
    /*以什么结尾*/
    a[href$=pdf]{
      background: yellow;
    }
  </style>
</head>
<body>
<p class="demo">
  <a href="http://www.baidu.com" class="links item first" id="first">1</a>
  <a  class="links item acitve" target="_blank" title="test">2</a>
  <a href="1.html" class="links item" >3</a>
  <a href="1.html" class="links item" >4</a>
  <a href="1.html" class="links item" >5</a>
  <a href="abc" >6</a>
  <a href="/a.pdf" >7</a>
  <a href="/abc.pdf" class="links item" >8</a>
  <a href="abc.doc" class="links item" >9</a>
  <a href="abc.doc" class="links item list" >10</a>
</p>
</body>
</html>

posted @ 2023-03-01 22:09  King-DA  阅读(19)  评论(0)    收藏  举报