Change CSS element that comes after another

后端 未结 2 422
时光取名叫无心
时光取名叫无心 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*/
    }
    <div class="executivo">
      <a class="bio" href="#">Bio+</a>
      <div class="pic">
        <img src="//lorempixel.com/1600/900" alt="alt text" />
      </div>
      <div class="title">
        <h3>title</h3>
      </div>
    </div>

    0 讨论(0)
  • 2021-01-29 11:07

    Nex element selector is

    +
    

    And direct decedent is

    >
    

    in css.

    Does this help you answer your question?

    0 讨论(0)
提交回复
热议问题