5

Trying to pin down in better details the steps involved when sub-theming, I can manage to get a sub-theme up in D, but there is a question I still have, concerning the style.css that is unfortunately not clear in my head. Is the sub-theme's style.css supposed to come from the parent theme or from subtheme?

The example I have show the subtheme as having no style.css. I tried the advice and flushed style.css, created an empty simpleblueMaster.css, added it to file[] in the .info file.

Author stated that css styles from parent theme will be loaded to be overridden if needed by sub-theme, and this totally makes sense. Unfortunately this is not the case on my installation and I would of liked to confirm the expected behavior.

THe author erases all css and images in his sub-theme, except if I do that in mine, nothing works. Parent theme's style.css does not seem to load and I assumed it should be. Anyone know what happens to style.css in sub-themes?

Or what could be preventing parent theme's style.css from not loading, if it should be?

Any insight appreciated, Thanks all!

Update:

Basically, there are 2 main ways (ok, probabably more I don't know of!) for a sub-theme to override the parent theme's css.

One involves copying the whole style.css in sub-theme and hacking on that. This works but a much cleaner approach as also mentionned in the answer is to not have a style.css in subtheme, and override with css in a sub-theme specific file. If there is a better way, I'd be very happy to know!

Thanks all

  • 1
    Can you clarify what theme you are using as the parent and the contents of your theme and subtheme .info files. – Ashlar Dec 12 '11 at 4:24
  • 1
    Hey! You made me catch on, when going to fetch the .info file a quick peek and I saw in dismay that ... the much needed base theme tag was missing! :) Thanks friend. – stefgosselin Dec 12 '11 at 5:11
3

You can choose which files you want to override in the parent theme... its as simple as including a copy of the files using the same name ex style.css just drop that anywhere inside your sub theme and tweak away.

Any file with the same exact names as files in the parent-theme will now default to the file that is in your sub_theme. So... if you still want the original style.css to load, do not add it to your sub-theme at all & instead create a custom.css and any similarly named style codes will default to the copy in your sub-themes css files first then if needed the original.

To add from your comment below, do not remove the style.css in the main theme unless you are going to bring in all of its code into your custom file. What would be easiest for light edits would be to create a custom.css file in your sub-theme and only copy over the codes you need to tweak, if your going hog-wild just copy over the whole contents style.css

Hope that helps :)

  • 1
    It does, help a bit but not to the point that it makes it clear for me. It seems to me there are 2 main options for css in subthemes: 1 .copy the parent style.css to child theme, hack away on style.css, or 2: create subtheme specific css file, add to .info in file[], delete style.css, hack away on subtheme's css. Am I correct? – stefgosselin Dec 12 '11 at 4:37
  • 1
    lol I updated my answer at the same time you were adding your comment. So the main point would be do not remove the style.css from the main theme, its absolutely needed, unless/if you fully override it with a file of the same name and bring in all of the style code along with it. – Macronomicus Dec 12 '11 at 4:40
  • Yes. Got that. I had copied an previous info file that did not have the base theme tag. That explains the weird behavior. Also confirms one can avoid creating a style.css, and just over ride the needed changes in a sub-theme specific .css file, that way your changes are not mixed with parent theme's css, and if parent theme changes their css code in upgrades you are more likely to have these changes reflected in your theme if you don't override the whole parent's style.css. Of course. If you update this in your answer I shall happilly give you the question, unless someone finds better. – stefgosselin Dec 12 '11 at 5:09
  • Yes you've got it, it took me a bit to get used to grasp this bit myself a few years back, I had a similar experience to you. I have always found these to be great little misstakes though since now you've really got a good understanding of sub-theme – Macronomicus Dec 12 '11 at 6:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.