Part of the CSS Cleanup: http://drupal.org/node/1089868 & #1921610: [Meta] Architect our CSS
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 guidelines extracted from CSS file organization (for Drupal 8):
CSS files for Drupal modules
All of a module's styles should be placed in a
css/sub-directory and broken into one or more of the following files:module_name.module.css: This file should hold the minimal styles needed to get the module's functionality working. This includes layout, component and state styles. Any needed RTL styling would go in a file namedmodule_name.module-rtl.css.module_name.skin.css: This file should hold extra styles to make the module's functionality aesthetically pleasing. This usually just consists of skin styles. Any needed RTL styling would go in a file namedmodule_name.skin-rtl.css.module_name.admin.css: This file should hold the minimal styles needed to get the module's admin screens working. This includes layout, component and state styles. On admin screens, the module may choose to load the *.module.css in addition to the *.admin.css file. Any needed RTL styling would go in a file namedmodule_name.admin-rtl.css.module_name.admin.skin.css: This file should hold extra styles to make the module's admin screens aesthetically pleasing. This usually just consists of skin styles. Any needed RTL styling would go in a file namedmodule_name.admin.skin-rtl.css.Note: Modules should never have any base styles. Drupal core's modules do not have any base styles. Instead Drupal core uses the Normalize.css library augmented with a drupal.base.css library.
If a module attaches a CSS file to a template file, the CSS file should be named the same as the template file, e.g. the system-plugin-ui-form.html.twig CSS file should be named system-plugin-ui-form.css
- 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 .stylewhere 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 |
|---|---|---|---|
| #9 | 1217010-9-menu.patch | 1.38 KB | cosmicdreams |
| #5 | remove-menu-css-1217010-5.patch | 266 bytes | skottler |
| #2 | before.png | 17.21 KB | devin carlson |
| #2 | after.png | 17.19 KB | devin carlson |
| #3 | remove-menu-css-1217010.patch | 1015 bytes | devin carlson |
Comments
Comment #1
jvc26 commentedFirst patch to try to clean up Menu module css.
Comment #2
devin carlson commentedHonestly, I think that we could just remove all of the menu css. There are only three styles in the menu.css file and they only make small changes to table column and cell contents sizes (which are best determined by the browser anyway).
There is almost no difference in presentation between using the styles and removing them.
Sets the size of the table cells which have the "edit" and "delete" buttons inside of them to 100px.
Sets the size of the table cells which have the "enabled" checkbox inside of them to 70px.
Adds 25px to the left of input checkboxes which are located inside of the "enabled" checkbox table cells.
Attached are two images: a before (with the styles) and an after (with the styles removed).
Comment #3
devin carlson commentedAnd a patch to remove the css file and the lone reference to it.
Comment #4
aspilicious commentedI disagree a bit.
This is unneeded. It looks even better without it.
But
and
should stay.
We can leave it in admin.css or we can move it to bartik and seven.
Comment #5
skottler commentedI've rerolled the patch and only removed .menu-enabled input.
Comment #6
aspilicious commentedAnyway the file name should change. We have to move this to menu.admin.css. (see summary)
Comment #7
cosmicdreams commentedLooks like the patch in #5 needs some love. I'll see if I can make some headway tonight.
Comment #8
cosmicdreams commentedLooks like the patch in #5 needs some love. I'll see if I can make some headway tonight.
Comment #9
cosmicdreams commentedHere's a patch that rerolls #5, renames the css to menu.admin.css, and makes the appropriate change to menu.admin.inc
Comment #10
cosmicdreams commentedComment #11
aspilicious commentedJust tested this, looks good :)
Comment #12
webchickTagging with coding standards, for Jennifer to take a look at.
Comment #13
jhodgdonI was going to say this needed to be delayed due to being over threshold on critical tasks right now, but it's such a small patch (one line of code and the rest is CSS), I went ahead and committed it anyway. I don't think it will affect any other issues (hopefully). Thanks!
Comment #14
devin carlson commentedI'm not usually one to disagree but I think that this should have been looked at a bit more closely.
I outlined some valid concerns in #2 which were only addressed, without explanation, by "but x and y should stay" in #4. I also provided screenshots which show that there is no benefit provided by the rules; they only provide inconsistency with other administration pages and introduce an unnecessarily large amount of white space.
Many of the core administration pages use a table with a row of "operations" links, such as:
The menu management page is the only page in Drupal core that places a class on the table column (except for the modules page which uses the class for creating icons). It is also the only place where a defined width is applied to the operations column.
Lets say you are building an administration theme and want to modify the width of table cells, such as by restricting all cells to a maximum width by doing something like:
This would work fine for every single table in core, except for the menu management table, since it specified its own width. Inconsistencies like this make theme developers, such as myself, sad. :(
Is there a good reason for keeping these rules? I also think the table classes should be gone, or those classes should be applied to operations links on every administration page (a separate issue).
Comment #15
aspilicious commentedIf you're concerned please collect some links to tables in the drupal admin interface and I'll look at them and make a proper response and maybe kill those lines if you're correct.
Comment #16
dcmouyard commentedI don't have a problem with removing
menu.admin.css, but those styles should definitely go into Seven and Bartik if it's removed.Comment #16.0
dcmouyard commentedUpdated issue summary.
Comment #16.1
chrisjlee commentedUpdated issue summary.
Comment #17
ckrinaStart working on that
Comment #18
ckrinaStart working on that
Comment #19
ckrinaChanges from #9 are already applied in the last commit:
- removed .menu-operations because it is not such class
- correct path for menu.admin.css
Marking as fixed because CSS is already cleaned and we will be able to close the hole #1921610 issue. Feel free to open a new issue to discuss any other topic related.
Comment #20.0
(not verified) commentedUpdating summary with the new css organization from #1887922