It’s nice to work on wordpress and to get the constant appreciation from within while working on this awesome platform. It’s very modular and systematic. For making any custom change you can find some nice action or filter but problem somethings things becomes weird. One such weird thing is overriding the parent CSS from child CSS.

Do you love making child theme for editing?


It’s always a good idea to make child theme of a parent theme. Not just it takes few minutes but it makes your editing very modular and understandable. There are many advantages of working on a child theme and you can read this blah blah here.

My Child CSS is not overriding the Parent CSS 🙁


This happens a lot. Sometimes it works but sometimes it doesn’t. As WordPress Codex says, that your child theme css is loaded very last in all css’s and that’s why it should override all the css rules defined in previous css’s. Very true but still I am not able to override.

There is a simple solution : Shout it loud in your child css,  override it you stupid 🙂

Can you?

Well yes, you can.

How to Shout Loud in Child CSS

In css it’s all about weight your rule is carrying. More the weight, more the preference.

Let’s take an example:

If you are overriding

//Defined in Parent theme css
#header{
   margin:20px;
}

with

//defined in Child theme css
#header{
   margin:0px;
}

but not able to override then there is a simple solution to this is put more weight in child css.

Suppose your #header is defined inside #main, then write your css in your child theme like this.

#main #header{
   margin:0px;
}

This is how we can shout that this this this is supposed to be overridden. Override it, you stupid interpreter.

Something about CSS weight

Weights are really important in css. Only a weight can decide which has priority over which.

Class < ID < Hierarchical (like in our example).

So, If in parent css something is written with a class then you can override it with ID (#) in your child css. If rule is applied with ID (#) in parent css then override it with Hierarchical (like discussed above).

Hope, someone will get benefited with it. Best of luck. Happy Blogging.