How to trigger two hovers when hovering over single element CSS

James Freight

I want to hover both classes col-md-3 and overlay-text via one hover. When hover over image I want to trigger second hover, in this case over text.

If CSS somehow could support if/else statements, I would wrote if col-md-3 is hovered then hover overlay-text.

.overlay-text {
  background-color: #79b13c;
  color: white;
  z-index: 50;
  position: absolute;
  bottom: 0px;
  width: 270px;
  text-align: center;
  font-size: 1.4rem;
  font-weight: 600;
  -webkit-transition: background-color 0.5s ease-in-out, font-size 0.5s;
  -moz-transition: background-color 0.5s ease-in-out, font-size 0.5s;
  -o-transition: background-color 0.5s ease-in-out, font-size 0.5s;
  transition: background-color 0.5s ease-in-out, font-size 0.5s;
}

.overlay-text:hover {
  content: "";
  background-color: #328ba6;
  cursor: pointer;
  transition: ease-in-out 0.5s, font-size 0.5s;
  line-height: 2;
  font-size: 1.5rem;
}

.overlay-text:hover::after {
  transition: ease-in-out 1s, font-size 1s;
}

.col-md-3 {
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  overflow: hidden;
  position: relative;
  padding-left: 5px;
  padding-right: 5px;
}

.col-md-3 img {
  -moz-transition: all 0.3s;
  -webkit-transition: all 0.3s;
  transition: all 0.3s;
}

.col-md-3 img:hover {
  -webkit-transform: translate3d(0, -10%, 0);
  transform: translate3d(0, -10%, 0);
  cursor: pointer;
}

.overlay-text-blank {
  text-align: center;
  font-size: 1.8rem;
  font-weight: 600;
  vertical-align: middle;
}
<div class="container">
  <div class="row tiles">
    <div class="col-md-3">
      <img alt="text" src="https://www.codeproject.com/KB/GDI-plus/ImageProcessing2/img.jpg" class="img-fluid">
      <div class="overlay-text">Custom text</div>
    </div>
  </div>
</div>

FiddleJS Demo: https://jsfiddle.net/57nvbfud/5/

Anzil khaN

You have two options here:

First one change hover to img:hover + .overlay-text

Second one is change both hover in col-md-3:hover.

.overlay-text {
	background-color: #79b13c;
	color: white;
	z-index: 50;
	position: absolute;
	bottom: 0px;
	width: 270px;
	text-align: center;
	font-size: 1.4rem;
	font-weight: 600;
	-webkit-transition: background-color 0.5s ease-in-out, font-size 0.5s;
	-moz-transition: background-color 0.5s ease-in-out, font-size 0.5s;
	-o-transition: background-color 0.5s ease-in-out, font-size 0.5s;
	transition: background-color 0.5s ease-in-out, font-size 0.5s;
}

.col-md-3:hover .overlay-text{
	content:"";
	background-color: #328ba6;
	cursor: pointer;
	transition: ease-in-out 0.5s, font-size 0.5s;
	line-height: 2;
	font-size: 1.5rem;
}

.col-md-3:hover .overlay-text::after{
	transition: ease-in-out 1s, font-size 1s;
}

.col-md-3 {
	-moz-box-sizing: border-box;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
	overflow: hidden;
	position: relative;
	padding-left: 5px;
	padding-right: 5px;
}

.col-md-3 img {
	-moz-transition: all 0.3s;
	-webkit-transition: all 0.3s;
	transition: all 0.3s;
}

.col-md-3:hover img{
	-webkit-transform: translate3d(0,-10%,0);
	transform: translate3d(0,-10%,0);
	cursor: pointer;
}

.overlay-text-blank {
	text-align: center;
	font-size: 1.8rem;
	font-weight: 600;
	vertical-align: middle;
}
<div class="container">
  <div class="row tiles">
    <div class="col-md-3">
      <img alt="text" src="https://www.codeproject.com/KB/GDI-plus/ImageProcessing2/img.jpg" class="img-fluid">
      <div class="overlay-text">Custom text</div>
    </div>
  </div>
</div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to change color of element when hovering over another element?

When hovering over a child element in firefox

Trigger CSS :hover only when hovering over border box

Css list disappearing when mouse hovers over other objects

How to change CSS elements of an element when hovering on another

Trying to display a hidden nav element when hovering over link via css

How to calculate mouse position relative to drawing area when it hovers over element being drawn

CSS Hover Opacity Transition flicker when hovering over element that is on top of another element

Trigger CSS animation when hovering over pseudo element?

p5.js: How can I make text appear when my mouse hovers over a different text element in the sketch in processing?

How do I trigger a click when hovering over a element for x seconds, using JQuery?

Trigger CSS animations by hovering over a seperate element

Hide image when hovering over a parent element

How can I avoid CSS flickering when hovering over areas?

Zoom in when hovering over image - CSS & HTML

Is it possible to remove a portion of a CSS hover overlay when hovering over a child element?

Unable to show a popup element when user hovers over another element

Using CSS to make two links fade in when hovering over a different link

How to trigger div visibility when hovering over list item in CSS?

Trigger two successive quick hovers to simulate a pulse effect in CSS/JQUERY

How to scroll up a div when hovering over another element

How to change css of one class when hovering over another?

How to make hovering over one div to trigger changes in two different divs?

Using CSS, how do you add a rounded grey background to an element when the user hovers over it

How to highlight the whole button when hovering over CSS Grid item?

How to stop the elements from growing when hovering over an element?

HTML/CSS tooltip that should appear when hovering over a certain element does not appear

Displaying an HTML element when hovering over only with CSS

How can I change one svg path ID element when hovering over another element

TOP Ranking

HotTag

Archive