Skip to content Skip to sidebar Skip to footer

Slider Pure CSS => Text Instead Of Bullets Point / Hover On Text To Change Image

I'm trying to do a Pure CSS slider but I tried many options (visibility: hidden;, z-index: 11,22,33..) but I didn't find the right way to make it works. I would like to show a defa

Solution 1:

A pure CSS solution can be easily done with flexbox. Just set the img container as a sibling of the buttons so you can access it with the ~ general sibling combinator, then use flex-basis:100% and flex-wrap:wrap on the container so it occupies a full row, and negative order so it gets visually above the buttons.

.flex-buttons{
  width:100%;
  display:flex;
  flex-wrap:wrap;
}

.flex-buttons button{
  flex:1;
  cursor:pointer;
}


.flex-buttons button:nth-child(1):hover ~ .imgs{
  background:red;
}

.flex-buttons button:nth-child(2):hover ~ .imgs{
  background:green;
}

.flex-buttons button:nth-child(3):hover ~ .imgs{
  background:blue;
}

.flex-buttons button:nth-child(4):hover ~ .imgs{
  background:purple;
}

.flex-buttons button:nth-child(5):hover ~ .imgs{
  background:orange;
}

.imgs{
  order:-1;
  flex-basis:100%;
  height:100px;
  border:2px solid grey;
}
<div class="flex-buttons">
    <button> Image 1 </button>
    <button> Image 2 </button>
    <button> Image 3 </button>
    <button> Image 4 </button>
    <button> Image 5 </button>
    <div class="imgs"></div>
  </div>

Replace the background colors with your imgs and style as needed.


Solution 2:

It works perfectly in the console (without the custom css style I'm working on), but on my website 4th and 5th slide aren't displayed... kind of weird!!

   

.flex-buttons{
  width:100%;
  display:flex;
  flex-wrap:wrap;
	background-image: url('https://www.jacquesgiral.com/wp-content/uploads/jg-photo/0-jacques-giral-photographie-accueil-paris.jpg');
	  height:450px;
	
}

.flex-buttons button{
  flex:1;
  cursor:pointer;
	margin-top:2%;
}


.flex-buttons button:nth-child(1):hover ~ .imgs{
  background-image: url('https://www.jacquesgiral.com/wp-content/uploads/jg-photo/1-archi-deco.jpg');
	

}

.flex-buttons button:nth-child(2):hover ~ .imgs{
  background-image: url('https://www.jacquesgiral.com/wp-content/uploads/jg-photo/2-bijoux-montre.jpg');

}

.flex-buttons button:nth-child(3):hover ~ .imgs{
  background-image: url('https://www.jacquesgiral.com/wp-content/uploads/jg-photo/3-cosmetique.jpg');

}

.flex-buttons button:nth-child(4):hover ~ .imgs{
  background-image: url('https://www.jacquesgiral.com/wp-content/uploads/jg-photo/4-edition.jpg');

}

.flex-buttons button:nth-child(5):hover ~ .imgs{
 background-image: url('https://www.jacquesgiral.com/wp-content/uploads/jg-photo/5-people.jpg');
   

}

.imgs{
  order:-1;
	
  flex-basis:100%;
  height:450px;
	background-size:cover;
	background-repeat: no-repeat;

  
}
<div class="flex-buttons">
    <button> <a class="button-slider" title="Lien vers ARCHI-DÉCO" href="#" rel="bookmark">ARCHI-DÉCO</a> </button>
    <button> <a class="button-slider" title="Lien vers BIJOUX-MONTRE" href="#" rel="bookmark">BIJOUX-MONTRE</a> </button>
    <button> <a class="button-slider" title="Lien vers COSMÉTIQUE" href="#" rel="bookmark">COSMÉTIQUE</a> </button>
    <button> <a class="button-slider" title="Lien vers ÉDITION" href="#" rel="bookmark">ÉDITION</a> </button>
    <button> <a class="button-slider" title="Lien vers PEOPLE" href="#" rel="bookmark">PEOPLE</a> </button>
    <div class="imgs"></div>
  </div>

Post a Comment for "Slider Pure CSS => Text Instead Of Bullets Point / Hover On Text To Change Image"