CSS
CSS
What is CSS?
CSS stands for Cascading Style Sheets
CSS describes how HTML elements are to be displayed on screen, paper, or in
other media
CSS saves a lot of work. It can control the layout of mul ple web pages all at once
External stylesheets are stored in CSS files
CSS Syntax
A CSS rule consists of a selector and a declara on block.
p{
text-align: center;
color: red;
}
#para1 {
text-align: center;
color: red;
}
The CSS class Selector
The class selector selects HTML elements with a specific class a ribute.
To select elements with a specific class, write a period (.) character, followed by
the class name.
.center {
text-align: center;
color: red;
}
External CSS
With an external style sheet, you can change the look of an entire website by
changing just one file!
Each HTML page must include a reference to the external style sheet file inside
the <link> element, inside the head section.
Example
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="mystyle.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Internal CSS
An internal style sheet may be used if one single HTML page has a unique style.
The internal style is defined inside the <style> element, inside the head sec on.
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: linen;
}
h1 {
color: maroon;
margin-le : 40px;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Inline CSS
An inline style may be used to apply a unique style for a single element.
To use inline styles, add the style a ribute to the relevant element. The style
a ribute can contain any CSS property.
Example
<!DOCTYPE html>
<html>
<body>
</body>
</html>
CSS Backgrounds
CSS background-color
The background-color property specifies the background color of an element.
CSS Borders
The CSS border proper es allow you to specify the style, width, and color of an
element's border.
CSS Border Style
The border-style property specifies what kind of border to display.
The following values are allowed:
do ed - Defines a do ed border
dashed - Defines a dashed border
solid - Defines a solid border
double - Defines a double border
groove - Defines a 3D grooved border. The effect depends on the border-
color value
ridge - Defines a 3D ridged border. The effect depends on the border-
color value
inset - Defines a 3D inset border. The effect depends on the border-color
value
outset - Defines a 3D outset border. The effect depends on the border-
color value
none - Defines no border
hidden - Defines a hidden border
Example
p.do ed {border-style: do ed;}
p.dashed {border-style: dashed;}
p.solid {border-style: solid;}
p.double {border-style: double;}
p.groove {border-style: groove;}
p.ridge {border-style: ridge;}
p.inset {border-style: inset;}
p.outset {border-style: outset;}
p.none {border-style: none;}
p.hidden {border-style: hidden;}
p.mix {border-style: do ed dashed solid double;}
p.two {
border-style: solid;
border-width: medium;
}
p.three {
border-style: do ed;
border-width: 2px;
}
p.four {
border-style: do ed;
border-width: thick;
}
CSS Margins
CSS Margins
The CSS margin proper es are used to create space around elements, outside of
any defined borders.
With CSS, you have full control over the margins. There are proper es for se ng
the margin for each side of an element (top, right, bo om, and le ).
Margin - Individual Sides
CSS has proper es for specifying the margin for each side of an element:
margin-top
margin-right
margin-bo om
margin-le
All the margin proper es can have the following values:
auto - the browser calculates the margin
length - specifies a margin in px, pt, cm, etc.
% - specifies a margin in % of the width of the containing element
inherit - specifies that the margin should be inherited from the parent
element
CSS Padding
Padding is used to create space around an element's content, inside of any
defined borders.
The CSS padding proper es are used to generate space around an element's
content, inside of any defined borders.
With CSS, you have full control over the padding. There are proper es for se ng
the padding for each side of an element (top, right, bo om, and le ).
The CSS height and width properties are used to set the height and width
of an element.
The CSS max-width property is used to set the maximum width of an
element.
Styling Links
Links can be styled with any CSS property (e.g. color, font-family, background,
etc.).
a:link - a normal, unvisited link
a:visited - a link the user has visited
a:hover - a link when the user mouses over it
a:active - a link the moment it is clicked
CSS Lists
CSS Flexbox
Flexbox is short for the Flexible Box Layout module.
Flexbox is a layout method for arranging items in rows or columns.
Flexbox makes it easier to design a flexible responsive layout structure,
without using float or positioning.
The CSS properties we use for the flex container are:
flex-direction
flex-wrap
flex-flow
justify-content
align-items
align-content
.flex-container {
display: flex;
flex-direction: column;
}
CSS Grid
CSS Grid Layout Module