0

I am having an issue where I cannot get another div to change a css property on hover.

My HTML structure is as follows:

<section class="grid panel-small">
  <div class="col-6 grid-container">
    <div class="col-12 item">
        <a href="#" class="item-area gold">
           <div class="full-row" style="
               background-image: url(https://www.painterartist.com/static/ptr/product_content/painter/2018/bob-ross/gallery/03.jpg)">
           </div>
           <div class="item-description">
                 <div class="item-description-inner">
                     <h2>Title</h2>
                     <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec faucibus sed sem eget efficitur.</p>
                     <div class="feature-btn">
                         View more
                            <i class="fas fa-angle-right"></i>
                      </div>
                </div>
           </div>
        </a>
     </div>
  </div>
 </section>

I want to be able to change item-description-inner to have a positive margin rather than a negative one.

Here is my CSS:

  main#container .grid, main#container .grid .grid-container {
     display: -webkit-flex;
     display: flex;
     -webkit-flex-flow: row wrap;
     flex-flow: row wrap;
  }

   main#container .grid .grid-container .item {
      -webkit-flex: 1 auto;
      flex: 1 auto;
      position: relative;
      overflow: hidden;
   }

    main#container .grid .grid-container .item > .item-area {
         position: relative;
         width: 100%;
         display: block;
         z-index: 1
      }

    main#container .grid .grid-container .item > .item-area > .full-row {
            padding-bottom: 56.222%;
         }

    main#container .grid .grid-container .item > .item-area > .half-row {
        padding-bottom: 112%;
        padding-bottom: calc( 2 * 56.222%);
     }

     main#container .grid .grid-container .item > .item-area .item-description {
        padding-right: 55px;
        padding-bottom: 33px;
        padding-left: 55px;
        position: relative;
        z-index: 2;
     }

        main#container .grid .grid-container .item > .item-area .item-description > .item-description-inner {
           margin-top: -31px;
           margin-bottom: 31px;
        }

.item > .item-area:hover .item-description > .item-description-inner {
    margin-top: 31px;
}

I read this S.O article, and read about ~ and + but none of these selectors are working for me.

cmp
  • 420
  • 5
  • 22

2 Answers2

1

You are facing a specificity issue as the intial selector is more specific than the one with the hover


This one is more specific:

 main#container .grid .grid-container .item > .item-area .item-description > .item-description-inner 

Than this one:

.item > .item-area:hover .item-description > .item-description-inner

To fix the issue you can add more specifity to the second one and make it like this :

main#container .grid .grid-container .item > .item-area:hover .item-description > .item-description-inner 

You can also make the first one less specific

Temani Afif
  • 245,468
  • 26
  • 309
  • 415
-1

try this:

.item-description-inner {
                margin-top: -31px;
                margin-bottom: 31px;
}

.item-description-inner:hover {
                 margin-top: 31px;
}
yinkouya
  • 83
  • 1
  • 11