Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
One of the first things people want to do when they activate a new WordPress theme is make changes to the look and feel of the theme to make it their own. This usually means making changes to the theme styles. Child themes were introduced to make this process non-destructive, meaning you don't have to mess with the core or parents theme styles to get what you want. That way you won't inadvertently break the parent theme and your changes won't be overwritten in the future when the parent theme updates. Let's take a look at how you go about making changes to the styles on your website using your child theme.
If you look closely at the images in the Twenty Twelve theme, you'll notice that they have a slight drop shadow behind them and that the box that contains them has rounded corners. You see the shadow here behind this white image and if we scroll down, you see that this solid image has rounded corners. If you want to change that, you have to make changes to the style sheet and those styles are in the parent theme. So what we're going to do is to use our child theme styles to override the parent theme styles. This is because of how CSS works.
CSS or cascading style sheets work on the simple principle of a cascade. The first styles that are listed have less importance than the last ones, meaning the ones that are the furthest down in the stylesheet matter the most. In the case of a child theme, the parent theme is called first and then the child theme. So any style that's in the child theme stylesheet has more importance than the ones that are in the parent stylesheet. If I use the developer tools here I can right- click on the image, click Inspect element and here I can see the styles that affect the image. You see the first style is this image align right, but this style only affects alignments.
If I scroll down you see that the second style here, the one that affects entry content image and other images has two variables; border-radius, and box -shadow, and obviously, these are impacting the image. If I want to see if this is a style I want to change, all I have to do is turn one of those styles off, so I'll turn off box- shadow, and now you see the box-shadow disappears. That also makes it harder to see the rounded corners though, because there's a white background and this image has a white background as well, so I'll scroll down and find another image, and here you see it still has a rounded corner, and I can now change that rounded corner radius either by going in and saying, let's say 10 pixels, to get a much more rounded corner, or I can go out and knock it away altogether and get a square corner.
Now that I know that I want to change the style, the next step is a copy to style itself, or copy the whole style and then go to my stylesheet in my child theme. So I'll navigate to my child theme, and open style.css in my text editor, and here I'm simply going to paste in the original style the way it was written. So here we have the style copied straight out of the browser. You see I made a change to it, I made border radius 10 pixels, but since I want to get rid of the border radius, I am going to set it to 0 instead, and then I'm also going to change box-shadow from these values to none, just to clean up a bit of code here so it's looks nice. And now when I save the stylesheet in the child theme, I can go back to my browser, reload the page, and you see that my changes are taking effect, and now I have square corners and no drop shadow.
But this isn't style that I changed in the parent stylesheet. I changed it in the child theme stylesheet, meaning I can now go back to the child theme stylesheet and simply comment out my new style, save it, reload the page and the old styles from the parent stylesheet kick back in. So now you see the power of a child theme style sheets. Instead of having to go and muck around with the actual styles and risk breaking something, you're simply adding on new styles and seeing what they do. And this doesn't just apply to styles you want to change, you can also go into your child theme and just add new styles at will.
So if you have new content then you need to change the way that appears, you can simply add new styles here and they'll be appended to the original styles from the parent theme. That way you're building on top of the parent theme instead of building everything from scratch. By modifying or overriding styles with your child theme, you can make quick and easy changes to your theme without having to touch the theme itself, and if you don't like what you did you just go back in and take out that new style code and you are back where you started.
Get unlimited access to all courses for just $25/month.Become a member