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

Comments

jvc26’s picture

Assigned: Unassigned » jvc26
Status: Active » Needs review
StatusFileSize
new1.44 KB

First patch to try to clean up Menu module css.

devin carlson’s picture

Assigned: Unassigned » jvc26
StatusFileSize
new17.19 KB
new17.21 KB

Honestly, I think that we could just remove all of the menu css. There are only three styles in the menu.css file and they only make small changes to table column and cell contents sizes (which are best determined by the browser anyway).

There is almost no difference in presentation between using the styles and removing them.

.menu-operations {
  width: 100px;
}

Sets the size of the table cells which have the "edit" and "delete" buttons inside of them to 100px.

  • I see no reason for these cells to be any larger than the text that they contain.
  • A width isn't specified for other delete links like the ones on the content type page (admin/structure/types).
  • If the words "edit" and "delete", when translated into another language, are longer than 100px, the style does nothing.
.menu-enabled {
  width: 70px;
}

Sets the size of the table cells which have the "enabled" checkbox inside of them to 70px.

  • There is also no reason for these to have a specific width defined.
  • The width isn't specified for other enabled checkboxes like the ones on the modules page (admin/modules).
.menu-enabled input {
  margin-left:25px;
}

Adds 25px to the left of input checkboxes which are located inside of the "enabled" checkbox table cells.

  • There is no reason to have an arbitrary amount of spacing added to the checkboxes.
  • Checkboxes located in table cells are automatically centered. The margin ruins the centered positioning.
  • Margins are not added to checkboxes added on other pages such as the modules page (admin/modules).

Attached are two images: a before (with the styles) and an after (with the styles removed).

devin carlson’s picture

Assigned: jvc26 » Unassigned
StatusFileSize
new1015 bytes

And a patch to remove the css file and the lone reference to it.

aspilicious’s picture

Assigned: jvc26 » Unassigned

I disagree a bit.

This is unneeded. It looks even better without it.

.menu-enabled input {
  margin-left:25px;
}

But

.menu-operations {
  width: 100px;
}

and

.menu-enabled {
  width: 70px;
}

should stay.

We can leave it in admin.css or we can move it to bartik and seven.

skottler’s picture

StatusFileSize
new266 bytes

I've rerolled the patch and only removed .menu-enabled input.

aspilicious’s picture

Status: Needs review » Needs work

Anyway the file name should change. We have to move this to menu.admin.css. (see summary)

cosmicdreams’s picture

Looks like the patch in #5 needs some love. I'll see if I can make some headway tonight.

cosmicdreams’s picture

Looks like the patch in #5 needs some love. I'll see if I can make some headway tonight.

cosmicdreams’s picture

StatusFileSize
new1.38 KB

Here's a patch that rerolls #5, renames the css to menu.admin.css, and makes the appropriate change to menu.admin.inc

cosmicdreams’s picture

Status: Needs work » Needs review
aspilicious’s picture

Status: Needs review » Reviewed & tested by the community

Just tested this, looks good :)

webchick’s picture

Issue tags: +Coding standards

Tagging with coding standards, for Jennifer to take a look at.

jhodgdon’s picture

Status: Reviewed & tested by the community » Fixed

I was going to say this needed to be delayed due to being over threshold on critical tasks right now, but it's such a small patch (one line of code and the rest is CSS), I went ahead and committed it anyway. I don't think it will affect any other issues (hopefully). Thanks!

devin carlson’s picture

Status: Fixed » Needs work

I'm not usually one to disagree but I think that this should have been looked at a bit more closely.

I outlined some valid concerns in #2 which were only addressed, without explanation, by "but x and y should stay" in #4. I also provided screenshots which show that there is no benefit provided by the rules; they only provide inconsistency with other administration pages and introduce an unnecessarily large amount of white space.

Many of the core administration pages use a table with a row of "operations" links, such as:

  • Content types
  • Menu management
  • Taxonomy
  • Blocks
  • Modules
  • People

The menu management page is the only page in Drupal core that places a class on the table column (except for the modules page which uses the class for creating icons). It is also the only place where a defined width is applied to the operations column.

Lets say you are building an administration theme and want to modify the width of table cells, such as by restricting all cells to a maximum width by doing something like:

table td {max-width: 200px;}

This would work fine for every single table in core, except for the menu management table, since it specified its own width. Inconsistencies like this make theme developers, such as myself, sad. :(

Is there a good reason for keeping these rules? I also think the table classes should be gone, or those classes should be applied to operations links on every administration page (a separate issue).

aspilicious’s picture

If you're concerned please collect some links to tables in the drupal admin interface and I'll look at them and make a proper response and maybe kill those lines if you're correct.

dcmouyard’s picture

I don't have a problem with removing menu.admin.css, but those styles should definitely go into Seven and Bartik if it's removed.

dcmouyard’s picture

Issue summary: View changes

Updated issue summary.

chrisjlee’s picture

Issue summary: View changes

Updated issue summary.

ckrina’s picture

Assigned: Unassigned » ckrina

Start working on that

ckrina’s picture

Start working on that

ckrina’s picture

Assigned: ckrina » Unassigned
Status: Needs work » Fixed

Changes from #9 are already applied in the last commit:
- removed .menu-operations because it is not such class
- correct path for menu.admin.css

Marking as fixed because CSS is already cleaned and we will be able to close the hole #1921610 issue. Feel free to open a new issue to discuss any other topic related.

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Updating summary with the new css organization from #1887922