0

This might has been answered already, though I couldn't find a concrete answer to my situation. I wrote the following code:

HTML:

<div class="parent">
 <div class="child">   
 </div>
</div>

CSS:

.parent {
   height: 100px;
   width: 100px;
   background-color: red;
}

.child {
   height: 50px;
   width: 50px;
   background-color: blue;
}

.child:hover .parent {
   width: 75px;
}

As you might have noticed, I am trying to change the style of a parent element and this, ofcourse, is a wrong method of trying to achieve that. Can anyone show me an example of how I can make this possible? I also made a FIDDLE

Mark C.
  • 5,789
  • 4
  • 31
  • 60
Barrosy
  • 1,343
  • 2
  • 17
  • 44
  • You can't do it! It's not possible to target parent selector in CSS – Dhaval Marthak May 04 '15 at 12:07
  • It's not possible to alter the parent div via child div css using only css – Kawinesh SK May 04 '15 at 12:08
  • So I should probably make use of javascript here? Thanks for the quick reply! – Barrosy May 04 '15 at 12:16
  • There is no parent selector in CSS but what is the real world scenario here? When you `hover` a child, its parent is also hovered on and so maybe it is possible by directly setting the properties on `.parent:hover`. This will work as long as the parent and child have same dimensions. – Harry May 04 '15 at 12:21
  • No, the problem is I am trying to make a menu with a submenu, however I styled the anchor element's background above the submenu (which is an unordered list element). Whenever I add styling to a situation like: .subMenu:hover, the styling won't be applied to the anchor above. – Barrosy May 04 '15 at 15:29

0 Answers0