izaan
izaan

Reputation: 11

Remove the css of a child class by a parent class

I have

HTML:

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

and

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

CSS:

.child{  width:2px;height:3px };
.parent .child{color:blue};

I want to remove the style of child class when I include the parent in the css ie if I use .parent .child there should not be width and height style to child ie the style of child should be removed if used along with parent.How can I do this?

Upvotes: 0

Views: 3231

Answers (1)

Bart Jedrocha
Bart Jedrocha

Reputation: 11570

The following code snippet will work. When the child is inside the parent node, set it's width and height to the element default, which is auto.

.parent .child {
    color: blue;
    width: auto;
    height: auto;
}

Upvotes: 6

Related Questions