#46685 closed defect (bug) (fixed)
Site Health: audit the CSS and reduce specificity
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 5.2 | Priority: | normal |
| Severity: | normal | Version: | 5.2 |
| Component: | Site Health | Keywords: | site-health has-patch |
| Focuses: | coding-standards | Cc: |
Description
Splitting this out from https://core.trac.wordpress.org/ticket/46573#comment:59
The Site Health CSS uses unnecessary overqualified selectors. For example:
body .health-check-accordion .health-check-accordion-trigger .badge.blue
Seems to me there's no reason to use a so high specificity: this stylesheet is enqueued only in the Site Health pages.
According to the WordPress CSS coding standards, specificity should be kept to the lower possible value. Reading https://make.wordpress.org/core/handbook/best-practices/coding-standards/css/#selectors two base principles should be applied:
- use specificity with responsibility
- refrain from using over-qualified selectors,
div.containercan simply be stated as.container
I'd recommend to review all the CSS part as new code merged in WordPress should meet the standards not only for mere compliance but also to illustrate best practices and for educational purposes.
Also, high specificity is one of the historical problems across the core stylesheets. New code should really reverse the trend and keep specificity to the lower possible value.
Attachments (2)
Change History (8)
#2
@
7 years ago
- Keywords has-patch added; needs-patch removed
- simplifies selectors and reduces specificity
.site-healthis a broad selector as it's applied on the body: shouldn't be used to target generic elements as they could live also in the admin menu, top bar, etc.- removes the
wrapclass: seems unnecessary and allows to simplify the headings rulesets - currently, the tables don't have
theadelements: removed the related ruleset - renames css classes so some elements can be targeted directly
- removes unnecessary properties e.g.
display: blockondivandnavelements
Note:
- couldn't find a
.spinnerused in these pages: removed but please double check
@clorith when you have a chance, your testing/revision is welcome!
#3
@
7 years ago
46685.2.diff refreshes the patch after recent line number changes.
Also, border-radius: 0.3em 0.3em 0 0; on the first accordion can be removed, as it has no effect.
Note: in #46621 I've started reducing specificity in the parts related to that specific issue.