Part of the CSS Cleanup: http://drupal.org/node/1089868

Overview of Goals

  1. Make it easy to remove unwanted design assumptions in the theme layer, while maintaining critical functionality (such as functional JavaScript widgets).
  2. Prevent uneeded administrative styles from loading on the front end.
  3. Give modules the ability to include a generic design implementation with their module, without burdening themers.
  4. 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.

  1. 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.

  2. 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.
  3. 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 {} over div.style {} where possible.
    • Use .module .style {} over div.module div.somenestedelement .style where possible.
  4. 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.
  5. 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.
  6. Start with Stark and cross-browser test.
    1. "Design" markup and CSS for the Stark theme.
    2. If applicable, adapt the styles to match the core themes afterward.
    3. Finally, test the changes in all supported browsers and ensure no regressions are introduced.
CommentFileSizeAuthor
#67 book bartik.jpg77.68 KBmortendk
#67 book stark.jpg80.88 KBmortendk
#67 book-bartik-no theme_css.jpg79.37 KBmortendk
#67 book-stark-no theme_css.jpg37.51 KBmortendk
#67 book-css-bartik.patch4.39 KBmortendk
#64 book bartik.jpg77.68 KBmortendk
#64 book stark.jpg80.88 KBmortendk
#64 bartik without .theme_.css_.jpg64.57 KBmortendk
#64 book-css-with-bartik-love.patch5.3 KBmortendk
#60 book-only-css-forrealz.patch3.96 KBmortendk
#59 book-only-css-forrealz.patch3.96 KBmortendk
#58 book-only-css.patch4.41 KBmortendk
#51 book-1216970-51.patch6.23 KBcleaver
#49 book-1216970-49.patch6.29 KBcleaver
#43 book.patch5.64 KBmortendk
#42 book-1216970-42.patch3.97 KBjyve
#39 book-1216970-39.patch3.86 KBjyve
#38 book-1216970-38.patch3.58 KBjyve
#36 Bartik-Book-patched.png23.32 KBmgifford
#36 Bartik-book.png23.29 KBmgifford
#36 Seven-Book-patch.png18.83 KBmgifford
#36 Seven-Book.png18.42 KBmgifford
#35 1216970-reroll.patch3.65 KBTR
#33 1216970-all.patch3.73 KBTR
#32 1216970.patch2.3 KBTR
#30 book-1216970-2.patch3.73 KBmortendk
#28 book-1216970.patch3.72 KBmortendk
#26 book-1216970.patch1.98 KBmortendk
#21 1216970.patch3.28 KBmortendk
#20 1216970.patch3.28 KBmortendk
#18 1216970.patch3.28 KBmortendk
#18 book-with-themecss.png49.2 KBmortendk
#18 book-clean.png53.61 KBmortendk
#14 1216970.patch3.77 KBmortendk
#12 1216970-book-css12.patch3.89 KBmortendk
#9 1216970-book-css5.patch3.14 KBmortendk
#8 1216970-book-css5.patch3.19 KBmortendk
#7 1216970-book-css5.patch2.42 KBmortendk
#5 1216970-book-css5.patch1.71 KBmortendk
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mdm’s picture

Title: Clean up the CSS for Book module » Clean up the CSS for Book module
mortendk’s picture

tag

mortendk’s picture

Assigned: Unassigned » mortendk

taking this one

mortendk’s picture

FileSize
1.71 KB

split 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 ?

Jacine’s picture

Woot! Happy that you are working on this Morten! Go go go :)

mortendk’s picture

Status: Active » Needs review
FileSize
2.42 KB

Forgot the admin.theme.css file

mortendk’s picture

FileSize
3.19 KB

forgot the book.theme.css file

mortendk’s picture

FileSize
3.14 KB

newlines added ...

Jacine’s picture

Status: Needs review » Needs work

Okay, just reviewed this and found a couple of issues with the patch:

  1. It's not properly deleting the book.css and book-rtl.css files for some reason. Did you delete the contents of the file and not the file itself? I tried this using the git add -N for the new files and deleted the old ones and it worked properly for me.
  2. The RTL file should be in the patch. It should be changed to book.theme-rtl.css.
  3. _book_admin_table_tree() doesn't seem like the right place to load book.admin.css. I'm going to ask around about this.
  4. The rest looks good to me! Go Morten go! :D

tstoeckler’s picture

+++ b/modules/book/book.admin.inc
@@ -174,6 +174,7 @@ function _book_admin_table($node, &$form) {
+  drupal_add_css(drupal_get_path('module', 'book') . '/book.admin.css');

This should use the #attached syntax.

mortendk’s picture

Status: Needs work » Needs review
FileSize
3.89 KB

this should do it

Status: Needs review » Needs work

The last submitted patch, 1216970-book-css12.patch, failed testing.

mortendk’s picture

Status: Needs work » Needs review
FileSize
3.77 KB

okay lets try again
have no clue why evil test bot dont give me any love

Jacine’s picture

Yeah, 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.

mortendk’s picture

yeah tried to get that one in but evil bot keept messing with me

sun’s picture

Status: Needs review » Needs work
+++ b/modules/book/book.admin.inc
@@ -174,6 +174,7 @@ function _book_admin_table($node, &$form) {
 function _book_admin_table_tree($tree, &$form) {
+  drupal_add_css(drupal_get_path('module', 'book') . '/book.admin.css');

This 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.

mortendk’s picture

Status: Needs work » Needs review
FileSize
53.61 KB
49.2 KB
3.28 KB

the 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.

Status: Needs review » Needs work

The last submitted patch, 1216970.patch, failed testing.

mortendk’s picture

FileSize
3.28 KB

didnt get the new files ...

mortendk’s picture

Status: Needs work » Needs review
FileSize
3.28 KB

lets try with the need review added ..

Status: Needs review » Needs work

The last submitted patch, 1216970.patch, failed testing.

mortendk’s picture

can 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;
+}

tim.plunkett’s picture

@mortendk, that patch looks whack. If you upload a zip of the book module directory, I can reroll a patch for you...

Dave Reid’s picture

@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.

mortendk’s picture

Status: Needs work » Needs review
FileSize
1.98 KB

alright one more time for prince knud

Status: Needs review » Needs work

The last submitted patch, book-1216970.patch, failed testing.

mortendk’s picture

Status: Needs work » Needs review
FileSize
3.72 KB
sun’s picture

Status: Needs review » Needs work

Looks pretty much RTBC after changing that drupal_add_css() call into #attached

mortendk’s picture

Status: Needs work » Needs review
FileSize
3.73 KB
droplet’s picture

Status: Needs review » Needs work

needs alphabetized properties :)
http://drupal.org/node/302199

TR’s picture

Status: Needs work » Needs review
FileSize
2.3 KB

Re-rolled #30 with alphabetized properties. I also checked all the modified CSS against the CSS coding standards, and found no other problems.

TR’s picture

FileSize
3.73 KB

Disregard #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.

mgifford’s picture

Subscribe. Hope to see this get into D8 -> #736604: book module now without clearfix & better markup + accessibility love without bumping into this cleanup initiative.

TR’s picture

FileSize
3.65 KB

Rerolled patch to account for changes committed in #120368: Book outline page breaks my site layout

@mgifford: Can you review this?

mgifford’s picture

I tested this against core. It looks good. Thanks for keeping up with core!

Jacine’s picture

Component: book.module » CSS
Issue tags: +D8H5

Updated the issue summary to include full information about what "clean up" means.

jyve’s picture

FileSize
3.58 KB

Just 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.

.js #edit-book-pick-book {
  display: none;
}
.form-item-book-bid .description {
  clear: both;
}

- The last css rule in admin.css adds a useless float, since that form-item is nicely handled by the draggable table layout.

#book-admin-edit .form-item {
  float: left;
}

- Since (re)moving these rules empties the admin.css, I've removed it entirely.

New patch attached!

jyve’s picture

FileSize
3.86 KB

Added @file and block level comments as requested in another thread.

xjm’s picture

Issue tags: +Novice

Thanks 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.

xjm’s picture

Status: Needs review » Needs work

Oops, forgot to set status.

jyve’s picture

Assigned: mortendk » jyve
Status: Needs work » Needs review
FileSize
3.97 KB

Rerolled the patch for the new folder structure.

mortendk’s picture

Assigned: jyve » mortendk
FileSize
5.64 KB

put the book navigation into

  • and added the pager class so it follow the same markup & classname's as the normal pager
    remove the book-navigation- print $book_id; id to stop the ID madness.
  • Status: Needs review » Needs work

    The last submitted patch, book.patch, failed testing.

    xjm’s picture

    Status: Needs work » Needs review
    +++ b/core/modules/book/book-navigation.tpl.phpundefined
    @@ -30,22 +30,22 @@
    \ No newline at end of file
    

    Note 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.)

    xjm’s picture

    Status: Needs review » Needs work

    And apparently it also needs some other work. :)

    mortendk’s picture

    ooh my so i also have to rewrite the .test file ?
    - this patch made the navigation have the same markup as the pagers ?

    cleaver’s picture

    I'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.

    cleaver’s picture

    Status: Needs work » Needs review
    FileSize
    6.29 KB

    Changed the book.test for #43

    xjm’s picture

    Status: Needs review » Needs work
    +++ b/core/modules/book/book-navigation.tpl.phpundefined
    @@ -30,22 +30,22 @@
    +<?php endif; ?>
    \ No newline at end of file
    

    Please add the newline here back (as per #45).

    cleaver’s picture

    Status: Needs work » Needs review
    FileSize
    6.23 KB

    Fix that pesky newline :)

    xjm’s picture

    Yay!

    Jacine’s picture

    Status: Needs review » Needs work

    Wait, what's going on here?

    1. The markup changes need to be removed. That's being worked on #736604: book module now without clearfix & better markup + accessibility love. We can't just hijack that work and bring it over here without even saying anything. This is why I suggested combining the 2 issues, but that would require doing a review and adding the CSS in the other issue.
    2. The latest patch doesn't add the book.theme.css or book.base.css contents that Morten added.
    3. It's a little odd that book.theme.css is loaded by default and book.base.css is not, but it also seems to make sense.
    4. The CSS properties need to be in alphabetical order.

    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.

    mortendk’s picture

    1 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

    jyve’s picture

    Looking 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.

    .js #edit-book-pick-book {
      display: none;
    }
    
    mortendk’s picture

    yup 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"

    module.admin.css
    Should hold styles that are only applicable to administrative pages.

    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 ;)

    jyve’s picture

    Ok 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:

    Should hold structural and behavior related styling

    That said: I promise not to kill anyone for putting it in admin.css, so the decision is up to you :)

    mortendk’s picture

    FileSize
    4.41 KB

    hmm 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 ?

    mortendk’s picture

    im 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 ...

    mortendk’s picture

    Status: Needs work » Needs review
    FileSize
    3.96 KB

    ...and this time with review status #facepalm

    xjm’s picture

    Regarding #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.

    jessebeach’s picture

    @xjm, have a look at this CSS Cleanup document that explains the rationale behind .admin.css files

    http://drupal.org/node/1089868

    Jacine’s picture

    Alright... 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). :)

    mortendk’s picture

    now 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

    jyve’s picture

    Ok 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?

    mortendk’s picture

    maybe 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

    mortendk’s picture

    jyve 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)

    jyve’s picture

    Tested the patch in #67, and I think we finally got it right!

    Patch looks perfect to me.

    mortendk’s picture

    Status: Needs review » Reviewed & tested by the community

    ill set it to rtbc ...and do a little happy dance :)

    xjm’s picture

    Status: Reviewed & tested by the community » Needs review

    You can't RTBC your own patch. :P

    mortendk’s picture

    i know xjm ;) but was hoping for a silent moment while i was dancing - can you review it

    mortendk’s picture

    Status: Needs review » Closed (duplicate)

    Im 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.

    mortendk’s picture

    Issue summary: View changes

    Add CSS Cleanup docs.