Professional Documents
Culture Documents
Style Sheet
(CSS)
What is CSS?
● Easy Maintenance –
To change the style of an element that appears
across the whole site, we have to make change at
one place only.
● Faster Download –
Using CSS, HTML code will be less which in turn
result in faster download.
Advantages of CSS
● Accessibility–
Separating style from content makes life very
easy for visitors who prefer to view only the
content of a web page, or to modify the content.
● Consistency–
Layout and position of navigation can be
completely consistent across a website using
CSS.
CSS Syntax
<html>
<head>
<style>
h1 {color:blue; text-align:center;}
h2 {color:blue; text-align:center;}
p {color:blue; text-align:center;}
</style>
</head>
Grouping Selectors
<head>
<style>
h1, h2, p{
color: blue; text-align: center;}
</style>
</head>
CSS Comments
<html>
<head>
<style>
body{
background-image: url(“Image”);
background-repeat: no-repeat;
background-size: 150px 100px;
}
</style>
</head>
Background-attachment
<head>
<style>
body{
background-image: url(“Image”);
background-repeat: no-repeat;
background-attachment : fixed;
}
</style>
</head>
Example
<body>
<p> Fixed background image</p>
<p> Scroll Down to check </p>
<p> Fixed background image</p>
<p> Scroll Down to check </p>
<p> Fixed background image</p>
<p> Scroll Down to check </p>
</body>
CSS Text
<html>
<head>
<style>
h1 { text-transform: uppercase;}
h2{ text-transform: capitalize;}
p{ text-transform: lowercase;}
</style>
</head>
Example
<body>
<h1>Heading in uppercase</h1>
<h2>Heading with first letter in each word in
uppercase</h2>
<p>Paragraph in lowercase</p>
</body>
</html>
Text Spacing
● e.g., p {
text-shadow: 3px 3px 4px red;
}
or
● e.g., p {
text-shadow: 2px 2px blue;
}
Text Direction
● e.g., p
{ font-family: “Times New Roman”;
}
Font Style
● e.g., p
{ font-style: italic;
}
Font Size
● e.g., .p1 {
font-variant: normal;
}
.p2 {
font-variant: small-caps;
}
CSS Margin
margin-top -
specifies the top margin of an element
margin-right –
specifies the right margin of an element
margin-bottom -
specifies the bottom margin of an element
margin-left -
specifies the left margin of an element
Margin – shorthand property
Value Description
p{
margin-top: 80px;
margin-bottom: 80 px;
margin-right: 120px;
margin-left: 40px;
}
Example with shorthand
property
p{
margin: 80px 120px 80px 40px;
}
- top margin is 80px
- right margin is 120 px
- bottom margin is 80px
- left margin is 40px
Examples with shorthand property
p{
border-top-style: dotted;
border-right-style: solid;
border-bottom-style: dotted;
border-left-style: solid;
}
or
p{
border-style: solid;
}
border-width Property
height: 150px; }
Example for rounded corners
</style>
</head>
<body>
<p id=“corner”>
Paragraph having border with rounded
corners
</p>
</body>
</html>
Ways to insert CSS
<html>
<head>
<style>
a:link { color: orange;}
a:visited { color: red;}
a:hover { color: green;}
a:active { color: blue;}
</style>
</head>
Background for CSS Links
• Background color for links can be specified
using background-color property.
<style>
a:link { color: orange; background-color:
blue;}
a:visited { color: red; background-color:
orange;}
a:hover { color: green; background-color:
red;}
a:active { color: blue; background-color:
green;}
</style>
Link Button
● list-style-position
specifies the position of the list-item
markers
generally used for a long point to
specify whether bullet point should
be displayed outside the list item or
inside the list item
CSS Properties for Lists
● list-style-image
specifies an image for the marker rather
than a bullet point or a number.
● list-style
serves as shorthand for the style-type,
style-position and style-image property
Values for list-style-type(UL)
● disc (default)
A filled-in circle
● circle
An empty circle
● square
A filled-in square
Values for list-style-type(OL)
● upper-roman
● lower-roman
● upper-alpha
● lower-alpha
● decimal
● decimal-leading-zero
Example
<style>
ul.a {list-style-type: circle;}
ul.b {list-style-type: square;}
ol.c {list-style-type: upper-roman;}
ol.d {list-style-type: lower-alpha;}
</style>
Example
<body>
<ul class=‘a’> <li>…..</li> </ul>
<ul class=‘b’> <li>…..</li> </ul>
<ol class=‘c’> <li>…..</li> </ol>
<ol class=‘d’> <li>…..</li> </ol>
</body>
Values for list-style-position
● inside
text on the second line will appear
indented to where the text should have
started
● outside
text will be aligned with the start of the
first line to the right of the bullet
Example
<style>
ul.a {list-style-position: outside;}
ul.b {list-style-position: inside;}
</style>
<body>
<ul class=‘a’> <li>…..</li> </ul>
<ul class=‘b’> <li>…..</li> </ul>
</body>
Values for list-style-image
● url(image URL)
image URL will be the path of the image file
Example
<style>
ul {list-style-image: url(“image”);}
</style>
<body>
<ul >
<li>…..</li> </ul>
</ul>
</body>
list-style
● The property list-style is a shorthand
property.
<html>
<head>
<style>
ul#menu li { display: inline}
ul#menu li a { background-color: black;
color: white;
padding: 10px 20px;
text-decoration: none;
}
ul#menu li a:hover { background-color:
green} </style>
</head>
Horizontal Lists
<html>
<body>
<ul id="menu">
<li><a href="HTML.html">HTML</a></
li>
<li><a href="CSS.html">CSS</a></li>
<li><a href="JAVA.html">JavaScript</
a></li>
<li><a href="PHP.html">PHP</a></li>
</ul>
</body>
</html>
CSS Tables