Module_3
Module_3
Unit 3
Cascading Style Sheets (CSS-3): CSS Overview - CSS Rules, CSS
Syntax and Style - Class Selectors, ID Selectors, span and div
Elements - Cascading, style Attribute, style Container, External
CSS Files –
CSS Properties: Color Properties, Font Properties, line-height
Property, Text Properties, Border Properties. Element Box, padding
Property, margin Property - Hosting a Website and GIT.
What is CSS?
Example
<h1 style="color:blue;">A Blue Heading</h1>
h1 {
color: maroon;
margin-left: 40px;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
•p {
color: red;
text-align: center;
}
Example Explained
• p is a selector in CSS (it points to the HTML element you
want to style: <p>).
• color is a property, and red is the property value
• text-align is a property, and center is the property value
Internal CSS Format
Inline CSS
<!DOCTYPE html>
<html>
<body>
<h1 style="color:blue;text-align:center;">This
is a heading</h1>
<p style="color:red;">This is a paragraph.</p>
</body>
</html>
External CSS
• <!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>
Cascading Order
• What style will be used when there is more than one style
specified for an HTML element?
• All the styles in a page will "cascade" into a new "virtual"
style sheet by the following rules, where number one has
the highest priority:
1. Inline style (inside an HTML element)
2. External and internal style sheets (in the head section)
3. Browser default
• So, an inline style has the highest priority, and will
override external and internal styles and browser defaults.
CSS Comments
<!DOCTYPE html>
<html>
<head>
<style>
.center-text {
text-align: center;
color: red;
}
</style>
</head>
<body>
</body>
</html>
Color Properties
• body {
color: red;
}
h1 {
color: #00ff00;
}
p.ex {
color: rgb(0,0,255);
}
• Try it Yourself »
CSS font Property
p.a {
font: 15px Arial, sans-serif;
}
p.b {
font: italic small-caps bold 12px/30px
Georgia, serif;
}
<!DOCTYPE html>
<html>
<head>
<style>
p.a {
font: 15px Arial, sans-serif;
}
p.b {
font: italic small-caps bold 12px/30px Georgia, serif;
}
</style>
</head>
<body>
<h1>The font Property</h1>
<p class="a">This is a paragraph. The font size is set to 15 pixels, and the font family is
Arial.</p>
<p class="b">This is a paragraph. The font is set to italic and bold, with small-caps (all
lowercase letters are converted to uppercase). The font size is set to 12 pixels, the line
height is set to 30 pixels, and the font family is Georgia.</p>
</body>
Font Variant
<!DOCTYPE html>
<html>
<body>
<h1>The font Property</h1>
<p style="font:caption">The font used in captioned controls.</p>
<p style="font:icon">The font used in icon labels.</p>
<p style="font:menu">The font used in dropdown menus.</p>
<p style="font:message-box">The font used in dialog boxes.</p>
<p style="font:small-caption">A smaller version of the caption font.</p>
<p style="font:status-bar">The font used in the status bar.</p>
<p><b>Note:</b> The result of the font keywords is browser dependant.</p>
</body>
</html>
The font-size Property
<!DOCTYPE html>
<html>
<head>
<style>
div.a {
font-size: 15px;
}
div.b {
font-size: large;
}
div.c {
font-size: 150%;
}
</style>
</head>
<body>
<h1>The font-size Property</h1>
<div class="a">This is some text.</div>
<div class="b">This is some text.</div>
<div class="c">This is some text.</div>
</body>
</html>
Line Height Property
<!DOCTYPE html> <body>
<html>
<head> <h1>The line-height Property</h1>
<style>
<h2>line-height: normal (default):</h2>
div.a {
<div class="a">This is a paragraph with a standard line-height.<br>
line-height: normal; The standard line height in most browsers is about 110% to 120%.</div>
}
<h2>line-height: 1.6 (recommended):</h2>
div.b { <div class="b">This is a paragraph with the recommended line-
line-height: 1.6; height.<br>
} The line height is here set to 1.6. This is a unitless value;<br>
meaning that the line height will be relative to the font size.</div>
div.c {
<h2>line-height: 80%:</h2>
line-height: 80%; <div class="c">This is a paragraph with a smaller line-height.<br>
} The line height is here set to 80%.</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
div {
border: 1px solid black;
background-color: lightblue;
padding-top: 50px;
padding-right: 30px;
padding-bottom: 50px;
padding-left: 80px;
}
</style>
</head>
<body>
<h2>Using individual padding properties</h2>
<div>This div element has a top padding of 50px, a
right padding of 30px, a bottom padding of 50px, and a
left padding of 80px.</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
div {
margin: 70px;
border: 1px solid #4CAF50;
}
</style>
</head>
<body>
<h2>CSS Margins</h2>
<div>This element has a margin of 70px.</div>
</body>
</html>