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 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 namedmodule_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 namedmodule_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 namedmodule_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 namedmodule_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
- 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 |
---|---|---|---|
#26 | simpletest-module-css-cleanup-1217040-26.patch | 3.51 KB | rteijeiro |
#24 | simpletest-css-cleanup-1217040-24.patch | 4.45 KB | rteijeiro |
#20 | 1217040-simpletest-css-cleanup-20.patch | 4.74 KB | rteijeiro |
#19 | 15-17-do-not-test.patch | 2.5 KB | droplet |
#17 | simpletest.patch | 3.4 KB | droplet |
Comments
Comment #2
mdm CreditAttribution: mdm commentedComment #3
tjhellmannHere is a first run at it. I changed the css file name to follow the BAT naming conventions. Also removed id selectors and tried to clean up the rest of the css.
Comment #4
dcmouyard CreditAttribution: dcmouyard commentedFixed coding style issues and added RTL style sheet.
Comment #6
dcmouyard CreditAttribution: dcmouyard commentedUpdated the tests to check for
simpletest.admin.css
instead ofsimpletest.css
.Comment #7
dcmouyard CreditAttribution: dcmouyard commentedComment #9
dcmouyard CreditAttribution: dcmouyard commentedI think the tests are fixed now...
Comment #10
sunThis needs another re-roll, since the test classes have been moved to new directories.
Comment #11
webchickMarked #1663164: Clean up css in simpletest module as a duplicate of this, but it may have more/different info.
Comment #12
droplet CreditAttribution: droplet commented.label class and then label tag ?
remove th ?
remove th ?
label and label class ?
same problem
remove tr ?
Comment #13
oresh CreditAttribution: oresh commented#9: simpletest-css-cleanup-1217040-9.patch queued for re-testing.
Comment #15
oresh CreditAttribution: oresh commentedreducing the weight of selectors.
Small css cleanup
Comment #17
droplet CreditAttribution: droplet commentedI removed it in favor to http://drupal.org/node/1252206
class is array
and few simple changes:
- simplify .class
- add .simpletest-verbose-message to item-list, don't override all item-list globally.
Comment #18
oresh CreditAttribution: oresh commented@droplet, thx :)
Can you please add diff to previous patch?
If the test turns green - marking rtbc
Comment #19
droplet CreditAttribution: droplet commented@oresh,
sure
Comment #20
rteijeiro CreditAttribution: rteijeiro commentedUpdated the css files names in the #17 patch.
Comment #20.0
rteijeiro CreditAttribution: rteijeiro commentedUpdated issue summary.
Comment #21
droplet CreditAttribution: droplet commented#20 doesn't include the new theme.css
Comment #22
rteijeiro CreditAttribution: rteijeiro commenteddroplet, what do you mean with the "new theme.css"?
I can't find this file in the simpletest module.
Comment #23
droplet CreditAttribution: droplet commented@rteijeiro,
You make the patch #20...and removed all our changes
Comment #24
rteijeiro CreditAttribution: rteijeiro commentedThe patches #17 and #19 had different changes so I had to review them line by line.
Reviewed all the patches and redone the changes.
I guess this patch is right now.
Comment #25
droplet CreditAttribution: droplet commented@rteijeiro,
Thanks.
#19 is a interdiff patch, showing the diff between #15 & #17. (For some reason, it lost the "interdiff" text in the patch file name)..Sorry!!
#17 is my final patch.
#24 looks fine :)
Cheers.
Comment #26
rteijeiro CreditAttribution: rteijeiro commentedRe-rolled with the latest changes in 8.x branch.
Comment #27
pakmanlhTested and migrated to the sanbox here #2030419: Clean up the CSS for Simpletest module
Comment #27.0
pakmanlhUpdated summary to the latest CSS organization guidelines.