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 |
---|---|---|---|
#67 | book bartik.jpg | 77.68 KB | mortendk |
#67 | book stark.jpg | 80.88 KB | mortendk |
#67 | book-bartik-no theme_css.jpg | 79.37 KB | mortendk |
#67 | book-stark-no theme_css.jpg | 37.51 KB | mortendk |
#67 | book-css-bartik.patch | 4.39 KB | mortendk |
Comments
Comment #2
mdm CreditAttribution: mdm commentedComment #3
mortendk CreditAttribution: mortendk commentedtag
Comment #4
mortendk CreditAttribution: mortendk commentedtaking this one
Comment #5
mortendk CreditAttribution: mortendk commentedsplit up the css so its in admin & theme
cleaned out the stuff from #book-admin-edit have a hard time justifieng its existence or am i wrong there ?
Comment #6
JacineWoot! Happy that you are working on this Morten! Go go go :)
Comment #7
mortendk CreditAttribution: mortendk commentedForgot the admin.theme.css file
Comment #8
mortendk CreditAttribution: mortendk commentedforgot the book.theme.css file
Comment #9
mortendk CreditAttribution: mortendk commentednewlines added ...
Comment #10
JacineOkay, just reviewed this and found a couple of issues with the patch:
_book_admin_table_tree()
doesn't seem like the right place to load book.admin.css. I'm going to ask around about this.The rest looks good to me! Go Morten go! :D
Comment #11
tstoecklerThis should use the #attached syntax.
Comment #12
mortendk CreditAttribution: mortendk commentedthis should do it
Comment #14
mortendk CreditAttribution: mortendk commentedokay lets try again
have no clue why evil test bot dont give me any love
Comment #15
JacineYeah, hopefully that one works... We still need to deal with adding the book.admin.css file. I don't think that function is where it should be added, and @tstoeckler's right that it should probably use #attached.
Comment #16
mortendk CreditAttribution: mortendk commentedyeah tried to get that one in but evil bot keept messing with me
Comment #17
sunThis should go into _book_admin_table() instead, as the _tree helper calls itself recursively for each level of the entire book tree -- simply use #attached on the initial $form['table']
Aside from that, I'm not 100% sure that all of the non-admin CSS belongs into .theme (i.e., with no or nothing in .base) -- does the output still "work" in Stark after manually removing book.theme.css from the output?
23 days to next Drupal core point release.
Comment #18
mortendk CreditAttribution: mortendk commentedthe output still works in stark after killing the book.theme.css - ive added 2 screenshots
im pretty sure we should fix the navigation class names so they got unified all over drupal, but that thats another issue though.
Comment #20
mortendk CreditAttribution: mortendk commenteddidnt get the new files ...
Comment #21
mortendk CreditAttribution: mortendk commentedlets try with the need review added ..
Comment #23
mortendk CreditAttribution: mortendk commentedcan someone tell my why the testbot gimme:
error: modules/book/book.admin.css: No such file or directory
error: modules/book/book.theme-rtl.css: No such file or directory
error: modules/book/book.theme.css: No such file or directory].
now that they are defined in the patch
index e69de29..1ec4614 100644
--- a/modules/book/book.admin.css
+++ b/modules/book/book.admin.css
@@ -0,0 +1,12 @@
+#book-outline {
+ min-width: 100em;
+}
+.js #edit-book-pick-book {
+ display: none;
+}
+.form-item-book-bid .description {
+ clear: both;
+}
+#book-admin-edit .form-item {
+ float: left;
+}
Comment #24
tim.plunkett@mortendk, that patch looks whack. If you upload a zip of the book module directory, I can reroll a patch for you...
Comment #25
Dave Reid@morten: Your Git diff is formatted in such a way that a book.admin.css must exist prior to patching rather than creating a new file.
Comment #26
mortendk CreditAttribution: mortendk commentedalright one more time for prince knud
Comment #28
mortendk CreditAttribution: mortendk commentedComment #29
sunLooks pretty much RTBC after changing that drupal_add_css() call into #attached
Comment #30
mortendk CreditAttribution: mortendk commentedComment #31
droplet CreditAttribution: droplet commentedneeds alphabetized properties :)
http://drupal.org/node/302199
Comment #32
TR CreditAttribution: TR commentedRe-rolled #30 with alphabetized properties. I also checked all the modified CSS against the CSS coding standards, and found no other problems.
Comment #33
TR CreditAttribution: TR commentedDisregard #32, I accidentally left the newly defined .css files out of the patch.
Attached is the proper patch that corresponds to #30 but with alphabetized properties.
Comment #34
mgiffordSubscribe. Hope to see this get into D8 -> #736604: book module now without clearfix & better markup + accessibility love without bumping into this cleanup initiative.
Comment #35
TR CreditAttribution: TR commentedRerolled patch to account for changes committed in #120368: Book outline page breaks my site layout
@mgifford: Can you review this?
Comment #36
mgiffordI tested this against core. It looks good. Thanks for keeping up with core!
Comment #37
JacineUpdated the issue summary to include full information about what "clean up" means.
Comment #38
jyve CreditAttribution: jyve commentedJust tested this patch and here is my feedback, and a new patch reflecting that feedback:
- The rules below in admin.css looks like it belongs in base.css. This is module behavior and not styling. Also, these rules apply to the node edit form, and admin.css was not being loaded there. I've moved them to base.css and added base.css to the form alter for the node edit form.
- The last css rule in admin.css adds a useless float, since that form-item is nicely handled by the draggable table layout.
- Since (re)moving these rules empties the admin.css, I've removed it entirely.
New patch attached!
Comment #39
jyve CreditAttribution: jyve commentedAdded @file and block level comments as requested in another thread.
Comment #40
xjmThanks for the patch. Note that the Drupal 8.x 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). When the patch has been rerolled, please set the issue back to "Needs Review."
Tagging as novice for the task of rerolling the Drupal 8.x patch.
If you need help rerolling this patch, you can come to core office hours or ask in #drupal-gitsupport on IRC.
Comment #41
xjmOops, forgot to set status.
Comment #42
jyve CreditAttribution: jyve commentedRerolled the patch for the new folder structure.
Comment #43
mortendk CreditAttribution: mortendk commentedput the book navigation into
remove the book-navigation-
print $book_id;
id to stop the ID madness.Comment #45
xjmNote that this patch removes the terminal newline from this file, so we'll need to add that back. (Put the cursor on the last line and hit enter.)
Comment #46
xjmAnd apparently it also needs some other work. :)
Comment #47
mortendk CreditAttribution: mortendk commentedooh my so i also have to rewrite the .test file ?
- this patch made the navigation have the same markup as the pagers ?
Comment #48
cleaver CreditAttribution: cleaver commentedI've done some work on the test for Morten's patch--cleaned up about half the fails so far. I'll post whatever I get done so that it can be reviewed.
Comment #49
cleaver CreditAttribution: cleaver commentedChanged the book.test for #43
Comment #50
xjmPlease add the newline here back (as per #45).
Comment #51
cleaver CreditAttribution: cleaver commentedFix that pesky newline :)
Comment #52
xjmYay!
Comment #53
JacineWait, what's going on here?
book.theme.css
orbook.base.css
contents that Morten added.book.theme.css
is loaded by default andbook.base.css
is not, but it also seems to make sense.Other than those issues the CSS, and comments look good. I think that the other patch is close. I'm going to go review it now.
For now, let's re-roll with just the CSS changes.
Comment #54
mortendk CreditAttribution: mortendk commented1 well wasn't aware of the work on the markup in another issue
im gonna move it out and post it over at the other issue, even imho i think thats double work .. ooh well.
hmm looks like book.base.css should actually be a book.admin.css instead
Comment #55
jyve CreditAttribution: jyve commentedLooking at the feedback from Jacine in #53, it feels like the patch in #42 is still correct, right? At least until the other patch get's in, and we can remove some css here.
@mortendk: this looks like a typical piece of CSS for a base.css instead of admin.css? It's basic hide/show behavior, not styling.
Comment #56
mortendk CreditAttribution: mortendk commentedyup but its only effective in the admin part of the module. Its not relevant to the rest of the modules functionality
The idea in .base.css is a crucial element to the overall modules functionality that you will always carry around, so in this case i would argue that its an "admin thing" and not a "overall functionality of the module"
so i think we should add it to the admin.css file & remove the base.css file in the book module.
... even that it could be seen as a little bikeshedding ;)
Comment #57
jyve CreditAttribution: jyve commentedOk then, one more attempt from my side :)
1. The editing of content can be done in frontend and backend theme, so the CSS currently in base.css would not be available if a user removes all theme.css files and would remove basic behavior in that way.
2. This is what is said in the issue description:
That said: I promise not to kill anyone for putting it in admin.css, so the decision is up to you :)
Comment #58
mortendk CreditAttribution: mortendk commentedhmm looks like we have hit the first "is it admin or base" dilemma
in my view its an administration task so it should be in the admin.css - its not crusial to the functionality of the module (aka it dosnt break anything if we leave it out) it just looks funky in the tab under book options with that big gray button.
I have rerolled it & killed the ID in the book-navigation.tpl - guess thats okay- even that we have the other issue about the general markup ?
could somebody else weight in here, so we can get a good concensus about the BAT files ?
Comment #59
mortendk CreditAttribution: mortendk commentedim an idiot this is the patch rerolled with the base.css -> admin.css renaming.
no markup changes etc. that we can take on later ? when this one is in ...
Comment #60
mortendk CreditAttribution: mortendk commented...and this time with review status #facepalm
Comment #61
xjmRegarding #58, I had similar doubts about a .admin.css in another issue. Is there a meta discussion somewhere for that point?
#60 looks pretty good, outside of that question. (I had no idea what to make of #43 but I sure knew it shouldn't take away our terminal newline.) ;)
An aside: When you mark an issue needs review, it tests all previously untested patches. So if you forget when you upload the patch, no need to upload it a second time--just set the status to needs review in a new comment and testbot will pick it up.
Comment #62
jessebeach CreditAttribution: jessebeach commented@xjm, have a look at this CSS Cleanup document that explains the rationale behind .admin.css files
http://drupal.org/node/1089868
Comment #63
JacineAlright... So, I am going to agree with @morten on this one. Sorry @jyve!
You've both got good points, but the main focus is front-end facing code. We could eventually start doing module.admin.base.css and module.admin.theme.css but that'd be a little out of hand right now. That's why there's only one-bucket for administrative CSS right now. Putting that code in .base.css would result in a wasted http request for code that's not going to be needed 80% of the time, so my vote is for .admin.css.
@xjm There's a bunch of discussion on #885228: CSS Files are in major need of clean up! and #777814: Allow modules to provide styles for themes (finally leverage structure/behavior split of CSS files). :)
Comment #64
mortendk CreditAttribution: mortendk commentednow that we have the theme.css file i have added the styles to bartiks style.css
screenshots added for both bartik & stark without theme.css
Comment #65
jyve CreditAttribution: jyve commentedOk so looks like I lost this one :)
Just looked at your last patch @mortendk, and I wonder why you duplicate the book.theme.css into Bartik? I don't see how this is usefull since it would make Bartik really bloated, or am I missing something here?
Comment #66
mortendk CreditAttribution: mortendk commentedmaybe its a brainfart from my side but shoudnt bartik work & look right without book.theme.css ?
... yeah guess it gets even more bloated ;)
im pretty sure were gonna stomp into more files where we cant figure out if they are base.css or admin.css
Comment #67
mortendk CreditAttribution: mortendk commentedjyve you absolutely right about the bartik css work unessesary bloat offcourse the theme.css will be used when people are using bartik *doh*
here we go its rerolled + i matched the colors so itsnt that ugly gray but the warmer that bartik are using allready. (if thats gonna keep this away from rtbc im gonna scream)
Comment #68
jyve CreditAttribution: jyve commentedTested the patch in #67, and I think we finally got it right!
Patch looks perfect to me.
Comment #69
mortendk CreditAttribution: mortendk commentedill set it to rtbc ...and do a little happy dance :)
Comment #70
xjmYou can't RTBC your own patch. :P
Comment #71
mortendk CreditAttribution: mortendk commentedi know xjm ;) but was hoping for a silent moment while i was dancing - can you review it
Comment #72
mortendk CreditAttribution: mortendk commentedIm moving the patch over to #736604: book module now without clearfix & better markup + accessibility love and marks this as a duplicate so we can roll the 2 of them together.
Comment #72.0
mortendk CreditAttribution: mortendk commentedAdd CSS Cleanup docs.