You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: curriculum/challenges/english/blocks/lecture-what-is-css/672acc03c257524d6a5151e8.md
+13-1Lines changed: 13 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ challengeType: 19
5
5
dashedName: how-do-width-and-height-work
6
6
---
7
7
8
-
# --description--
8
+
# --interactive--
9
9
10
10
In CSS, the `width` and `height` properties are used to control the dimensions of elements on a webpage.
11
11
@@ -17,6 +17,8 @@ The `height` property specifies the height of an element. Similarly, the height
17
17
18
18
Here's an example using the `width` and `height` properties:
19
19
20
+
:::interactive_editor
21
+
20
22
```html
21
23
<head>
22
24
<style>
@@ -32,6 +34,8 @@ Here's an example using the `width` and `height` properties:
32
34
</body>
33
35
```
34
36
37
+
:::
38
+
35
39
In this example, we have a `div` element with class named `box`. This element will be occupying `100px` in height and width, whereas the background color will be `skyblue`.
36
40
37
41
Pixels are a fixed-size unit of measurement in CSS, providing precise control over dimensions.
@@ -42,6 +46,8 @@ The `min-height` specifies the minimum height an element can be. It ensures that
42
46
43
47
Here is an example:
44
48
49
+
:::interactive_editor
50
+
45
51
```html
46
52
<head>
47
53
<style>
@@ -59,6 +65,8 @@ Here is an example:
59
65
</body>
60
66
```
61
67
68
+
:::
69
+
62
70
The above example demonstrates how `min-width` and `min-height` work.
63
71
64
72
Even though the box has its `width` and `height` set to 50px, it will actually be `100px` by `100px`. This is because the `min-width` and `min-height` are set to `100px`, which are larger than the specified `width` and `height`.
@@ -71,6 +79,8 @@ The `max-height` specifies the maximum height an element can grow to, regardless
71
79
72
80
Here is an example:
73
81
82
+
:::interactive_editor
83
+
74
84
```html
75
85
<head>
76
86
<style>
@@ -88,6 +98,8 @@ Here is an example:
88
98
</body>
89
99
```
90
100
101
+
:::
102
+
91
103
The above example demonstrates how `max-width` and `max-height` override `width` and `height`. Even though the box is set to `200px` by `200px`, it will actually be `150px` by `150px`. This is because the `max-width` and `max-height` are set to `150px`, which is smaller.
92
104
93
105
Remember, when `max-width` or `max-height` are smaller than `width` or `height`, they take precedence. This is important for controlling the maximum size of elements in your layouts.
0 commit comments