Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#46685 closed defect (bug) (fixed)

Site Health: audit the CSS and reduce specificity

Reported by: afercia's profile afercia Owned by: afercia's profile afercia
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.container can 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)

46685.diff (15.4 KB) - added by afercia 7 years ago.
46685.2.diff (15.4 KB) - added by afercia 7 years ago.

Download all attachments as: .zip

Change History (8)

#1 @afercia
7 years ago

Note: in #46621 I've started reducing specificity in the parts related to that specific issue.

@afercia
7 years ago

#2 @afercia
7 years ago

  • Keywords has-patch added; needs-patch removed

46685.diff

  • simplifies selectors and reduces specificity
  • .site-health is 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 wrap class: seems unnecessary and allows to simplify the headings rulesets
  • currently, the tables don't have thead elements: removed the related ruleset
  • renames css classes so some elements can be targeted directly
  • removes unnecessary properties e.g. display: block on div and nav elements

Note:

  • couldn't find a .spinner used in these pages: removed but please double check

@clorith when you have a chance, your testing/revision is welcome!

#3 @afercia
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.

Last edited 7 years ago by afercia (previous) (diff)

@afercia
7 years ago

#4 @afercia
7 years ago

  • Owner set to afercia
  • Resolution set to fixed
  • Status changed from new to closed

In 45071:

Coding Standards: Clean up the Site Health stylesheet.

  • reduces selectors specificity to avoid over-qualified selectors
  • removes unused rulesets / properties
  • renames some CSS classes

Fixes #46685.

#5 @afercia
7 years ago

In 45074:

Coding Standards: Improve the Site Health CSS for small screens.

Amends #45071.
See #46685.

#6 @spacedmonkey
7 years ago

  • Component changed from Administration to Site Health
Note: See TracTickets for help on using tickets.