Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Part of the CSS Cleanup: http://drupal.org/node/1089868
Overview of Goals
- Make it easy to remove unwanted design assumptions in the theme layer, while maintaining critical functionality (such as functional JavaScript widgets).
- Prevent uneeded administrative styles from loading on the front end.
- Give modules the ability to include a generic design implementation with their module, without burdening themers.
- Make CSS and related markup more efficient and less intrusive to improve the themer experience.
The CSS Clean-up Process
Use the following guidelines when writing patches for the core issues listed below.
- Put CSS is in the appropriate file: CSS should be moved to separate files, using the following
name spacing conventions based on their purpose:- module.base.css
- Should hold structural and behavior related styling. CSS should be coded against the Stark theme. The absolute bare minimum CSS required for the module to function should go here. If there is no CSS required, this file should be omitted.
- module.theme.css
- Should hold generic design-related styles that could be used with Stark and other themes. It's where all design assumptions like backgrounds, borders, colors, fonts, margins, padding, etc, would go.
- module.admin.css
- Should hold styles that are only applicable to administrative pages.
To see an example of this in practice, look at Drupal's system module.
- Remove Assumptions: Styles that make too many assumptions, introduce superflous margins, padding and add things like font settings are not necessary and don't belong in core module CSS files. In cases where core themes depend on these properties, they should be moved to the CSS stylesheet of the respective theme.
- Reduce Selector Specificity: CSS code that resides in modules should be written in a way that's easily overridable in the theme layer. To improve the Themer Experience and make core CSS more efficient, CSS selectors should be made as general and short as possible. For example:
- Use
.style {}
overdiv.style {}
where possible. - Use
.module .style {}
overdiv.module div.somenestedelement .style
where possible.
- Use
- Don't use IDs in selectors: Use of ID's in core CSS selectors requires more specificity in the theme layer, making it harder and more annoying to deal with. It makes achieveing consistency in complex design implementations much harder than it needs to be. We need to stop making life hard for theme developers.
- Don't be afraid to change markup: There's lots of overlap between using proper and semantic markup and doing CSS right. If you come across a case where CSS is being applied where using a more semantic elements would solve the problem, then change the markup in your patch to make it right. For more information, see the Drupal 8 Markup Gate rules.
- Start with Stark and cross-browser test.
- "Design" markup and CSS for the Stark theme.
- If applicable, adapt the styles to match the core themes afterward.
- Finally, test the changes in all supported browsers and ensure no regressions are introduced.
Comment | File | Size | Author |
---|---|---|---|
#16 | 1216994-file_module-css-clean-up-16.patch | 856 bytes | oresh |
#11 | file-1216994-11.patch | 1.94 KB | jyve |
#10 | 1216994.009.patch | 1.91 KB | karschsp |
#7 | clean-up-file-css.1216994.007.patch | 1.91 KB | karschsp |
#5 | clean-up-file-css.1216994.005.patch | 2.04 KB | karschsp |
Comments
Comment #1
jvc26 CreditAttribution: jvc26 commentedPatch attempting to close this issue attached. Comments/review please.
Comment #2
jvc26 CreditAttribution: jvc26 commentedCorrected patch - prior patch added a stylesheets reference to file.info, new one replaces the old reference to the stylesheet in file.module.
Comment #3
jyve CreditAttribution: jyve commentedReviewed this patch, and looks good to me.
A patch for the image module css was added today, and I will advise there to also use base.css instead of admin.css so that these two modules are in line with each other.
Comment #4
xjmNote that this patch will need to be rerolled, because the core directory structure for Drupal 8 has now changed. (For more information, see #22336: Move all core Drupal files under a /core folder to improve usability and upgrades). Tagging as novice for the task of rerolling the patch. Set the status back to "needs review" when submitting the updated patch.
If you need help rerolling this patch, you can come to core office hours or ask in #drupal-gitsupport on IRC.
Comment #5
karschsp CreditAttribution: karschsp commentedHere's a re-roll for the /core move.
Comment #6
jyve CreditAttribution: jyve commentedAfter some discussion in another issue #1216970: Clean up the CSS for Book module I would think all this CSS should go into a file.admin.css instead of file.base.css.
Comment #7
karschsp CreditAttribution: karschsp commentedHere's a re-roll.
Comment #8
karschsp CreditAttribution: karschsp commentedComment #10
karschsp CreditAttribution: karschsp commentedTrying again.
Comment #11
jyve CreditAttribution: jyve commentedJust reviewed this patch and two things have been updated in the patch attached:
1. Added a file header in file.admin.css
2. Alphabetized the properties.
Comment #12
karschsp CreditAttribution: karschsp commentedLooks good.
Comment #13
catchLooks good to me too. Committed/pushed to 8.x.
Comment #15
miguelfrias CreditAttribution: miguelfrias commentedHow can contributed to this section?
Comment #16
oresh CreditAttribution: oresh commentedReally small patch for selector weight reduce. Just to make core cleaner.
Comment #17
xjmCreate new issues, don't raise zombies.
Comment #17.0
xjmUpdated issue summary.