Ascading Tyle Heet: 05/28/2024 Cascading Style Sheet
Ascading Tyle Heet: 05/28/2024 Cascading Style Sheet
Ascading Tyle Heet: 05/28/2024 Cascading Style Sheet
CSS is used to define styles for your web pages, including the
design, layout and variations in display for different devices and
screen sizes.
HTML was NEVER intended to contain tags for formatting a web page!
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
A CSS comment starts with /* and ends with */. Comments can also span
multiple lines:
p{
color: red;
/* This is a single-line comment */
text-align: center;
}
/* This is
a multi-line
comment */
05/28/2024 Cascading Style Sheet
CSS Syntax and Selectors
The selector points to the HTML element you want to
style.
Inline style
To use inline styles, add the style attribute to the relevant element. The
style attribute can contain any CSS property.
<h1 style="color:blue;margin-left:30px;">
This is a heading.
</h1>
05/28/2024 Cascading Style Sheet
CSS Introduction
Internal Style Sheet
An internal style sheet may be used if one single page has a unique style.
Internal styles are defined within the <style> element, inside the <head> section
of an HTML page:
<head>
<style>
body
{
background-color: linen;
}
h1 {
color: maroon;
margin-left: 40px;
}
05/28/2024 </style> Cascading Style Sheet
</head>
CSS Introduction
External Style Sheet
With an external style sheet, you can change the look of an entire website by
changing just one file!
Each page must include a reference to the external style sheet file inside the <link>
element. The <link> element goes inside the <head> section:
Generally speaking we can say that all the styles will "cascade" into a new "virtual"
style sheet by the following rules, where number one has the highest priority:
3. Browser default
So, an inline style (inside a specific HTML element) has the highest priority, which
means that it will override a style defined inside the <head> tag, or in an external
style sheet, or a browser default value.
Type of Selectors
The ID Selector
You can select all <p> elements on a page like this (in this case, all <p>
elements will be center-aligned, with a red text color):
P{
text-align: center;
color: red;
}
To select an element with a specific id, write a hash (#) character, followed by
the id of the element.
The style rule below will be applied to the HTML element with id="para1":
#para1 {
text-align: center;
color: red;
05/28/2024
} Cascading Style Sheet
CSS Introduction
CSS Selectors
To select elements with a specific class, write a period (.) character, followed by
the name of the class.
In the example below, all HTML elements with class="center" will be red and
center-aligned:
.center {
text-align: center;
color: red;
}
05/28/2024 Cascading Style Sheet
CSS Introduction
The class Selector
You can also specify that only specific HTML elements should be affected
by a class.
h1, h2, p
{
text-align: center;
color: red;
}
05/28/2024 Cascading Style Sheet
CSS Background
Background Color Background Image
body { body {
background-image: url("img_tree.png");
background- background-repeat: no-repeat;
color: lightblue; background-position: right top;
background-attachment: fixed;
} }
With CSS, a color is most often body {
specified by: background: #ffffff
a valid color name - like "red" url("img_tree.png") no-repeat
a HEX value - like "#ff0000" right top;
an RGB value - like "rgb(255,0,0)" }
CSS Box Modal
The CSS Box Model
In CSS, the term "box model" is used when talking about design
and layout.
The CSS box model is essentially a box that wraps around every
HTML element.
It consists of:
margins,
outline
borders,
padding, and
the actual content.
CSS Box Modal
CSS Box Modal
Content - The content of the
box, where text and images div {
appear width: 300px;
Padding - Clears an area border: 15px solid green;
around the content. The padding: 50px;
padding is transparent margin: 20px;
Border - A border that goes }
around the padding and
content
Margin - Clears an area
outside the border. The
margin is transparent
CSS Box Modal
div {
width: 320px;
padding: 10px;
border: 5px solid gray;
margin: 0;
}
320px (width)
+ 20px (left + right padding)
+ 10px (left + right border)
+ 0px (left + right margin)
= 350px
CSS Padding
Padding is used to create space around an element's
content, inside of any defined borders. With CSS, you
have full control over the padding. There are
properties for setting the padding for each side of an
element (top, right, bottom, and left).
length - specifies a padding in px,
pt, cm, etc.
Padding - Individual Sides % - specifies a padding in % of the
•padding-top width of the containing element
•padding-right inherit - specifies that the padding
•padding-bottom should be inherited from the
•padding-left parent element
CSS Padding
div {
padding-top: 50px;
padding-right: 30px;
padding-bottom: 50px;
padding-left: 80px;
}
CSS Border
The CSS border properties allow you to specify the style, width, and
color of an element's border
p{ p{
border-left: 6px solid red; border: 2px solid red;
background-color: lightgrey; border-radius: 5px;
} }
p{ p{
border-bottom: 6px solid red; border-style: solid;
background-color: lightgrey; border-left-width: 15px;
} }
CSS Border
p.one {
border-style: solid;
border-color: #0000ff;
}
p.two {
border-style: solid;
border-color: #ff0000 #0000ff;
}
p.three {
border-style: solid;
border-color: #ff0000 #00ff00 #0000ff;
}
p.four {
border-style: solid;
border-color: #ff0000 #00ff00 #0000ff
rgb(250,0,255);
}
CSS Outline
An outline is a line drawn outside the element's border.
CSS Outline
CSS has the following outline properties:
•outline-style
•outline-color
•outline-width
•outline-offset
•outline
CSS Outline
Outline Style
The margin properties set the size of the white space outside
the border.
With CSS, you have full control over the margins. There are
CSS properties for setting the margin for each side of an element
(top, right, bottom, and left).
CSS has properties for specifying the margin for each side of an
element:
•margin-top
•margin-right
•margin-bottom
•margin-left
CSS Margin
All the margin properties can have the following values:
auto - the browser calculates the margin
p{ p{
margin-top: 100px; margin: 100px 150px 100px 80px;
margin-bottom: 100px; }
margin-right: 150px; div {
margin-left: 80px; width: 300px;
} margin: auto;
border: 1px solid red;
CSS LINK
Styling Links
Links can be styled with any CSS property (e.g. color, font-
family, background, etc.).
/* selected link */
a:active {
color: blue;
}
CSS LINK
Text Decoration The property is mostly used to remove
underlines from links:
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:active {
text-decoration: underline;
}
CSS LINK
Background property can be used to specify a background
color for links:
a:link {
background-color: yellow;
}
a:visited {
background-color: cyan;
}
a:hover {
background-color: lightgreen;
}
a:active {
background-color: hotpink;
}
CSS LINK
Advanced Link Button a:link, a:visited {
background-color: white;
a:link, a:visited { color: black;
background-color: #f44336; border: 2px solid green;
color: white; padding: 10px 20px;
padding: 14px 25px; text-align: center;
text-align: center; text-decoration: none;
text-decoration: none; display: inline-block;
display: inline-block; }
}
a:hover, a:active {
a:hover, a:active { background-color: green;
background-color: red; color: white;
} }
CSS Table
The look of an HTML table can be greatly improved
with CSS
} } }
CSS Table
The look of an HTML table can be greatly improved
with CSS
table, th, td
{
border: 1px solid black;
}
CSS Table
The look of an HTML table can be greatly improved
with CSS
Table
{
width:100%;
height:50px;
border-collapse: collapse;
}
CSS Table
The look of an HTML table can be greatly improved
with CSS
th,td
{
text-align:center;
vertical-align:center;
padding:15px;
border-bottom: 1px solid #ddd;
}
CSS Table
The look of an HTML table can be greatly improved
with CSS
tr:hover
{
background-color:#f5f5f5;
}
CSS Table
Stripped Table
tr:nth-child(even)
{
background-color: #f2f2f2;
}
CSS Table
Table Color
th
{
background-color: #f2f2f2;
color:white;
}
CSS Table
Responsive Table
<table>
... table content ...
</table>
text-align: center;
text-align:justify; CSS Text
text-decoration:none;
text-decoration:overline;
text-decoration:underline;
text-decoration:line-through;
text-transform:smallcase;
text-transform:uppercase;
text-transform:capitalize;
text-indent:50px
text-shadow: 3px 2px red;
CSS Text
letter-spacing:3px;
letter-spacing:-3px;
line-height:1.8;
direction:rtl;
word-spacing:5px;
word-spacing:-5px
CSS Font
font-family: “time new roman”, times, serif;
font-style : normal / italic /oblique;
font-size: 40px;
font-size: 2em;
font-size: 10vw;
}
ol {
background: #ff9999;
padding: 20px;
CSS List
}
ul {
background: #3399ff; padding: 20px;
}
ol li {
background: #ffe5e5; padding: 5px; margin-left: 35px;
}
ul li {
background: #cce5ff; margin: 5px;
}
THANKS