Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Want to override child element css property by parent element

Tags:

css

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

In CSS, "child" class has its own bg color, that I can't change. I want to apply "parent" class bg color to container. So, Is there any CSS trick to override "child" bg color by "parent" bg color.

Any help would be much appreciated.

like image 839
user3225796 Avatar asked Jan 23 '14 00:01

user3225796


People also ask

How do I override CSS class in external CSS file?

html worked fine, overrides the external css. Show activity on this post. Either apply the style="padding:0px;" on the content div inline (not recommended), or load your style after you load your external style sheet.

What is CSS rules overriding?

CSS allows you to apply styles to web pages. More importantly, CSS enables you to do this independent of the HTML that makes up each web page. Overriding: Overriding in CSS means that you are providing any style property to an element for which you have already provided a style.


2 Answers

!important will override any inline background color applied, let me know if this works

.parent > .child {
    background-color: transparent !important;
 }
like image 71
Cam Avatar answered Nov 08 '22 17:11

Cam


.parent .child {
    background-color: inherit !important; // can also use "transparent"
}

Use !important only if nothing else works.

like image 20
rvighne Avatar answered Nov 08 '22 18:11

rvighne