Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change background of child if parent :hover

I want to change the bg-color of .circle.icon if posts-item is hovered. Any idea how to accomplish that, possibly without Javascript?

<div id="scr1" class="large-6 columns timeline">
    <div class="line"></div>
    <ul class="posts">
        <li class="posts-item">
            <div class="circle icon"></div>
             <h2 class="posts-item-title">
                 <a href=""></a>
              </h2>
            <p class="summary"></p>
        </li>
    </ul>
</div>
like image 217
user2705526 Avatar asked Aug 22 '13 00:08

user2705526


People also ask

How do you style the parent element when hovering a child element?

The trick is to give the sibling the same size and position as the parent and to style the sibling instead of the parent. This will look like the parent is styled!

How do you select a child element in CSS?

The CSS child selector has two selectors separated by a > symbol. The first selector indicates the parent element. The second selector indicates the child element CSS will style.

How do you select parent element in CSS?

The element>element selector is used to select elements with a specific parent. Note: Elements that are not directly a child of the specified parent, are not selected.


1 Answers

Like so.

.posts-item:hover .circle.icon {
    background: green;
}

No jQuery - Everyone's happy :)

like image 109
iConnor Avatar answered Nov 09 '22 07:11

iConnor