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: README.md
+77-99Lines changed: 77 additions & 99 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -264,76 +264,7 @@ Render tree construction follows the following order:
264
264
265
265
<br/>
266
266
267
-
## Q. What is the CSS Box Model?
268
-
269
-
Every HTML element is treated as a rectangular box by the browser. The **CSS Box Model** describes this rectangular box through four areas that wrap around the element\'s content: **content**, **padding**, **border**, and **margin**.
270
-
271
-
```
272
-
+------------------------------------------+
273
-
| Margin |
274
-
| +------------------------------------+ |
275
-
| | Border | |
276
-
| | +------------------------------+ | |
277
-
| | | Padding | | |
278
-
| | | +------------------------+ | | |
279
-
| | | | Content | | | |
280
-
| | | +------------------------+ | | |
281
-
| | +------------------------------+ | |
282
-
| +------------------------------------+ |
283
-
+------------------------------------------+
284
-
```
285
-
286
-
***Content** – The area where the actual content (text, images, etc.) is displayed.
287
-
***Padding** – Transparent space between the content and the border.
288
-
***Border** – A line that wraps around the padding and content.
289
-
***Margin** – Transparent space outside the border, separating the element from others.
290
-
291
-
<divalign="right">
292
-
<b><a href="#">↥ back to top</a></b>
293
-
</div>
294
-
295
-
## Q. What is the difference between `box-sizing: content-box` and `box-sizing: border-box`?
296
-
297
-
The `box-sizing` property controls how the total width and height of an element is calculated.
298
-
299
-
| Property | Width Calculation |
300
-
|---|---|
301
-
|`content-box` (default) |`width` = content only. Padding and border are **added** on top. |
302
-
|`border-box`|`width` = content + padding + border. They are **included** inside the declared width. |
A common best practice is to apply `border-box` globally:
352
+
353
+
```css
354
+
*, *::before, *::after {
355
+
box-sizing: border-box;
356
+
}
357
+
```
358
+
359
+
<divalign="right">
360
+
<b><a href="#">↥ back to top</a></b>
361
+
</div>
362
+
391
363
## Q. What is margin collapsing in CSS?
392
364
393
365
**Margin collapsing** occurs when the top and bottom margins of block-level elements combine into a single margin equal to the **larger** of the two values.
@@ -946,16 +918,16 @@ a:hover {
946
918
947
919
## Q. What is contextual selector?
948
920
949
-
Contextual selector addresses specific occurrence of an element. It is a string of individual selectors separated by white space (search pattern), where only the last element in the pattern is addressed providing it matches the specified contex.
950
-
951
-
It also check the context of the class in the html tree, assigning the style to the element through a specific route, taking into account the order of depth in the tree.
921
+
A **contextual selector** targets an element only when it appears within a specific context (ancestor). It\'s a string of selectors separated by whitespace, where only the last element is styled — but only if it matches the specified ancestral path.
952
922
953
923
**Example:**
954
924
955
925
```css
956
-
tablep { property: value; }
926
+
tablep { color: red; }
957
927
```
958
928
929
+
This styles `<p>` elements only when they are descendants of a `<table>` — not all `<p>` elements on the page.
930
+
959
931
<divalign="right">
960
932
<b><a href="#">↥ back to top</a></b>
961
933
</div>
@@ -1093,7 +1065,7 @@ In the CSS, a class selector is a name preceded by a full stop (".") and an ID s
1093
1065
<b><a href="#">↥ back to top</a></b>
1094
1066
</div>
1095
1067
1096
-
## Q. What is the difference between the “nth-child()” and “nth-of-type()” selectors?
1068
+
## Q. What is the difference between the "nth-child()" and "nth-of-type()" selectors?
1097
1069
1098
1070
The `nth-child()` pseudo-class is used to match an element based on a number, which represents the element\'s position amongst it\'s siblings. More specifically, the number represents the number of siblings that exist before the element in the document tree (minus 1).
1099
1071
@@ -1137,34 +1109,40 @@ This number can also be expressed as a function, or using the keywords even or o
1137
1109
1138
1110
## Q. What is specificity?
1139
1111
1140
-
A process of determining which css rule will be applied to an element. It actually determines which rules will take precedence. Inline style usually wins then ID then class value (or pseudo-class or attribute selector), universal selector (*) has no specificity. ID selectors have a higher specificity than attribute selectors.
1141
-
1142
-
**Selector Types**
1112
+
**Specificity** is the algorithm browsers use to determine which CSS rule takes precedence when multiple rules target the same element.
1143
1113
1144
-
The following list of selector types increases by specificity:
1114
+
**Specificity Hierarchy (lowest → highest)**
1145
1115
1146
-
***Type selectors** (e.g., h1) and pseudo-elements (e.g., ::before).
|`!important`|`color: red !important`| Overrides all |
1149
1124
1150
-
```css
1151
-
/*wins*/
1152
-
a#a-02 { background-image : url(n.gif); }
1153
-
a[id="a-02"] { background-image : url(n.png); }
1154
-
```
1125
+
**Key Rules**
1155
1126
1156
-
Contextual selectors are more specific than a single element selector.The embedded style sheet is closer to the element to be styled. The last rule defined overrides any previous, conflicting rules.
1127
+
-**Higher specificity wins**, regardless of order.
1128
+
- If specificity is **equal**, the **last rule** declared wins.
1129
+
- A **class** beats any number of element selectors:
1157
1130
1158
-
```css
1159
-
p { color: red; background: yellow }
1160
-
p { color: green } // wins
1161
-
```
1131
+
```css
1132
+
.intro {} /* wins */
1133
+
htmlbodydivdivp {} /* loses */
1134
+
```
1135
+
-**ID** beats any number of classes:
1136
+
```css
1137
+
#main { color: red; } /* wins */
1138
+
.box.card.active { color: blue; } /* loses */
1139
+
```
1162
1140
1163
-
A class selector beats any number of element selectors.
* Every ```<a>``` element whose href attribute value begins with “https”.
1154
+
* Every ```<a>``` element whose href attribute value begins with "https".
1177
1155
1178
1156
```css
1179
1157
a[href^="https"]
1180
1158
```
1181
1159
1182
-
* Every ```<a>``` element whose href attribute value ends with “.pdf”.
1160
+
* Every ```<a>``` element whose href attribute value ends with ".pdf".
1183
1161
1184
1162
```css
1185
1163
a[href$=".pdf"]
1186
1164
```
1187
1165
1188
-
* Every ```<a>``` element whose href attribute value contains the substring “css”.
1166
+
* Every ```<a>``` element whose href attribute value contains the substring "css".
1189
1167
1190
1168
```css
1191
1169
a[href*="css"]
@@ -6729,7 +6707,7 @@ When using `translate()`, the element still occupies its original space (sort of
6729
6707
6730
6708
**Example:**
6731
6709
6732
-
If we combine `position:relative` with one of the offset properties `top`, `bottom`, `left` or `right` the element will be moved from its original place in the layout whilst preserving the space in the document it once occupied. The element will be moved on to a new layer and its “layer order” or its stacking order can then be controlled with the `z-index` property.
6710
+
If we combine `position:relative` with one of the offset properties `top`, `bottom`, `left` or `right` the element will be moved from its original place in the layout whilst preserving the space in the document it once occupied. The element will be moved on to a new layer and its "layer order" or its stacking order can then be controlled with the `z-index` property.
0 commit comments