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 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.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 named module_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 named module_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 named module_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

  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.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

xjm’s picture

Assigned: Unassigned » xjm

I'll work on this.

cosmicdreams’s picture

forum isn't using drupal_add_css to include css files but dashboard does. Are we ok with the inconsistent approach to delivering css files?

Oh and wasn't forum going to be eliminated for D8?

cosmicdreams’s picture

Here's a patch to get this issue started. It renames forum.css to forum.base.css, moves most of the css into the newly created forum.theme.css and loads these css files with the forum.info file.

TODO: prune forum.theme.css for styles that are not needed.

cosmicdreams’s picture

Status: Active » Needs review

Setting to needs review so that the patch can be evaluated by the testbot. I'd like to know if there's something wrong with the way I'm making patches.

xjm’s picture

Assigned: xjm » Unassigned

Yeah, I clearly forgot about this. :)

aspilicious’s picture

Status: Needs review » Needs work
+++ b/core/modules/forum/forum.base.cssundefined
@@ -0,0 +1,17 @@
+  float: left; /* LTR */

There are no rtl files

+++ b/core/modules/forum/forum.base.cssundefined
@@ -0,0 +1,17 @@
+}
\ No newline at end of file

newline needed

And I don't think there should be a theme file, this all looks base.css

dcmouyard’s picture

Status: Needs work » Needs review
FileSize
4.49 KB

Removed unecessary styles, including the float on the icon. An RTL style sheet is no longer needed.

Added classes to table markup and used .forum-table instead of #forum.

andypost’s picture

#7 makes more sense also there's a #821702: Replace Forum Icon Column with Topic Span whick affects icon

andypost’s picture

Issue tags: -html5, -Front end

#7: forum-css-cleanup-1217002-7.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +html5, +Front end

The last submitted patch, forum-css-cleanup-1217002-7.patch, failed testing.

oresh’s picture

Status: Needs work » Needs review
FileSize
2.82 KB

CSS cleanup for latest build.
Reducing selector weight by replacing id with class where possible.

rteijeiro’s picture

Status: Needs review » Needs work

Maybe this selector must be less specific in forum-rtl.css file:

Change .forum div.indent { to .forum .indent {

The rest changes seems ok for me.

rteijeiro’s picture

Issue summary: View changes

Updated issue summary.

rteijeiro’s picture

Status: Needs work » Needs review
FileSize
2.25 KB

Re-rolled with the latest changes and fixed some strict selectors.

pakmanlh’s picture

Status: Needs review » Closed (duplicate)

The work here has been migrated to the Sandbox issue #2028049: Clean up the CSS for Forum module

pakmanlh’s picture

Issue summary: View changes

Updating summary to the latests CSS organization guidelines

LewisNyman’s picture

Issue summary: View changes
Status: Closed (duplicate) » Needs review
LewisNyman’s picture

Issue tags: -Front end +frontend, +CSS

Reopening as the changes from the sandbox were never merged into core.

LewisNyman’s picture

Status: Needs review » Closed (duplicate)