CSS Notes
CSS Notes
*Simple Selectors:*
1. *Type Selector:* Selects elements based on their element type.
Example: div, p, span.
2. *Class Selector:* Selects elements based on their class attribute.
Example: .classname.
3. *ID Selector:* Selects elements based on their id attribute.
Example: #idname.
4.*Universal Selector:*Selects all elements in webpage at once.
5.*Grouping Selector:* Selects multiple elements same time
separated by comma. Example: h1,p,div{//css}
*Combinator Selectors:*
1. *Descendant Selector:* Selects an element that is a descendant
of another specified element. Example: div p.
2. *Child Selector:* Selects an element that is a direct child of
another specified element. Example: ul > li.
3. *Adjacent Sibling Selector:* Selects an element that is
immediately preceded by a sibling element. Example: h2 + p.
4. *General Sibling Selector:* Selects elements that are siblings of a
specified element. Example: h2 ~ p.
*Pseudo-class Selectors:*
1. *:hover:* Selects an element when the mouse pointer is over it.
2. *:active:* Selects an element when it is being activated by the
user.
3. *:focus:* Selects an element when it is in focus.
4. *:first-child:* Selects an element that is the first child of its
parent.
5. *:last-child:* Selects an element that is the last child of its parent.
6. *:nth-child():* Selects elements based on their position within a
parent.
7. *:not():* Selects elements that do not match a specific selector.
8. *:nth-of-type():* Selects elements based on their position within
a parent, counting only elements of the same type.
9. *:checked:* Selects input elements that are checked.
*Pseudo-element Selectors:*
1. *::before:* Inserts content before the selected element.
2. *::after:* Inserts content after the selected element.
3. *::first-line:* Selects the first line of text within the selected
element.
4. *::first-letter:* Selects the first letter of text within the selected
element.
5. *::selection:* Selects the portion of an element that is selected by
a user.
*Attribute Selectors:*
1. *[attribute]:* Selects elements that have the specified attribute.
2. *[attribute=value]:* Selects elements with the specified attribute
and value.
3. *[attribute~=value]:* Selects elements with an attribute that
includes the specified value as one of its space-separated values.
4. *[attribute|=value]:* Selects elements with an attribute that
exactly matches the specified value or starts with the specified value
followed by a hyphen.
** Inline CSS:**
- Applied directly to individual HTML elements using the style
attribute.
- Highest specificity.
- Overrides external and internal styles for the targeted element.
- Example: <div style="color: red;">.
** Selector Specificity:**
- Inline styles have the highest specificity, followed by ID selectors,
class selectors, and tag name selectors.
- Specificity is calculated based on the combination of selectors used
to target an element.
- The more specific selector takes precedence over less specific
selectors.
** ID Selectors:**
- Defined using the id attribute in HTML elements.
- More specific than class and tag name selectors.
- Should be used for unique elements.
- Example: <div id="uniqueElement">.
** Class Selectors:**
- Defined using the class attribute in HTML elements.
- Less specific than ID selectors but more specific than tag name
selectors.
- Can be applied to multiple elements.
- Example: <div class="container">.
** Importance:**
- The !important declaration overrides normal specificity rules.
- Should be used sparingly as it can make styles harder to override
and maintain.
*Simple Selectors:*
1. *Type Selector:* Selects elements based on their element type.
Example: div, p, span.
2. *Class Selector:* Selects elements based on their class attribute.
Example: .classname.
3. *ID Selector:* Selects elements based on their id attribute.
Example: #idname.
4.*Universal Selector:*Selects all elements in webpage at once.
5.*Grouping Selector:* Selects multiple elements same time
separated by comma. Example: h1,p,div{//css}
*Combinator Selectors:*
1. *Descendant Selector:* Selects an element that is a descendant
of another specified element. Example: div p.
2. *Child Selector:* Selects an element that is a direct child of
another specified element. Example: ul > li.
3. *Adjacent Sibling Selector:* Selects an element that is
immediately preceded by a sibling element. Example: h2 + p.
4. *General Sibling Selector:* Selects elements that are siblings of a
specified element. Example: h2 ~ p.
*Pseudo-class Selectors:*
1. *:hover:* Selects an element when the mouse pointer is over it.
2. *:active:* Selects an element when it is being activated by the
user.
3. *:focus:* Selects an element when it is in focus.
4. *:first-child:* Selects an element that is the first child of its
parent.
5. *:last-child:* Selects an element that is the last child of its parent.
6. *:nth-child():* Selects elements based on their position within a
parent.
7. *:not():* Selects elements that do not match a specific selector.
8. *:nth-of-type():* Selects elements based on their position within
a parent, counting only elements of the same type.
9. *:checked:* Selects input elements that are checked.
*Pseudo-element Selectors:*
1. *::before:* Inserts content before the selected element.
2. *::after:* Inserts content after the selected element.
3. *::first-line:* Selects the first line of text within the selected
element.
4. *::first-letter:* Selects the first letter of text within the selected
element.
5. *::selection:* Selects the portion of an element that is selected by
a user.
*Attribute Selectors:*
1. *[attribute]:* Selects elements that have the specified attribute.
2. *[attribute=value]:* Selects elements with the specified attribute
and value.
3. *[attribute~=value]:* Selects elements with an attribute that
includes the specified value as one of its space-separated values.
4. *[attribute|=value]:* Selects elements with an attribute that
exactly matches the specified value or starts with the specified value
followed by a hyphen.
Color Property :-The color property specifies the color of the text.
1. Color Name: It will target the text color by directly specifying the
name of the color like blue, green, yellow, white, black, etc.
Syntax:
color: name-of-the-color;
Syntax:
Syntax:
font-variant: normal/small-caps;
Syntax:
body {
background-color:color-name;
}
6 ways to add color by using:- 1. Color-name
2. By Hexadecimal(#)
3. RGB(0-255,0-255,0-255)
4. HSL(0-360,0-100%,0-100%)
5. RGBA(0-255,0-255,0-255,0-
1)
6. HSLA(0-360,0-100%,0-100%,0-
1)
Directions:-
i. to bottom v. to top left
ii. to top vi. to top right
iii. to right vii. to bottom left
iv. to left viii. To bottom right
Directions:-
i. Circle at bottom v. Circle at top left
ii. Circle at top vi. Circle at top right
iii. Circle at right vii. Circle at bottom left
iv. Circle at left viii. Circle at bottom right
Image
Bottom center
Bottom-left Corner
Bottom-left Corner
Values :-
i. Top center v. top left ix) center center
ii. Bottom center vi. top right x) 20px 40px
iii. Right center vii. bottom left xi) top 50% left 50%
iv. Left center viii. bottom right
6. Background-attachment Property : The property
background-attachment property in CSS is used to specify
the kind of attachment of the background image with respect to
its container. It can be set to scroll or remain fixed.
Values:-
scroll: It sets the background image to get fixed at its
position with respect to the containing element and scroll
with the page. It is the default value.
fixed: This property is used to set the background image to
fixed at its position with respect to the viewport.
local: This property is used to set the background image to
scroll along with the content of its container element instead
of the page.
Syntax:
background-attachment: scroll| fixed| local;
Syntax :-
background-clip: border-box |padding-box |content-box |
text
Firefox -moz-
Ms Edge -ms-
Opera -o-
Syntax :-
-webkit-background-clip: text;
Syntax:
h2 {
text-transform: values;
[values:-
Uppercase,lowercase,capitalize,none]
}
Syntax:
h2 {
text-decoration: values;
[values:- Underline, overline, line-
through,none]
}
}
Word-spacing: It is used to control the space between words.
Syntax:
h2 {
}
Offset-x: This property is required & used to specify the position
of horizontal shadow. It accepts the negative values.
Offset-y: This property is required & used to specify the position
of vertical shadow. It also accepts the negative values.
blur-radius: It is used to set the blur radius. Its default value is 0
& is optional.
color: It is used to set the color of the shadow. It is optional.
h2 {
top = 40px
right = 100px
bottom = 120px
left = 80px
div {
margin: 40px 100px 120px;
top = 40px
right and left= 100px
bottom = 120px
div {
margin: 40px;
}
top, right, bottom and left = 40px
}
Top and bottom = 150px
Right and left = auto
Padding Property :- CSS paddings are used to create space
around the element, inside any defined border.
padding-top: It is used to set the width of the padding area on
the top of an element.
padding-right: It is used to set the width of the padding area on
the right of an element.
padding-bottom: It is used to set the height of the padding area
on the bottom of an element.
padding-left: It is used to set the width of the padding area on
the left of an element.
top = 40px
right and left = 100px
bottom = 120px
Shorthand :- If the padding property has 2 values
Div{
padding: 100px 150px;
}
Border :- CSS border properties allow us to set the style, color, and
width of the border.
Values :- Hidden,visible,scroll
Values:-
i. static (default)
ii. relative
iii. absolute
iv. fixed
v. sticky
1. Static:-
It is the default position value for the element. Under
static position, elements are positioned according to
the normal flow of the page.
Note: left, right, top, and bottom properties will not
affect if the position is static.
2. Relative:-
Position element w.r.t its original position.
Elemnet will remain in browser, empty space is not occupied.
Left,Right,Top,Bottom is used to shift the position of an element.
3. Absolute :-
Position Element w.r.t its nearest parent.
Element will come out of the browser flow, empty space will be
occupied by succeeding element.
Left,Right,Top,Bottom is used to shift the position of an element.
4. Fixed :-
Fixed element does not follow normal document flow and
positions themselves relative to <HTML> tag. This
element always stick to the screen.
Positioned element w.r.t Viewport (Ex:- Chat with us).
5. Sticky :-
Position an element according to user scroll
Example:- Navigation/Header in websites.
Z-index :-
The z-index property is used to displace elements on the z-axis i.e in or
out of the screen. It is used to define the order of elements if they
overlap on each other.
This Property is used to position element on z-axis.
Example :- z-index: number(1,2,3,4…);
Transition-duration : This property allows you to determine how long it will take to
complete the transition from one CSS property to the other.
Or
OR
Shorthand Property :
transition: (property name) | (duration) | (timing function) |
(delay);
Animation Name :
To animate an element we have to provide animation to the element.
Example: Animation-name : Box1 ;
By this name {Box1} @keyframe will target the element for animation.
@keyframes identifier {
From{
}
}
2. Percentage :-
@keyframes identifier { We can use percentage. By using
0%{ percentage (%) we can target any
moment in the animation
background-color : red;
}
50% {
background-color : green;
}
100%{
background-color : red;
}
}
Value :-
1. normal Forward
2. Reverse
Reverse
3. Alternate
Forward
Reverse
4. alternate-reverse
Reverse
Forward