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

CSS Functions: Replace clamp() function explanation #27707

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 5 additions & 6 deletions intermediate_html_css/intermediate_css_concepts/css_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
--footer: 40px;
--main: calc(100vh - calc(var(--header) + var(--footer)));
}
```

Check failure on line 53 in intermediate_html_css/intermediate_css_concepts/css_functions.md

View workflow job for this annotation

GitHub Actions / Lint lesson files

Fenced code blocks should be surrounded by blank lines

intermediate_html_css/intermediate_css_concepts/css_functions.md:53 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"] https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md031.md
- `--header`, `--footer`, and `--main` are all examples of CSS variables. You will be learning about these in the next lesson.

Check failure on line 54 in intermediate_html_css/intermediate_css_concepts/css_functions.md

View workflow job for this annotation

GitHub Actions / Lint lesson files

Lists should be surrounded by blank lines

intermediate_html_css/intermediate_css_concepts/css_functions.md:54 MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "- `--header`, `--footer`, and ..."] https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md032.md

Setting main to equal the outcome of: `100vh - (3rem + 40px)`.
To put it another way: `main = 100vh - (header + footer)`.
Expand Down Expand Up @@ -87,12 +87,12 @@
Focus on this line `width: min(150px, 100%);` we can make several observations:
If there are `150px` available to the image, it will take up all `150px`.
If there are not `150px` available, the image will switch to `100%` of the parent's width.
In the first case `min()` selects `150px`, since `150px` is the smaller (the minimum) between `150px` and `100%` of the parent's width; in the second, it chooses `100%`. `min()` behaves as a boundary for the _maximum_ allowed value, which in this example is `150px`.

Check failure on line 90 in intermediate_html_css/intermediate_css_concepts/css_functions.md

View workflow job for this annotation

GitHub Actions / Lint lesson files

Emphasis style

intermediate_html_css/intermediate_css_concepts/css_functions.md:90:209 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 90 in intermediate_html_css/intermediate_css_concepts/css_functions.md

View workflow job for this annotation

GitHub Actions / Lint lesson files

Emphasis style

intermediate_html_css/intermediate_css_concepts/css_functions.md:90:217 MD049/emphasis-style Emphasis style [Expected: asterisk; Actual: underscore] https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md049.md
<br>You are able to do basic math inside a `min ( )` => for example: `width: min(80ch, 100vw - 2rem);`

Check failure on line 91 in intermediate_html_css/intermediate_css_concepts/css_functions.md

View workflow job for this annotation

GitHub Actions / Lint lesson files

Inline HTML

intermediate_html_css/intermediate_css_concepts/css_functions.md:91:1 MD033/no-inline-html Inline HTML [Element: br] https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md033.md

### max()

Max works the same way as min, only in reverse. It will select the largest possible value from within the parentheses. You can think of `max()` as ensuring a _minimum_ allowed value for a property.

Check failure on line 95 in intermediate_html_css/intermediate_css_concepts/css_functions.md

View workflow job for this annotation

GitHub Actions / Lint lesson files

Emphasis style

intermediate_html_css/intermediate_css_concepts/css_functions.md:95:159 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 95 in intermediate_html_css/intermediate_css_concepts/css_functions.md

View workflow job for this annotation

GitHub Actions / Lint lesson files

Emphasis style

intermediate_html_css/intermediate_css_concepts/css_functions.md:95:167 MD049/emphasis-style Emphasis style [Expected: asterisk; Actual: underscore] https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md049.md

Consider the following property of a given element:

Expand All @@ -107,20 +107,19 @@

### clamp()

`clamp()` is a great way to make elements fluid and responsive.
`clamp()` takes 3 values:
Imagine you're designing a website and want headings to look good on any device, from a tiny phone screen to a giant monitor. The `clamp()` function is like a tool that helps you set the perfect size for your headings on any screen.

```css
h1 {
font-size: clamp(320px, 80vw, 60rem);
}
```

1. the smallest value (320px)
2. the ideal value (80vw)
3. the largest value (60rem)
1. **Minimum size (320px in the example):** This is like the narrowest the heading can get. Even on a super small screen, the heading won't shrink any smaller than 320px so it stays readable.
2. **Ideal size (80vw in the example):** This is the sweet spot where you want the heading to be most of the time. The `vw` unit means "viewport width" - so 80vw makes the heading size 80% of the width of the screen. This makes it flexible and adjusts as the screen size changes.

Check failure on line 119 in intermediate_html_css/intermediate_css_concepts/css_functions.md

View workflow job for this annotation

GitHub Actions / Lint lesson files

Ordered list item prefix

intermediate_html_css/intermediate_css_concepts/css_functions.md:119:1 MD029/ol-prefix Ordered list item prefix [Expected: 1; Actual: 2; Style: 1/1/1] https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md029.md
3. **Maximum size (60rem in the example):** This is like a safety guard to prevent the heading from getting too big on very large screens. Here, 60rem is the largest the heading can be.

Check failure on line 120 in intermediate_html_css/intermediate_css_concepts/css_functions.md

View workflow job for this annotation

GitHub Actions / Lint lesson files

Ordered list item prefix

intermediate_html_css/intermediate_css_concepts/css_functions.md:120:1 MD029/ol-prefix Ordered list item prefix [Expected: 1; Actual: 3; Style: 1/1/1] https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md029.md

The `clamp()` CSS function uses these values to set the smallest value, ideal value and largest value. In the above example, this would mean the smallest acceptable font-size would be 320px and the largest would be 60rem. The ideal font-size would be 80vw.
So, the `clamp()` function considers the screen size and makes sure the heading stays within a comfortable reading range, no matter what device someone is using!

### Assignment

Expand All @@ -131,7 +130,7 @@

### Knowledge check

- [What are the four CSS math functions we covered above?](#function-names-knowledge-check)

Check failure on line 133 in intermediate_html_css/intermediate_css_concepts/css_functions.md

View workflow job for this annotation

GitHub Actions / Lint lesson files

Sections have default content

intermediate_html_css/intermediate_css_concepts/css_functions.md:133 TOP003/default-section-content Sections have default content [Expected default section content to precede the unordered list of knowledge checks: "The following questions are an opportunity to reflect on key topics in this lesson. If you can't answer a question, click on it to review the material, but keep in mind you are not expected to memorize or master this knowledge."] https://github.com/TheOdinProject/curriculum/blob/main/markdownlint/docs/TOP003.md
- [How do we use CSS math functions in our CSS?](#what-is-a-function-and-how-are-they-used-in-css)
- [How can CSS functions help make websites and applications more responsive?](#responsive-design-knowledge-check)

Expand Down