This repository has been archived by the owner on Aug 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'latest' of github.com:bbc/psammead into new-inline-link…
…-styling
- Loading branch information
Showing
14 changed files
with
398 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# REMs vs EMs for spacing | ||
|
||
REMs and EMs can be used for spacing (padding/margins/line height). We chose REMs on the basis of clarity and no perceptible difference in rendering. | ||
|
||
## REMs | ||
|
||
The REM unit represents a size relative to the root element (e.g., the `font-size` of `<html>`). Unlike the EM, which may be different for each element, the REM is constant throughout the document. | ||
|
||
### Advantages | ||
|
||
Spacing will be global across `Psammead`. | ||
|
||
Ease of understanding: When we create a constant expressed in REMs (e.g. `export const GEL_SPACING = '0.5rem'`) that value, or values based of that value, stay constant, which adds simplicity from a developer perspective. | ||
|
||
``` | ||
// assumes the root font size is 16px, which is a common browser default | ||
export const GEL_SPACING = '0.5rem'; // 8px | ||
export const GEL_SPACING_DBL = GEL_SPACING * 2; // 16px | ||
export const GEL_SPACING_QUAD = GEL_SPACING * 4; // 32px | ||
``` | ||
|
||
REMs offer an easy transition from our current code base's use of pixels for padding. | ||
|
||
### Disadvantages | ||
|
||
REMs are not supported in IE8: https://caniuse.com/#search=REMs, but REMs are used on our production sites. IE8 is not a supported browser. However, spacing doesn't appear to break in IE8 when REMs are used: | ||
|
||
Pixels for padding: | ||
![latest-px-win7-ie8](https://user-images.githubusercontent.com/916416/43953551-46638fea-9c91-11e8-851a-ef74c2cee458.PNG) | ||
|
||
REMs for padding | ||
![rems-win7-ie8](https://user-images.githubusercontent.com/916416/43953553-46899366-9c91-11e8-8335-a0c833a4c5c9.PNG) | ||
|
||
<hr/> | ||
|
||
## EMs | ||
|
||
"Represents the calculated font-size of the element. If used on the font-size property itself, it represents the inherited font-size of the element."(MDN) | ||
|
||
### Advantages | ||
|
||
EMs are more flexible for sizing text and spacing in and around elements rather than pixels, because this unit is relative to the font size of its parent element. | ||
|
||
### Disadvantages | ||
|
||
Potential complexity of understanding due to nesting components, depending on how font size is implemented. It's harder to immediately understand what the current font size is that the EM is relative to: | ||
|
||
``` | ||
<style> | ||
.parent { | ||
font-size: 16px; | ||
} | ||
h1 { | ||
font-size: 2em; | ||
} | ||
.child { | ||
font-size: 0.75em; /* 12px */ | ||
padding-bottom: 1em; /* 12px - confusing! because it's relative to the current font-size, | ||
0.5em, which is 12px. */ | ||
} | ||
</style> | ||
<div class="parent"> | ||
<h1>I am a heading and I should be 32px</h1> | ||
<div class="child"> | ||
I am the child and I should be 12px | ||
</div> | ||
</div> | ||
``` | ||
|
||
## a11y | ||
|
||
- Both are resizable. | ||
- Both are used in production. | ||
- Both require a default font-size set in a resizable unit. An example implementation would be `font-size: 100%` on the `html` element. If, as authors, we provide a resizable default font-size alongside using REMs/EMs for spacing, we give user agents the ability to resize spacing. | ||
|
||
## Further reading: | ||
|
||
<ul> | ||
<li>https://developer.mozilla.org/en-US/docs/Web/CSS/length</li> | ||
<li>https://engageinteractive.co.uk/blog/em-vs-rem-vs-px</li> | ||
<li>https://zellwk.com/blog/rem-vs-em/</li> | ||
</ul> | ||
|
||
This spike arises from https://github.com/bbc/simorgh/issues/407. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
<!-- prettier-ignore --> | ||
| Version | Description | | ||
| ------- | ----------- | | ||
| 1.0.2 | [PR#722](https://github.com/bbc/psammead/pull/722) Fix hover cap on older browsers | | ||
| 1.0.1 | [PR#677](https://github.com/bbc/psammead/pull/677) Use `@bbc/[email protected]` | | ||
| 1.0.0 | [PR#679](https://github.com/BBC-News/psammead/pull/679) Bump version number | | ||
| 0.2.1 | [PR#644](https://github.com/BBC-News/psammead/pull/644) Fixes for screenreader UX | | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.