Part of the CSS Cleanup: http://drupal.org/node/1089868 & #1921610: [Meta] Architect our CSS

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 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 named module_name.module-rtl.css.

    module_name.theme.css: This file should hold extra styles to make the module's functionality aesthetically pleasing. This usually just consists of theme styles. Any needed RTL styling would go in a file named module_name.theme-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 named module_name.admin-rtl.css.

    module_name.admin.theme.css: This file should hold extra styles to make the module's admin screens aesthetically pleasing. This usually just consists of theme styles. Any needed RTL styling would go in a file named module_name.admin.theme-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

  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.

Comments

johnvsc’s picture

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

Assigned: Unassigned » mortendk

gimme...

mortendk’s picture

Status: Active » Needs review
StatusFileSize
new8.26 KB
droplet’s picture

+++ b/modules/user/user.theme.cssundefined
@@ -0,0 +1,69 @@
+/* Generated by user.module but used by profile.module: */

Can't it move to profile.module?

21 days to next Drupal core point release.

mortendk’s picture

the only thing this issues is about & this patch is doing moving the css files in so we can begin to use the bat name scheme.
to begin trying to fix all kinds of other problems isnt the role of this issue if its a problem that should be looked at i think you should open up a new issue

jacine’s picture

Profile module doesn't exist, so related code should be removed.

But, this issue and all of these aren't just about moving CSS and changing file names. We need to really get deep into the CSS, and the markup, if necessary and fix problems with the code. I am going to work on better instructions for what's going on in these issues and provide summaries.

jyve’s picture

StatusFileSize
new8.32 KB

Just tested the patch by @mortendk in #3. This is my feedback and summary of the new patch:

- The comment /* Generated by user.module but used by profile.module: */ is incorrect. The class .profile is added by the User module in user-profile.tpl.php. I updated the comment in the css to make this clear.
- The border under the .profile h2 seems useless, so that's been removed.
- The file user.css was empty but still present, so completely removed that one.
- Moved some css from user.theme-rtl.css to user.base-rtl.css since that css was overwriting css in user.base.css.
- added some margin to .password-strength to reflect the margin on .password-confirm.
- removed some more divs.

One more question for @mortendk: why was some of the css duplicated in Bartik?

aspilicious’s picture

Status: Needs review » Needs work
+++ b/modules/user/user.theme.cssundefined
@@ -0,0 +1,64 @@
+  margin-top: 1.5em;  ¶

trailing whitespace

+++ b/themes/bartik/css/style.cssundefined
@@ -1083,6 +1083,54 @@ div.password-confirm {
+
+
+
+
+
+

Way to much line breaks

Those duplicated css lines in Bartik should be removed

-28 days to next Drupal core point release.

aspilicious’s picture

And the profile stuff needs to be removed

jyve’s picture

A new patch will be posted tomorrow that removes the trailing whitespaces and the Bartik changes.

As mentioned earlier, the .profile css is added and used by the user module so I don't see why this should be removed?

droplet’s picture

is it possible to remove td.class, tr.class, div.class ?

jyve’s picture

Assigned: mortendk » jyve
Status: Needs work » Needs review
StatusFileSize
new8.63 KB

Here's a list of updates that can be found in the new patch:

- Rerolled against the new /core folder
- alphabetized all properties
- removed trailing white-space and other small spacing errors
- to avoid confusion and/or clashing with the profile module, I've changed the .profile class to .user-profile.
- removed this css since it no longer reflects the HTML cleanup in other patches:

.user-profile dl {
  margin: 0 0 1.5em 0;
}
.user-profile dt {
  font-weight: bold;
  margin: 0 0 0.2em 0;
}
.user-profile dd {
  margin: 0 0 1em 0;
}

- the user.admin.css was no longer included on the permissions and roles page after applying the patch.
- Removed this unnecessary css for the Account settings page:

#user-admin-settings .fieldset-description {
  font-size: 0.85em;
  padding-bottom:.5em;
}

- remove td/tr from selectors where possible
- added file headers
- other small fixes :)

aspilicious’s picture

Ultra quick dreditor scroll review

+++ b/core/modules/user/user.admin.cssundefined
@@ -0,0 +1,32 @@
+ * User roles form. ¶

trailing whitespace

-21 days to next Drupal core point release.

Status: Needs review » Needs work

The last submitted patch, user_css_cleanup-12170542-12.patch, failed testing.

jyve’s picture

Status: Needs work » Needs review
StatusFileSize
new9.4 KB

Two updates:

- Trailing white-space removed
- The RDF-test has been updated to reflect the switch from .profile to .user-profile.

aspilicious’s picture

Status: Needs review » Needs work
+++ b/core/modules/user/user.infoundefined
@@ -7,4 +7,5 @@ files[] = user.entity.inc
-stylesheets[all][] = user.css
+stylesheets[all][] = user.theme.css
+stylesheets[all][] = user.base.css

This loads this css on every page, seems like overkill... I think we can include it when we need it. When thats done we can remove these lines. Less crap in .info files++

Second thingie: this all seems admin css, so why is it inside theme.css? I tested the css and it looks great. So I can rtbc when my concerns are fixed or when someone proves me wrong.

-22 days to next Drupal core point release.

KrisBulman’s picture

speaking of unwanted design assumptions on the theme layer, do we really need to be floating the profile photo?

it has caused problems in the past due to a lack of clearing.. seems like something a theme should handle, not a module.

#67523: Looking at the user list the user picture stick out of the border

cosmicdreams’s picture

Assigned: jyve » cosmicdreams

on my list for tonight

cosmicdreams’s picture

Status: Needs work » Needs review

In this patch I:

  • removed user.base.css and user.theme.css from the .info file
  • made an effort to find all the places where I would need to include the user.base.css and user.theme.css files and used #attached to include them
  • modified the css so the user pictures aren't floated.

I'm unsure if I found all of the places where I need to include the css. Can someone please review this?

cosmicdreams’s picture

StatusFileSize
new10.13 KB

Forgot the attach the patch.

KrisBulman’s picture

not entirely sure not floating the user photo is the right approach, (especially for the solution in d7) just wanted to bring it up for discussion.

cosmicdreams’s picture

I suppose the floating user picture issue is weakened by the fact that we have that code in the user.theme.css file, which allows themers to simply turn off that file if they don't like the floating.

KrisBulman’s picture

great point, moving to theme.css resolves the concern from a themers perspective

& since the "History" H3 element with the border is no longer present in D8, the D7 issue has no bearings really.

cosmicdreams’s picture

ok, then I'll revert the removal of float from my patch in #20 (but I won't have an opportunity to do this until tonight.)

KrisBulman’s picture

Status: Needs review » Needs work
aspilicious’s picture

We hava to make sure the password css still works in every case (installation and changing password)

cluke009’s picture

Status: Needs work » Needs review
StatusFileSize
new5.16 KB

The patch from 20 no longer works with the latest git version.

I hand copied the changes and ran a new patch. Hopefully I caught everything.

Status: Needs review » Needs work

The last submitted patch, user-1217054-27.patch, failed testing.

Anonymous’s picture

Issue summary: View changes

Updated issue summary.

rteijeiro’s picture

Status: Needs work » Needs review
StatusFileSize
new3.19 KB

Rerolled the patch. Hope everything is right.

lewisnyman’s picture

Status: Needs review » Needs work
+++ b/core/modules/user/user.admin.cssundefined
@@ -0,0 +1,30 @@
+#permissions .module {
+  font-weight: bold;
+}
+#permissions .permission {
+  padding-left: 1.5em; /* LTR */
+}
+#permissions .odd .form-item,
+#permissions .even .form-item {
+  white-space: normal;
+}
+#user-admin-settings .details-description {
+  font-size: 0.85em;
+  padding-bottom: .5em;

These selectors don't seem to be inline our new SMACSS style guidelines. These selectors seem unnecessarily strong

rteijeiro’s picture

Status: Needs work » Needs review
StatusFileSize
new6.06 KB

Ok, I fixed the css files folder and the #permissions id, but I don't find where is the #user-admin-settings id defined.

rteijeiro’s picture

Issue summary: View changes

add meta issue it belongs to

rteijeiro’s picture

Issue summary: View changes

Updated summary to the latest CSS organization guidelines.

rteijeiro’s picture

StatusFileSize
new2.37 KB

Re-rolled with the latest changes in 8.x branch.

oriol masjuan’s picture

Starting to work on this.

oriol masjuan’s picture

Status: Needs review » Closed (duplicate)

This issue is continued in the https://drupal.org/node/2030539.

Closing.

oriol masjuan’s picture

Issue summary: View changes

Consensus was reached in both http://drupal.org/node/1921610 and at DrupalconPDX discussions that using "theme" over "skin" in the CSS class renaming effort is more straight-forward.