What is the best way to prevent the child elements from inheriting the hover effect of the main container?

Looking to spice up the appearance of the div element that holds the product's image, SKU, and price. Adding a hover effect to the main container causes the child divs to inherit it, resulting in separate hover effects on each child div.

Sample HTML for each main container:

<div class="maincontainer">
    <div class="imgbox" >
        <img src="G-Shock.png" alt="gshock">
    </div>
    <div class="skubox">
        <p>
            G-Shock Watch
        </p>
    </div>
    <div class="pricebox">
        <p>
            $500.00
        </p>
    </div>
</div>

Sample CSS for main container and its children:

.maincontainer{
   width:350px; 
   position: relative;
   padding:2%;
   flex-grow:1;
   flex-basis:16%;

}
.imgbox{
    height:218px;
    width:218px;
    margin:0 auto;

}
.skubox{
    height:72px;
    width:160px;
    margin:0 auto;
    text-align:center;
    position:relative;
    padding-top:1px;
}
.pricebox{
    height:22px;
    width:80px;
    margin:0 auto;
    text-align:center;
    position:relative;
    padding-top:1px; 
}
p{
    margin:0;
    padding:0;
    text-align:center;
    position:relative;
    top:50%;
    left:50%;
    transform: translateX(-50%) translateY(-50%);
    font-size:13px;
}
.maincontainer :hover{
    box-shadow: 0 0 11px;
}

Answer №1

It appears that the issue is stemming from the space between the class selector .maincontainer and the pseudoselector :hover. This creates a rule that targets any child of the maincontainer with the hover style. To resolve this, simply remove the space between the selectors. Here is the corrected code:

.maincontainer {
  width: 350px;
  position: relative;
  padding: 2%;
  flex-grow: 1;
  flex-basis: 16%;
}

.imgbox {
  height: 218px;
  width: 218px;
  margin: 0 auto;
}

.skubox {
  height: 72px;
  width: 160px;
  margin: 0 auto;
  text-align: center;
  position: relative;
  padding-top: 1px;
}

.pricebox {
  height: 22px;
  width: 80px;
  margin: 0 auto;
  text-align: center;
  position: relative;
  padding-top: 1px;
}

p {
  margin: 0;
  padding: 0;
  text-align: center;
  position: relative;
  top: 50%;
  left: 50%;
  transform: translateX(-50%) translateY(-50%);
  font-size: 13px;
}

.maincontainer:hover {
  box-shadow: 0 0 11px;
}
<div class="maincontainer">
  <div class="imgbox">
    <img src="G-Shock.png" alt="gshock">
  </div>
  <div class="skubox">
    <p>
      G-Shock Watch
    </p>
  </div>
  <div class="pricebox">
    <p>
      $500.00
    </p>
  </div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

designing a button layout with bootstrap framework

I am attempting to position a "Redigera" button after the "Avsluta" button <div class="row"> <div class="col-md-4"> </div> <div class="col-md-4"></div> <div class="col-md-4"> <button class=" ...

The utilization of CSS within Flask can sometimes lead to a state

Struggling with a python Flask issue here and could really use some help. My CSS is completely out of whack and not displaying correctly at all. Despite setting everything up in static_files and seeing only a 304 code in the terminal, even when trying new ...

Can anyone explain why my navbar text is not aligning in the center?

I am struggling to center the text in one of my two navbars. As a newcomer to both navbars and bootstrap, I am having difficulty figuring out why I can't achieve this. Should I be making changes on the bootstrap side or can it be fixed within the < ...

When I attempt to run JavaScript code on the server, it fails to execute properly

When I run my code on my PC without putting it on the server, it works perfectly fine. However, when I upload it to the server and try to call it, I encounter the following error: Uncaught ReferenceError: crearLienzo is not defined at onload ((index): ...

Collision of CSS styles with a different CSS stylesheet causing conflicts

Currently, I am in the process of developing a website and have encountered a specific issue. Within my page, there are various divs and tables present. I have meticulously crafted classes and styles to customize the appearance of these elements to align ...

(Vue.js) The icon fails to be applied

<link rel="icon" href="/static/icons/apple-touch-icon.png" type="image/x-icon"> <link rel="icon" type="image/png" sizes="32x32" href="/static/icons/apple-touch-icon.png"> <link rel="icon" type="image/png" sizes="16x16" href="/static/ ...

Adjust the size of both the right and left price scales on TradingView Lightweight Charts

Is it possible to set a fixed width for both the right and left price scales on a chart? Let's say, 50 pixels for the right price scale and 70 pixels for the left price scale? For a working example, please visit https://jsfiddle.net/TradingView/cnbam ...

Dynamic HTML and CSS Table Alignment Techniques

Issue Screenshot: Is there a way to properly align the right column of the table, particularly the Student NRIC row and School's? .formstyled { width:70%; margin-left:5%; } .formstyled input[type=text],input[type=password],text ...

Modify the contents of a textbox by editing the text as you type

Text within the text box follows this format: login -u username -p password When entering this text, I want to substitute 'password' with a series of '*'s equal in length. For example: 'login -u <a href="/cdn-cgi/l/email-prot ...

Tips for aligning 2 columns perfectly in a 3 column layout

I am facing an issue with a grid section where the grid-template-column is set for 3 columns, but sometimes the content loaded dynamically only fills 2 columns. I am attempting to center the columns when there are only 2. Despite going through the grid CS ...

Issue with Angular custom tag displaying and running a function

I have created a custom HTML tag. In my next.component.ts file, I defined the following: @Component({ selector: 'nextbutton', template: ` <button (click) = "nextfunc()">Next</button> ` }) export class NextComponent{ nextfunc( ...

Conceal User Interface Angular Tabulation

I'm working on setting up UI Bootstrap tabs, and for reference you can find the plunker here. My goal is to hide the tabs since I will be utilizing a button to switch between them. Despite adding the following CSS class to my file, the styling is not ...

"Activate the parent window by navigating using the accesskey assigned to the href

I have integrated a bank calculator tool into a website. The calculator opens in a new window, but I am encountering an issue. Users need a shortcut to open the calculator multiple times. I have discovered the accesskey feature, which works the first tim ...

Steps for removing all inline styles within an element:1. Access the element's

I have a group of span elements containing texts generated by tinymce. <span class="ArticleSummary"> This content is produced using a text editor and may include various inline styles. </span> Typically, this text includes numerous inline s ...

How to dynamically change the position of an input field within a form using JavaScript and jQuery

I have a form displayed on my website that looks like this: input a input b input c I am wondering if it is achievable to rearrange the order of inputs using jQuery, like so: input a input c input b However, it is important that the data is still ...

If a specific class is identified, add a border to the div when clicked using JavaScript

Is there a way to use javascript/jquery to add a border to a selected div? I have multiple rows with columns, and I want only one column per row to be highlighted with a border when clicked. Each row should have one column with a border, so it's clear ...

Emptying the AnyChart (Javascript) container prior to generating new charts

I have been utilizing the anychart JavaScript library to generate a pie-chart from my data, which is dynamically pulled whenever a user modifies a dropdown selection. Below is the code snippet I am employing for this purpose: var stage = anychart.graph ...

The Bootstrap carousel controls now add the carousel ID to the address bar instead of just moving to the next slide

I can't figure out why my carousel isn't working. The id of the carousel is showing up in the webpage's address, which usually happens when the 'bootstrap.js' file is missing, but I have included it. Can anyone help me troubleshoo ...

Avoid running old JavaScript code when using turbolinks in conjunction with highcharts library, specifically LazyHighCharts

Utilizing turbolinks 5 and rails version 5, along with the latest Highcharts has been causing me some issues. T LazyHighCharts offers a solution for Turbolinks 5 by encapsulating chart building javascript within (function() { document.addEventListe ...

"Trying to activate a hover effect on a div using JQuery, but it's not functioning

Is there a way to make these divs animate each time I hover over them? Currently, the animation only works once and does not repeat when hovering again. Can anyone provide guidance on how to achieve this? function Rotate() { $('#gear1,#gear2,#gea ...