Problem/Motivation

We don't have anything in our CSS standards about which units to use and when, apart from media queries

We have a really inconsistent implementation just in Seven alone, it would be nice to have some guidance for contributors.

Proposed resolution

Use rem units preceded by px units for a safe fallback, unless it creates an undesired effect.

Remaining tasks

Discuss
Agree
Add to the standards document

User interface changes

None

API changes

None

Comments

sarahjean’s picture

Agree. Seems like rems would be a good choice, although ems would also be fine.

smira’s picture

I would suggest rems with a px fallback (or not, since I believe we're not supporting IE8, correct?).

chippper’s picture

As we're not supporting IE8, especially on the admin side, I would suggest standardizing on rem's. It has excellent browser support -http://caniuse.com/#feat=rem - and is the best of both worlds. You get the benefits of relative font size units (scales nicely), but the numbers don't make your head implode. More info here: http://snook.ca/archives/html_and_css/font-size-with-rem

nod_’s picture

Issue tags: +ie8
karolus’s picture

Agree. rems are a good choice, ems for fallback. With more users moving to mobile, pixels are becoming a hassle to work with, especially with retina and other high-resolution formats.

LewisNyman’s picture

hmm, looks like the current version of Opera mini still doesn't support rem. In that case I would prefer a pixel declaration before the rem. It's useful as documentation to understand the size and also as a fallback. Pixels aren't much harder to work with on different resolution displays because a CSS pixel is different to the device pixel A pixel identity crisis

Another point, this is clear we should use this technique for font sizes but should we use it for everything else? Padding? Margins?

sarahjean’s picture

I think it makes sense to use it for padding and margin also, then everything continues to resize relatively. One of the big benefits to ems/rems in my opinion. The pixel fallback makes sense if we go with rem.

LewisNyman’s picture

But when you increase the font size, do you want to increase horizontal padding? You're reducing availiable space for text as the text size is gettign bigger, that's going to result in sub-optimal line lengths?

rem > em in my opinion.

rootwork’s picture

Well damn Opera Mini, that really sucks that they don't support rems yet. Weird.

Given that, I'd support rems with pixel fallbacks.

Relative units should definitely be used for padding/margins between blocks of text -- paragraphs and menu items, for instance. The margins are logically related to the size of the text and should vary based on the size of the text.

Padding/margins around boxes (regions, entities, etc.) are trickier because of the issue you raised, Lewis, but I think it still makes sense to use relative units for those. It's true that if you dramatically increase or decrease text size, line lengths are going to get comically too short or too long. But most text resizing is done at smaller intervals, and the relationship between an element's padding/margin and its text size will still be strong. (And, of course, if the window itself is being resized, we'll have media queries to just set different padding/margins.)

So I'd go with rems + pixels for everything.

LewisNyman’s picture

I would prefer a simple rule like that that's easy to understand instead of having exceptions. Who wants to update the documentation?

LewisNyman’s picture

Sorry wait, if we use rems and pixels for everything, that's going to require a lot more code to be added for everywhere use margin/padding in core with equivalents for RTL?

LewisNyman’s picture

Sorry I totally derailed this issue with indecision. Yes let's do px+rem for everything. I think we can make one big patch that changes all the units in core. I've added guidance to the CSS standards and updated the code examples: https://www.drupal.org/node/1887862

Use rem units preceded by px units for a safe fallback, unless it creates an undesired effect.

Note the caveat here, there may be some properties that look strange when scaled up, like borders or box shadows, so ultimately it's a judgment call.

bryanbraun’s picture

Issue summary: View changes

So since we don't support IE8, is the px fallback just for Opera mini?

The reason I ask is that putting in place a px fallback for every instance of rems adds some CSS bloat... something we wouldn't want to introduce unless there is a good reason. To be explicit, this is my understanding of how the changes affect a rule in Bartik:

Before:

.sidebar h2 {
  margin: 0 0 0.5em;
  border-bottom: 1px solid #d6d6d6;
  padding-bottom: 5px;
  text-shadow: 0 1px 0 #fff;
  font-size: 1.071em;
  line-height: 1.2;
}

After:

.sidebar h2 {
  margin: 0 0 8px;
  margin: 0 0 0.5rem;
  border-bottom: 1px solid #d6d6d6;
  border-bottom: 0.063rem solid #d6d6d6;
  padding-bottom: 5px;
  padding-bottom: 0.313rem;
  text-shadow: 1px 0 #fff;
  text-shadow: 0 0.063rem 0 #fff;
  font-size: 17px;
  font-size: 1.071rem;
  line-height: 1.2;
}

Looking at this Opera Mini release post, it looks like Opera mini support for REMS is in the works, and once it's added all users will immediately be "upgraded" (since Opera mini uses server-side rendering). How likely is it that they support REMs by the time Drupal 8 is released? I don't know.

I support the current consensus (rem with px as fallbacks). It's going to be some work to add in all the fallbacks and (inevitably) pull them out again, but oh well.

(also updating the issue summary)

LewisNyman’s picture

Issue tags: +CSS, +Coding standards

Let's sort this out, shall we specify rems for font size properties only? That makes it a lot easier to implement and to be honest that's the most important property. Happy to go REM only in this situation.

axe312’s picture

As u can see on caniuse.com the REM issue is now fixed on Opera Mobile. With the server side rendering, all clients should be automatically support it now.

If we decide to move only some values to REM, I'd love to see media queries also using rem instead of pixel/em.

We should also keep the known issues in mind, in my opinion especially the line-height issue in IE and the borders in chrome. The problems with some (old?) Android phones should not bother us, for every day D8 takes longer, the usage of older mobile browsers should drop :)

LewisNyman’s picture

LewisNyman’s picture

This tweet captures what I was trying to say and failing. We can't just choose one unit and enforce it. It's about picking the right unit for the right job.

What is your sizing based on?

  • Containing block size? → Use percents.
  • Viewport size? → Use viewport units: vw, vh, vmin, vmax
  • Font height? → Use em or rem.
  • Font pitch? → Use em or ch.
  • Content size? → Use auto or min-content/max-content.
  • Combination of the above? → Use the appropriate layout formulas: flex, min-width, max-width, etc.

Absolute units are usually the wrong answer.

WARNING: Requires Critical Thinking

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Active » Postponed (maintainer needs more info)

Believe with the switch to claro and olivero a much more standard approach has been taken.

Could this be close.d