Utilisez css pour obtenir un clic pour changer d'effet actif

不使用js,纯css实现点击切换active样式

Les petites étiquettes sont imbriquées dans une boîte parent, disposées horizontalement

html

  <div class="box">
    <a href="#">选项1</a>
    <a href="#">选项2</a>
    <a href="#">选项3</a>
    <a href="#">选项4</a>
    <a href="#">选项5</a>
  </div>

css

  .box{
    
    
      width: 300px;
      height: 300px;
      background-color: #efefef;
      margin: 0 auto;
      display: flex;
      justify-content: space-between;
    }

    .box a {
    
    
      text-decoration: none;
      color: #000;
      display: inline-block;
      height: 20px;
      padding: 10px 0;
      width: 100%;
      text-align: center;
    }

style
insérez la description de l'image ici

Ajouter une pseudo classe

css

    .box a:active,
    .box a:focus {
    
    
      color: #fff;
      background-color: skyblue;
    }

obtenir un effet

insérez la description de l'image ici

Je suppose que tu aimes

Origine blog.csdn.net/zyue_1217/article/details/132361441
conseillé
Classement