Change CSS element that comes after another

后端 未结 2 438
时光取名叫无心
时光取名叫无心 2021-01-29 10:27

I would like to hover in a.bio change the background .pic to green.

I tried some ways, but it did not work out.

I did not understand th

2条回答
  •  既然无缘
    2021-01-29 10:55

    Move your a.bio in your HTML, because ~ is a sibling selector (however less strict than the +), and use position to stay as it was before moving the HTML:

    Snippet

    .executivo .pic::after {
      background-color: #00845b;
      content: "";
      height: 100%;
      left: 0;
      position: absolute;
      top: 0;
      width: 100%;
      opacity: 0;
      transition: .3s ease-in-out;
    }
    .executivo {
      position: relative;
    }
    .executivo a.bio {
      position: absolute;
      bottom: -20px
    }
    .executivo a.bio:hover ~ .pic img {
      opacity: 0.35;
    }
    .executivo .pic {
      margin-bottom: 45px;
      position: relative;
    }
    .executivo .pic img {
      display: block;
      max-width:100% /*demo*/
    }
    Bio+
    alt text

    title

提交回复
热议问题