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 CSS Cleanup Initiative
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 |
---|---|---|---|
#18 | 1217032-dashboard-css-6.patch | 10.58 KB | aspilicious |
#16 | dashboard-cleanup-1216980-16.patch | 9.96 KB | cosmicdreams |
#15 | dashboard-cleanup-1216980-15.patch | 10.01 KB | cosmicdreams |
#14 | dashboard-cleanup-1216980-14.patch | 9.56 KB | cosmicdreams |
#13 | 1216980-12-dashboard-css-cleanup.patch | 9.3 KB | cosmicdreams |
Comments
Comment #0.0
JamesK CreditAttribution: JamesK commentedFixed link to initiative page.
Comment #1
cosmicdreams CreditAttribution: cosmicdreams commentedHere's my first shot at this patch. In the end there was only a tiny bit of css needed to make dashboard work as most of it is controlled by jQuery UI.
Also, I changed some of the hardcoded ids to classes. I wanted to convert all of the ids to classes but I couldn't change the #dashboard ID. When I did the dashboard broke.
Comment #2
cosmicdreams CreditAttribution: cosmicdreams commentedComment #3
cosmicdreams CreditAttribution: cosmicdreams commentedI think there is an argument to be made here that the dashboard.base.css is too sparse. As the dashboard's usability is removed if you only use dashboard.base.css and any theme would exclude the dashboard.theme.css would have to implement many of the same styles to get to a working state.
If the instructions above are read literally, the dashboard.base.css should be as sparse as possible. That is the aim of this patch.
Comment #5
cosmicdreams CreditAttribution: cosmicdreams commentedAfter having a conversation with Jacine it's clear that I'll need to rework this patch. Admin specific css should be targetted at dashbaord.admin.css. In this case that's a lot of the styles that are in dashboard.theme.css after this patch is applied.
So, this is a good starting point but more work is needed. I'll likely have more time to look at this later in the week.
Comment #6
jyve CreditAttribution: jyve commentedI just had a quick look at your patch, so here is some feedback that you could incorporate in your updated patch:
The separation between base.css and theme.css seems ok to me, although most of theme.css content should go to admin.css, as you mentioned. In fact, since dashboard is an admin tool I would think that a theme.css is not required here?
Maybe a minor thing we could fix while we are at it is the use of underscores in the dasboard id's. I did not find a convention against that, but I've never seen underscores in other Drupal modules, so we should avoid it here too.
Good luck with the patch!
Comment #7
cosmicdreams CreditAttribution: cosmicdreams commentedI'll try to get this done before the next html 5 sprint starts.
Comment #8
cosmicdreams CreditAttribution: cosmicdreams commentedHere's a revised patch that admittedly doesn't cover all of the issues we care about in this patch (doesn't cover rtl, but I don't see how we can)
It doesn't seem that the module is specifically calling the rtl.css for this module. Can someone explain what needs to be done in order to have rtl support?
Also, how does the patch look?
Comment #9
cosmicdreams CreditAttribution: cosmicdreams commentedComment #10
jyve CreditAttribution: jyve commented@cosmicdreams: just some info without looking at the patch:
Drupal automatically picks up -rtl.css files when needed. That means that if you have a dashboard.theme.css, it will automatically look for dashboard.theme-rtl.css when browsing the site in a RTL-language. That dashboard.theme-rtl.css file will then be added after dashboard.theme.css.
Comment #11
skottler CreditAttribution: skottler commentedThis looks good to me.
Comment #12
aspilicious CreditAttribution: aspilicious commentedThis doesn't make sense if we are not renaming the original css files.
-22 days to next Drupal core point release.
Comment #13
cosmicdreams CreditAttribution: cosmicdreams commentedWorking on this again. This is before I properly segregate the styles into .admin.css and .theme.css
Comment #14
cosmicdreams CreditAttribution: cosmicdreams commentedThis patch refactors dashboard.base.css into two files and eliminates dashboard.theme.css. No CSS has been removed from original implementation yet.
I've tested this with the dashboard.admin.css turned off and it is technically functional but it is quite awkward with the proper paddings and dotted boarders present.
Putting into needs review to test my patch only. Will attempt to prune the css used even further.
Comment #15
cosmicdreams CreditAttribution: cosmicdreams commentedIn the last patch, I forgot to refactor the rtl styles. Fixed that with this patch.
Comment #16
cosmicdreams CreditAttribution: cosmicdreams commentedlast patch did not have proper endlines on two files. Fixing...
Comment #17
cosmicdreams CreditAttribution: cosmicdreams commentedI've been thinking about making a concerned effort to reduce the amount of css used here (specifically targeting the browser specific properties, and other styles that in testing can be removed without degradation of appearance). But I want to test my assumptions can someone review this and let me know if the patch is good to go now, or if a further css cleanup is necessary?
Comment #18
aspilicious CreditAttribution: aspilicious commented"module.admin.css
Should hold styles that are only applicable to administrative pages."
Everything from the dashboard module should be part of admin.css, we don't need base.css in this case.
ps: I still think this module is going away soon, so we shouldn't waste much time on this one.
ps2: wrong issue number in the patch name
Comment #19
jyve CreditAttribution: jyve commented@aspilicious: it is not because something is only visible in the backend that everything should be in .admin.css. base.admin.css is making sure it works. .admin.css adds styles to that. I'm quite sure this is what Jacine once pointed out.
So I would tend to agree with the patch from #16.
Comment #20
JacineIt looks like the only clean up that is going on here is moving selectors into the right file. I'm fine with that because I think this module really needs to be removed from core.
As far as which files to use, since this is strictly for an administrative UI, the styles belong in .admin.css. I know it's confusing for some of these newer modules, but it's different from say, contextual links because those are displayed both on the front and backend. Also things like tabledrag styles, and some of the other stuff in system.base.css can be implemented by modules anywhere, which also makes it "special." That's not going to happen for this module, and we decided early on not to put that kind of energy (splitting admin in the .base and .theme) early on because it's just not worth the effort it would require this time around.
Comment #21
RobLoach#950956: Remove Dashboard from core
Comment #22
cosmicdreams CreditAttribution: cosmicdreams commentedUnassigned issue so I can focus on D8 initiatives.
Comment #22.0
cosmicdreams CreditAttribution: cosmicdreams commentedUpdated issue summary.
Comment #23
plopesc