CSS
CSS
makeup
not a programming language, but a stying language
But for styling there should be some content, and that's why
we studied html before css
Selector
h1 {
}
Property Value
<style> tag
<style>
h1 {
color : red;
}
</style> Writing style directly inline on each element
Style is added using the <style> element in the same document
Including Style
External Stylesheet
Writing CSS in a separate document and linking it in your main html file.
best way
color: red;
color: pink;
color: blue;
color: green;
Background Color Property
Used to set the color of background
background-color: red;
C
background-color: pink;
background-color: blue;
background-color: green;
Color Systems
RGB
color: rgb(255, 0, 0);
color: #00ff00;
* {}
.myClass { }
Element Selector
h1 { }
Id Selector
#myId { }
Practice Set 1
Q1: Create a simple div with an id "box".
Add some text content inside the div.
Set its background color to blue.
in css3, latest css -> start and end are introduced for language
support like arabic
Text Properties
text-decoration
font-weight : 100-900
arial, roboto
font-family : arial
pixels (px)
96px = 1 inch
font-size: 2px;
line-height : 2px
line-height : 3
line-height : normal
Text Properties
text-transform
Margin
Height
content
Height
Padding
Width Border
Border
Padding
Margin
Height
Height
content
By default, it sets the content area height of the element
div {
height: 50px;
}
Width
Width
content
By default, it sets the content area width of the element
div {
width: 50px;
}
Border
content
Used to set an element's border
Border
border-width : 2px;
border-style : solid / dotted / dashed
border-color : black;
Border
Shorthand
padding-left
Padding
padding-right
padding-top
padding-bottom
Padding
Shorthand
padding: 50px;
padding: 1px 2px 3px 4px;
C
3
top |right |bottom |left -> clockwise
Margin Margin
content content
margin-right
margin-left
margin-top
margin-bottom
Margin
Shorthand
margin: 50px;
margin: 1px 2px 3px 4px;
display: inline- The inline element takes the required width only. It doesn't
force the line break so the flow of text doesn't break in inline example.
none - The "none" value totally removes the element from the page. It
will not take any space.
visibility: hidden;
Note : When visibility is set to none, space for the element is reserved.
But for display set to none, no space is reserved or blocked for the
element.
Practice Set 4
Q1: Create a webpage layout with a header, a footer & a content area containing 3 divs.
Set the height & width of divs to 100px.
(add the previous navbar in the header)
Q3: Add a different background color to each div with an opacity of 0.5
em
rem
width : 33% ;
margin-left : 50% ;
for padding & margin it's relative to same element's font size
for padding & margin it's relative to same element's font size
Absolute/ fixed
Position
https://developer.mozilla.org/en-US/docs/Web/CSS/position
z-index
It decides the stack level of elements
Overlapping elements with a larger z-index cover those with a smaller one.
z-index : 1 / 2 / ...
z-index : -1 / -2 / ...
show 3d space
Background Image
Used to set an image as background
background-image: url(“image.jpeg”);
Background Size
Use the appropriate position property for the div element to place it at the
right end of the page. (The div should not move even on scroll)
COL
flex item
cross axis
flex-direction : row-reverse;
flex-direction : column;
flex-direction : column-reverse;
Flex Properties
for Flex Item
flex-grow : how much a flex item will grow relative to the rest of the flex items if
space is available
flex-shrink : how much a flex item will shrink relative to the rest of the flex items if
space is available
the color of a div changes to green for viewport width less than 300px
the color of a div changes to pink for width between 300px & 400px
the color of a div changes to red for width between 400px & 600px
rotate
transform: rotate(45deg);
transform: scale(2);
transform: scale(0.5);
transform: scale(1, 2);
transform: scaleX(0.5);
transform: scaleY(0.5);
transform: translate(20px);
C
transform: translate(20px, 50px);
transform: translateX(20px);
transform: translateY(20px);
@keyframe myName {
to { font-size : 40px; }
from { font-size : 20px;
}
}
Animation Properties
animation-name
animation-duration
animation-timing-function
animation-delay
animation-iteration-count
animation-direction
% in Animation
@keyframe myName {
0% { font-size : 20px; }
50% { font-size : 30px; }
100% { font-size : 40px; }
}