Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Foundations/Growing and Shrinking/Provide descriptive link text #27784

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
4 changes: 2 additions & 2 deletions foundations/html_css/flexbox/flexbox-growing-and-shrinking.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

This section contains a general overview of topics that you will learn in this lesson.

- You'll learn the 3 properties that are defined by the `flex` shorthand, and how to use them individually.

Check failure on line 9 in foundations/html_css/flexbox/flexbox-growing-and-shrinking.md

View workflow job for this annotation

GitHub Actions / Lint lesson files

Spaces after list markers

foundations/html_css/flexbox/flexbox-growing-and-shrinking.md:9:1 MD030/list-marker-space Spaces after list markers [Expected: 1; Actual: 3] https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md030.md

### The flex shorthand

Expand All @@ -22,7 +22,7 @@

In the above screenshot, `flex: 1` equates to: `flex-grow: 1`, `flex-shrink: 1`, `flex-basis: 0`.

Very often you see the flex shorthand defined with only _one_ value. In that case, that value is applied to `flex-grow`. So when we put `flex: 1` on our divs, we were actually specifying a shorthand of `flex: 1 1 0`.

Check failure on line 25 in foundations/html_css/flexbox/flexbox-growing-and-shrinking.md

View workflow job for this annotation

GitHub Actions / Lint lesson files

Emphasis style

foundations/html_css/flexbox/flexbox-growing-and-shrinking.md:25:57 MD049/emphasis-style Emphasis style [Expected: asterisk; Actual: underscore] https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md049.md

Check failure on line 25 in foundations/html_css/flexbox/flexbox-growing-and-shrinking.md

View workflow job for this annotation

GitHub Actions / Lint lesson files

Emphasis style

foundations/html_css/flexbox/flexbox-growing-and-shrinking.md:25:61 MD049/emphasis-style Emphasis style [Expected: asterisk; Actual: underscore] https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md049.md

#### Flex-grow

Expand All @@ -30,26 +30,26 @@

In the following example the `flex` shorthand has values for `flex-shrink` and `flex-basis` specified with their default values.

<p class="codepen" data-height="300" data-default-tab="html,result" data-slug-hash="YzQqvgK" data-editable="true" data-user="TheOdinProjectExamples" style="height: 300px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;">

Check failure on line 33 in foundations/html_css/flexbox/flexbox-growing-and-shrinking.md

View workflow job for this annotation

GitHub Actions / Lint lesson files

Multiline HTML tags should be surrounded by blank lines or code block delimiters

foundations/html_css/flexbox/flexbox-growing-and-shrinking.md:33 TOP005/blanks-around-multiline-html-tags Multiline HTML tags should be surrounded by blank lines or code block delimiters [ Expected blank lines/code block delimiters: { Before: 1, After: 1 } Actual blank lines/code block delimiters: { Before: 1, After: 0 } ] [Context: "<p class="codepen" data-height="300" data-default-tab="html,result" data-slug-hash="YzQqvgK" data-editable="true" data-user="TheOdinProjectExamples" style="height: 300px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;">"] https://github.com/TheOdinProject/curriculum/blob/main/markdownlint/docs/TOP005.md
<span>See the Pen <a href="https://codepen.io/TheOdinProjectExamples/pen/YzQqvgK">
flex-grow example</a> by TheOdinProject (<a href="https://codepen.io/TheOdinProjectExamples">@TheOdinProjectExamples</a>)
on <a href="https://codepen.io">CodePen</a>.</span>
</p>

Check failure on line 37 in foundations/html_css/flexbox/flexbox-growing-and-shrinking.md

View workflow job for this annotation

GitHub Actions / Lint lesson files

Multiline HTML tags should be surrounded by blank lines or code block delimiters

foundations/html_css/flexbox/flexbox-growing-and-shrinking.md:37 TOP005/blanks-around-multiline-html-tags Multiline HTML tags should be surrounded by blank lines or code block delimiters [ Expected blank lines/code block delimiters: { Before: 1, After: 1 } Actual blank lines/code block delimiters: { Before: 0, After: 0 } ] [Context: "</p>"] https://github.com/TheOdinProject/curriculum/blob/main/markdownlint/docs/TOP005.md
<script async src="https://cpwebassets.codepen.io/assets/embed/ei.js"></script>

#### Flex-shrink

`flex-shrink` is similar to `flex-grow`, but sets the "shrink factor" of a flex item. `flex-shrink` only ends up being applied if the size of all flex items is larger than their parent container. For example, if our 3 divs from above had a width declaration like: `width: 100px`, and `.flex-container` was smaller than `300px`, our divs would have to shrink to fit.

The default shrink factor is `flex-shrink: 1`, which means all items will shrink evenly. If you do _not_ want an item to shrink then you can specify `flex-shrink: 0;`. You can also specify higher numbers to make certain items shrink at a higher rate than normal.

Check failure on line 44 in foundations/html_css/flexbox/flexbox-growing-and-shrinking.md

View workflow job for this annotation

GitHub Actions / Lint lesson files

Emphasis style

foundations/html_css/flexbox/flexbox-growing-and-shrinking.md:44:100 MD049/emphasis-style Emphasis style [Expected: asterisk; Actual: underscore] https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md049.md

Check failure on line 44 in foundations/html_css/flexbox/flexbox-growing-and-shrinking.md

View workflow job for this annotation

GitHub Actions / Lint lesson files

Emphasis style

foundations/html_css/flexbox/flexbox-growing-and-shrinking.md:44:104 MD049/emphasis-style Emphasis style [Expected: asterisk; Actual: underscore] https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md049.md

Here's an example. Note that we've also changed the `flex-basis` for reasons that will be explained shortly. If you shrink your browser window you'll notice that `.two` never gets smaller than the given width of 250px, even though the `flex-grow` rule would otherwise specify that each element should be equally sized.

<p class="codepen" data-height="300" data-default-tab="html,result" data-slug-hash="JjJXZVz" data-editable="true" data-user="TheOdinProjectExamples" style="height: 300px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;">

Check failure on line 48 in foundations/html_css/flexbox/flexbox-growing-and-shrinking.md

View workflow job for this annotation

GitHub Actions / Lint lesson files

Multiline HTML tags should be surrounded by blank lines or code block delimiters

foundations/html_css/flexbox/flexbox-growing-and-shrinking.md:48 TOP005/blanks-around-multiline-html-tags Multiline HTML tags should be surrounded by blank lines or code block delimiters [ Expected blank lines/code block delimiters: { Before: 1, After: 1 } Actual blank lines/code block delimiters: { Before: 1, After: 0 } ] [Context: "<p class="codepen" data-height="300" data-default-tab="html,result" data-slug-hash="JjJXZVz" data-editable="true" data-user="TheOdinProjectExamples" style="height: 300px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;">"] https://github.com/TheOdinProject/curriculum/blob/main/markdownlint/docs/TOP005.md
<span>See the Pen <a href="https://codepen.io/TheOdinProjectExamples/pen/JjJXZVz">
flex-shrink example</a> by TheOdinProject (<a href="https://codepen.io/TheOdinProjectExamples">@TheOdinProjectExamples</a>)
on <a href="https://codepen.io">CodePen</a>.</span>
</p>

Check failure on line 52 in foundations/html_css/flexbox/flexbox-growing-and-shrinking.md

View workflow job for this annotation

GitHub Actions / Lint lesson files

Multiline HTML tags should be surrounded by blank lines or code block delimiters

foundations/html_css/flexbox/flexbox-growing-and-shrinking.md:52 TOP005/blanks-around-multiline-html-tags Multiline HTML tags should be surrounded by blank lines or code block delimiters [ Expected blank lines/code block delimiters: { Before: 1, After: 1 } Actual blank lines/code block delimiters: { Before: 0, After: 0 } ] [Context: "</p>"] https://github.com/TheOdinProject/curriculum/blob/main/markdownlint/docs/TOP005.md
<script async src="https://cpwebassets.codepen.io/assets/embed/ei.js"></script>

An important implication to notice here is that when you specify `flex-grow` or `flex-shrink`, flex items do not necessarily respect your given values for `width`. In the above example, all 3 divs are given a width of 250px, but when their parent is big enough, they grow to fill it. Likewise, when the parent is too small, the default behavior is for them to shrink to fit. This is not a bug, but it could be confusing behavior if you aren't expecting it.
Expand All @@ -58,7 +58,7 @@

`flex-basis` sets the initial size of a flex item, so any sort of `flex-grow`ing or `flex-shrink`ing starts from that baseline size. The shorthand value defaults to `flex-basis: 0%`. The reason we had to change it to `auto` in the `flex-shrink` example is that with the basis set to `0`, those items would ignore the item's width, and everything would shrink evenly. Using `auto` as a flex-basis tells the item to check for a width declaration (`width: 250px`).

> #### Important note about flex-basis:

Check failure on line 61 in foundations/html_css/flexbox/flexbox-growing-and-shrinking.md

View workflow job for this annotation

GitHub Actions / Lint lesson files

Trailing punctuation in heading

foundations/html_css/flexbox/flexbox-growing-and-shrinking.md:61:39 MD026/no-trailing-punctuation Trailing punctuation in heading [Punctuation: ':'] https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md026.md
>
> There is a difference between the default value of `flex-basis` and the way the `flex` shorthand defines it if no `flex-basis` is given. The actual default value for `flex-basis` is `auto`, but when you specify `flex: 1` on an element, it interprets that as `flex: 1 1 0`. If you want to _only_ adjust an item's `flex-grow` you can do so directly, without the shorthand. Or you can be more verbose and use the full 3 value shorthand `flex: 1 1 auto`, which is also equivalent to using `flex: auto`.

Expand All @@ -78,7 +78,7 @@

1. Read [W3C's flex section](https://www.w3.org/TR/css-flexbox-1/#flex-common) to understand the basic values of common flex shorthand values.

2. This [MDN Doc](https://developer.mozilla.org/en-US/docs/Web/CSS/flex) summarizes the entire flex shorthand values as well as introduces some new syntax that hasn't been covered in the previous article.
2. [MDN's documentation on flex](https://developer.mozilla.org/en-US/docs/Web/CSS/flex) summarizes the entire flex shorthand values, as well as introduces some new syntax that hasn't been covered in the previous article.

</div>

Expand All @@ -93,6 +93,6 @@

This section contains helpful links to related content. It isn’t required, so consider it supplemental.

* [Check out this video](https://www.youtube.com/watch?v=u044iM9xsWU&t=1s&pp=ugMICgJhchABGAE%3D) explaining how flexbox works and why.
* A [video exploring how flexbox works and why](https://www.youtube.com/watchv=u044iM9xsWU&t=1s&pp=ugMICgJhchABGAE%3D).

* For an interactive explanation and demo, check out the [Scrim on the flex shorthand](https://scrimba.com/learn/flexbox/the-flex-property-flexbox-tutorial-cGNKJTv). For an alternative explanation you can view the [Scrim on using flex-grow, flex-shrink, and flex-basis](https://scrimba.com/learn/flexbox/flex-grow-shrink-basis-flexbox-tutorial-ck6L7fv). Note that these Scrims require logging into Scrimba in order to view.