CSS Practicals
CSS Practicals
Inline implementation
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Embedded/Internal Implementation
<html>
<head>
<style>
p{
text-align: center;
color: red;
}
</style>
</head>
<body>
<p>Every paragraph will be affected by the style.</p>
<p >Me too!</p>
<p>And me!</p>
</body>
</html>
External Style sheet
<html>
<head>
<title>My Example</title>
<link rel="stylesheet" href="style2.css">
</head>
<body>
<h1>External Styles</h1>
<h2>Allow you to define styles for the whole
website.</h2>
<p >This has a style applied via a class.</p>
</body>
</html>
style2.css
body {
background-color: darkslategrey;
color: azure;
font-size: 1.1em;
}
h1 {
color: coral;
}
h2 {
font-size: 1.3em;
}
p{
color: orange;
}
The id selector
<!DOCTYPE html>
<html>
<head>
<style>
#t {
text-align: center;
color: red;
}
</style>
</head>
<body>
<p id=“t">Hello World!</p>
<p >This paragraph is not affected by the style.</p>
</body>
</html>
Class selector
<!DOCTYPE html>
<html>
<head>
<style>
.center {
text-align: center;
color: red;
}
</style>
</head>
<body>
<h1 class="center">Red and center-aligned heading</h1>
<p class="center">Red and center-aligned paragraph.</p>
</body>
</html>
Class selector
<!DOCTYPE html>
<html>
<head>
<style>
p.center {
text-align: center;
color: red;
}
</style>
</head>
<body>
</body>
</html>
Grouping Selectors
<!DOCTYPE html>
<html>
<head>
<style>
h1, h2, p {
text-align: center;
color: red;
}
</style>
</head>
<body>
<h1>Hello World!</h1>
<h2>Smaller heading!</h2>
<p>This is a paragraph.</p>
</body>
</html>
Background Colour
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: #b0c4de;
}
</style>
</head>
<body>
</body>
</html>
Background Colour of different Elements
div { </body>
background-color: #b0c4de; </html>
}
Background Image
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image: url("paper.gif");
}
</style>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
Position Background Image
p.main { </body>
text-align: justify; </html>
}
Decorate Text
h2 { </body>
text-decoration: line-through; </html>
}
h3 {
text-decoration: underline;
}
Text font
<!DOCTYPE html>
<html>
<head>
<style>
ul {
list-style: square inside url(“place url");
}
</style>
</head>
<body>
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
</body>
</html>