1

I have an image gallery where as you scroll the four tiled image section appears. After it reveals itself I want the user to be able to hover over each image and for the image that is being hovered over to expand and fill the section.

/* this is the CSS */

   .section .tiles img {
      width: 50%;
      float: left;
      height: auto;
      opacity: 0.7;
      -moz-transition: 0.3s ease-in-out all;
      -o-transition: 0.3s ease-in-out all;
      -webkit-transition: 0.3s ease-in-out all;
      transition: 0.3s ease-in-out all;
    }

      .section .tiles img:hover {
        cursor: pointer;
        opacity: 1;
      }

<!-- here is the HTML -->
        
        <div class="right tiles">
           <img src="../badAppleimg/colorPalatteDarkRed.jpg" />
           <img src="../badAppleimg/colorPaletteOffWhite.jpg" />
           <img src="../badAppleimg/colorPalatteCream.jpg" />
           <img src="../badAppleimg/colorPaletteRed.jpg" />
        </div>

Right now the Width is set to 50% and height at auto. If I put to set the width to 100% and height auto when you hover over it only position 1 expands to fill the section. So my solution was to have each image re position to position 1 in order to expand and fill the section. Not sure if thats the easiest solution. Right now position 1 seems to be the only position that correctly fills the section. the other positions either glitch or only fill have the section.

3
  • It can hardly work this way, if you use float- making one element "bigger", will make the following ones move to undesired positions. If you don't want any animation for this, but just "hard" switch from that 2x2 image grid to one single image - then you could just completely hide all the other images, when the parent container gets hovered (.section .tiles:hover img:not(:hover) { display: none; })
    – CBroe
    Commented Sep 13, 2023 at 7:13
  • @CBroe I think I see what you are trying to do looks like only the top left corner image stays when I hover over it and the other images disappear but if I hover over image 2 in the top right corner or any other position all 4 images disappear. I think you are tying to make it where the image that gets hovered stays but the rest don't display? Commented Sep 13, 2023 at 19:22
  • I meant like this: jsfiddle.net/p03b2vza
    – CBroe
    Commented Sep 14, 2023 at 5:50

0

Browse other questions tagged or ask your own question.