CSS Tutorial1 and 2
CSS Tutorial1 and 2
CSS Syntax
Each declaration includes a CSS property name and a value, separated by a colon.
Example:
p{
color: red;
text-align: center;
CSS Comments
p{
color: red;
text-align: center;
}
External Style Sheet
theme.css page1.html
body {
<!DOCTYPE html>
background-color: lightblue;
<html>
}
<head>
<link rel="stylesheet" href="theme.css">
h1 {
</head>
color: white;
<body>
text-align: center;
}
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
p{
font-family: verdana;
</body>
font-size: 20px;
</html>
}
home.html
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: lightblue;
}
h1 {
color: white;
text-align: center;
}
p{
font-family: verdana;
font-size: 20px;
}
</style>
</head>
<body>
</body>
</html>
a) Universal Selector
The universal selector (*) selects all HTML elements on the page. Therefore the CSS rule will affect
every HTML element on the page.
*{
text-align: center;
color: blue;
b) Element Selector
The element selector selects all elements with the specified element name.
p{
color: blue;
c) Class Selector
The class selector selects HTML elements with a specific class attribute.
To select elements with a specific class, write a period (.) character, followed by the class name.
d) ID Selector
The id selector uses the id attribute of an HTML element to select a specific element.
The id of an element is unique within a page, so the id selector is used to select one unique element!
To select an element with a specific id, write a hash (#) character, followed by the id of the element.
#para1 {
color: red;
}
e) Attribute Selectors
The attribute selector is used to select elements based on the presence or value of html attributes.
-------------
a[target=_blank] {
<a href="http://www.disney.com" target="_blank">disney.com</a>
background-color: yellow;
f) Pseudo-classes Selector
The pseudo-class selector is used to select a special state of an element. For example, it can be used
to style an element when a user moves the mouse over it.
a:hover {
color: #FF00FF;
g) Pseudo-elements Selector
The pseudo-element selector is used to select specified parts of an element. For example, it can be
used to style the first letter (or line) of an element.
p::first-line {
color: #ff0000;
font-variant: small-caps;
h) Multiple Selectors
Multiple selector is sued to select all the HTML elements with the same style definitions.
text-align: center;
color: red;
}
Style Elements
h3 {
color: blue;
text-align: center;
text-decoration: underline;
}
p{
font-family: "Times New Roman", Times, serif;
font-style: italic;
font-size: 40px;
font-weight: bold;
}
c) Links |link, visited, hover, active, color, text -decoration, background –color
<ul class="b">
ul.b {
<li>Coffee ..........</li>
list-style-position: inside;
<li>Tea ………….</li>
}
</ul>
table {
table, th, td { table { border-collapse: collapse;
border: 1px solid black; border-collapse: collapse; width: 400px;
} } height: 150px;
}
th { td { th, td {
text-align: center; vertical-align: bottom; padding: 15px;
} } }
img {
padding: 5px;
width: 150px;
height: 150px;
opacity: 0.5;