Html is just an skeletal layout of a website. Website need to design a website, add style to itand it look beautiful.
We can add multiple classes to an elements like this:-
<div id="first" class="c1 c2 c3">
</div>
body{
color: blue;
backgroud-color:green;
}
It is used to select an element based off the tagname
h2{
color:blue;
}
It is used to an element with a given id :-
#first{
color:white;
background-color:black;
}
It is used to select an element with a given class.
.blue{
background-color:blue;
}
h1,h2,h3{
color:blue;
}
p .red{
color:red;
}
*{
margin:0;
padding:0;
}
p{
color:red;
}
similarly we can set color for different elements
The value of the color or background color is provided any of these values.
.brown{
background-color: brown;
}
Used to set an image as the background.
body{
background-color:url("image.jpg");
}
The image is by default repeated in x & y directions.
div{@#39;img.png') no-repeat fixed right-top;
}
One of the proprerties can be missing given others are in order
#box{
height:70px;
width:20px;
}
Note: that the total width/height id calculated as:-
Total height=height + top/bottom padding+top/bottom border + top/bottom margin
We can set margin and padding as follows: - Sets top,bottom,left,and right:
.box{
margin:3px;
padding:4px;
}
.boxmain{
margin:7px 0px 2px 11px;
}
.boxlast{
margin:7px 3px;
}
We can also set indiviusual margins/paddings like this:
margin-top:2px; margin-bottom:2px; margin-left:2px; margin-right:2px;
We can set the bordr as follows:
.bx{
border-width: 2px ;
border-style: solid;
border-color: blue ;
}
We can set border radius to create rounded borders
.div2{
border-radius:7px;
}
When two margins from different elements onerlap, the equivalent
margin is the greater of the two . This is called margin collpse.
.div1{
box-sizing:border-box
}
Note:This conatins width and height includes content+padding+border
The css display is used to determine whether an element is treated as a block/inline element and the layout used for its children.
Takes only the space required by the element. No linebreaks before and after. settings width/height or margin/paddings not allowed.
.div1{
text-align:center;
}
Used to decorate the text. It can be :
p .uppercase{
text-transform:uppercase;
}
used to specify the space between lines
.small{
line-height:0.7;
}
Fonts plays a very impoertant role inthe look and fed of a website
p{
font-family:"Times new Roman", monospace;
}
These fonts are universally installed arcoss browsers
There are more units for describing size other than ‘px’ There are rem, em, vw, vh, percentages, etc.
Pixels (px) are relative to the viewing device. For a device with the size 1920x1080, 1px is 1unit out of 1080/1920.
These units are relative to the other length property. Following are some of the most commonly used relative lengths,
CSS has a min-height, max-height, and min-width, max-width property. If the content is smaller than the minimum height, minimum height will be applied.
Used to manipulate the location of an element Following are the possible values: - static: The default position. top/bottom/left/right/z-index has no effec) - relative : The top/bottom/left/right/z-index will now work. Otherwise, the element is in the flow of the document like static. - absolute: The element is removed from the flow and is relatively positioned to its first non-static ancestor. top/bottom etc. works - fixed: Just like absolute except the element is positioned relative to the browser window - sticky: The element is positioned based on the user’s scroll position
The list-style property is a shorthand for type, position, and image
ul{
list-style: square inside url(‘harry.jpg’)
}
‘square’ in the above code is the list-style-type, ‘inside’ is the
list-style-position and ‘harry.jpg’ is the list-style-image. z-index
property The z-index property specifies the stack order of an element.
It defines which layer will be above which in case of overlapping
elements.

Before we look into the CSS flexbox, we will look into float and
clear properties. The float property float property is simple. It just
flows the element towards left/right

Used to clear the float. It specifies what elements can float beside a given element
Aims at providing a better way to layout, align, and distribute space among items in a container.
.container{
display: flex; /*Initialize a flexbox*/
}
Defines the direction towards which items are laid. Can be row (default), row-reverse, column and column-reverse
Following are the properties for the flex parent:
Following are the properties for the flex children:
A CSS grid can be initialized using:
.container {
display: grid;
}
All direct children automatically become grid items
Used to adjust the space between the columns of a CSS grid
Used to adjust the space between the rows of a CSS grid
Shorthand property for grid-row-gap & grid-column-gap
.container {
display: grid;
grid-gap: 40px 100px; /*40px for row and 100px for column*/
}
Note: For a single value of grid-gap, both row and column gaps can be set in one value.
.container {
display: grid;
grid-template-columns: 80px 120px auto;
}
.container {
display: grid;
grid-template-rows: 70px 150px;
}
.grid-item{
grid-column: 1/5;
}
.item{
grid-column: 1/span 3;
}
Used to apply CSS only when a certain condition is true.
Syntax:
@media only screen and (max-width: 800px) {
body{
background: red;
}
}
Transforms are used to rotate, move, skew or scale elements. They are used to create a 3-D effect.
Used to apply a 2-D or 3-D transformation to an element
Allows to change the position of transformed elements 2D transforms – can change x & y-axis 3D transforms – can change Z-axis as well
You can use the following 2-D transforms in CSS:
Used to change property values smoothly, over a given duration.
The transition property is used to add a transition in CSS. Following are the properties used for CSS transition:
Syntax:
transition: property duration timing-function delay;
transition: width 35 ease-in 25;
We can transition multiple properties as follows:
transition: opacity 15 ease-out 15, transform 25 ease-in;
Used to animate CSS properties with more control. We can use the @keyframes rule to change the animation from a given style to a new style.
@keyframes harry {
from { width: 20px; } /*Can change multiple properties*/
to { width: 31px; }
}
Following are the properties used to set animation in CSS:
All the animation properties from 1-6 can be applied like this:
animation: harry 65 linear 15 infinite reverse;
We can use % values to indicate what should happen when a certain percent of animation is completed
@keyframes harry {
0% {
width: 20px;
}
50% {
width: 80px;
}
100% {
width: 200px;
}
}