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/25-front-end-development/review-basic-css/671a887a7e62c75e9ab1ee4a.md
+117Lines changed: 117 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,123 @@ dashedName: review-basic-css
9
9
10
10
Review the concepts below to prepare for the upcoming quiz.
11
11
12
+
## CSS Basics
13
+
14
+
-**What is CSS?**: Cascading Style Sheets (CSS) is a markup language used to apply styles to HTML elements. CSS is used for colors, background images, layouts and more.
15
+
-**Basic Anatomy of a CSS Rule**: A CSS rule is made up of two main parts: a selector and a declaration block. A selector is a pattern used in CSS to identify and target specific HTML elements for styling. A declaration block applies a set of styles for a given selector, or selectors.
16
+
-**`meta name="viewport"` Element**: This `meta` element gives the browser instructions on how to control the page's dimensions and scaling on different devices, particularly on mobile phones and tablets.
17
+
-**Default Browser Styles**: Each HTML element will have default browser styles applied to them. This usually includes items like default margins and paddings.
18
+
19
+
## Inline, Internal, and External CSS
20
+
21
+
-**Inline CSS**: These styles are written directly within an HTML element using the `style` attribute. Most of the time you will not be using inline CSS due to separation of concerns.
22
+
-**Internal CSS**: These styles are written within the `<style>` tags inside the `<head>` section of an HTML document. This can be useful for creating short code examples, but usually you will not need be using internal CSS.
23
+
-**External CSS**: These styles are written in a separate CSS file and linked to the HTML document using the `<link>` element in the `<head>` section. For most projects, you will use an external CSS file over internal or inline CSS.
24
+
25
+
## Working With the `width` and `height` Properties
26
+
27
+
-**`width` Property**: This property specifies the width of an element. If you do not specify a width, then the default is set to `auto`. This means the element will take up the full width of its parent container.
28
+
-**`min-width` Property**: This property specifies the minimum width for an element.
29
+
-**`max-width` Property**: This property specifies the maximum width for an element.
30
+
-**`height` Property**: This property specifies the height of an element. Similarly, the height is `auto` by default, which means it will adjust to the content inside.
31
+
-**`min-height` Property**: This property specifies the minimum height for an element.
32
+
-**`max-height` Property**: This property specifies the maximum height for an element.
33
+
34
+
## Different Types of CSS Combinators
35
+
36
+
-**Descendant Combinator**: This combinator is used to target elements that are descendants of a specified parent element. The following example will target all `li` items inside `ul` elements.
37
+
38
+
```html
39
+
<ul>
40
+
<li>Example item one</li>
41
+
<li>Example item two</li>
42
+
<li>Example item three</li>
43
+
</ul>
44
+
```
45
+
46
+
```css
47
+
ulli {
48
+
background-color: yellow;
49
+
}
50
+
```
51
+
52
+
-**Child Combinator (`>`)**: This combinator is used to select elements that are direct children of a specified parent element. The following example will target all `p` elements that are direct children of the `container` class.
53
+
54
+
```html
55
+
<divclass="container">
56
+
<p>This will get styled.</p>
57
+
58
+
<div>
59
+
<p>This will not get styled.</p>
60
+
</div>
61
+
</div>
62
+
```
63
+
64
+
```css
65
+
.container>p {
66
+
background-color: black;
67
+
color: white;
68
+
}
69
+
```
70
+
71
+
-**Next-sibling Combinator (`+`)**: This combinator selects an element that immediately follows a specified sibling element. The following example will select the paragraph element that immediately follow the `h2` element.
72
+
73
+
```html
74
+
<h2>I am a sub heading</h2>
75
+
76
+
<p>This paragraph element will get a red background.</p>
77
+
```
78
+
79
+
```css
80
+
h2+p {
81
+
background-color: red;
82
+
}
83
+
```
84
+
85
+
-**Subsequent-sibling Combinator (`~`)**: This combinator selects all siblings of a specified element that come after it. The following example will style only the second paragraph element because it is the only one that is a sibling of the `ul` element and share the same parent.
86
+
87
+
```html
88
+
<divclass="container">
89
+
<p>This will not get styled.</p>
90
+
<ul>
91
+
<li>Example item one</li>
92
+
<li>Example item two</li>
93
+
<li>Example item three</li>
94
+
</ul>
95
+
<p>This will get styled.</p>
96
+
</div>
97
+
<p>This will not get styled.</p>
98
+
```
99
+
100
+
```css
101
+
ul~p {
102
+
background-color: green;
103
+
}
104
+
```
105
+
106
+
## Inline, Block, and Inline-Block Level Elements
107
+
108
+
-**Inline Level Elements**: Inline elements only take up as much width as they need and do not start on a new line. These elements flow within the content, allowing text and other inline elements to appear alongside them. Common inline elements are `span`, `anchor`, and `img` elements.
109
+
-**Block Level Elements**: Block level elements that take up the full width available to them by default, stretching across the width of their container. Some common block-level elements are `div`, `paragraph`, and `section` elements.
110
+
-**Inline-Block Level Elements**: You can set an element to `inline-block` by using the `display` property. These elements behave like inline elements but can have a `width` and `height` set like block-level elements.
111
+
112
+
## Margin and Padding
113
+
114
+
-**`margin` Property**: This property is used to apply space outside the element, between the element's border and the surrounding elements.
115
+
-**`padding` Property**: This property is used to apply space inside the element, between the content and its border.
116
+
117
+
## CSS Specificity
118
+
119
+
-**Inline CSS Specificity**: Inline CSS has the highest specificity because it is applied directly to the element. It overrides any internal or external CSS. The specificity value for inline styles is (1, 0, 0, 0).
120
+
-**Internal CSS Specificity**: Internal CSS is defined within a `<style>` element in the `<head>` section of the HTML document. It has lower specificity than inline styles but can override external styles.
121
+
-**External CSS Specificity**: External CSS is linked via a `<link>` element in the `<head>` section and is written in separate `.css` files. It has the lowest specificity but provides the best maintainability for larger projects.
122
+
-**Universal Selector (`*`)**: a special type of CSS selector that matches any element in the document. It is often used to apply a style to all elements on the page, which can be useful for resetting or normalizing styles across different browsers. The universal selector has the lowest specificity value of any selector. It contributes 0 to all parts of the specificity value (0, 0, 0, 0).
123
+
-**Type Selectors**: These selectors target elements based on their tag name. Type selectors have a relatively low specificity compared to other selectors. The specificity value for a type selector is (0, 0, 0, 1).
124
+
-**Class Selectors**: These selectors are defined by a period (`.`) followed by the class name. The specificity value for a class selector is (0, 0, 1, 0). This means that class selectors can override type selectors, but they can be overridden by ID selectors and inline styles.
125
+
-**ID Selectors**: ID selectors are defined by a hash symbol (#) followed by the ID name. ID selectors have a very high specificity, higher than type selectors and class selectors, but lower than inline styles. The specificity value for an ID selector is (0, 1, 0, 0).
126
+
-**`!important` keyword**: used to give a style rule the highest priority, allowing it to override any other declarations for a property. When used, it forces the browser to apply the specified style, regardless of the specificity of other selectors. You should be cautious when using `!important` because it can make your CSS harder to maintain and debug.
127
+
-**Cascade Algorithm**: An algorithm used to decide which CSS rules to apply when there are multiple styles targeting the same element. It ensures that the most appropriate styles are used, based on a set of well-defined rules.
128
+
-**CSS Inheritance**: The process by which styles are passed down from parent elements to their children. Inheritance allows you to define styles at a higher level in the document tree and have them apply to multiple elements without explicitly specifying them for each element.
0 commit comments