Home > OS >  Hover on a child element WITHOUT changing a parent element (css)
Hover on a child element WITHOUT changing a parent element (css)

Time:06-04

I've already broken my brain looking for a solution. I need to hover on the child element (button) so that the parent element (h2) doesn't have a hover effect. Not sure how to do it.

Thank you.

This is my css and html:

.parent {
  display: block;
  text-align: center;
  font-weight: 700;
  font-size: 31px;
  letter-spacing: normal;
  position: relative;
}

.parent:hover {
  color: orange;
}

span {
  line-height: unset;
  vertical-align: baseline;
  top: 0;
  left: 0;
  position: absolute;
  color: transparent;
  box-shadow: none;
  z-index: 5;
}

span button {
  position: absolute;
  left: 0;
  top: -20px;
  color: #fff;
  width: 30px;
  height: 30px;
  min-width: 30px;
  min-height: 30px;
  z-index: 5;
  background: #0085ba !important;
  border-radius: 50%;
  border: 2px solid #fff;
  box-sizing: border-box;
  padding: 3px;
  display: inline-block;
  overflow: hidden;
}
<h2 >
  Title
  <span >
    <button> </button>
  </span>
</h2>

CodePudding user response:

This can be helpful

example

.html

<div >
     <div >
          /*.....*/

.css

.parent1:hover{
 cursor: pointer;
 }

.parent1:hover .child1{
/*......*/
}

snippet

.parent:hover .child {
/* ... */
}

CodePudding user response:

Add the below:

    parent:hover {
      cursor:pointer
    } 

CodePudding user response:

I think the easiest way would be to add "button:hover" under the "span button" of your css. Example:

button:hover {
  color: black;      
}

You can learn more here: https://www.w3schools.com/css/css3_buttons.asp

  • Related