2. CASCADING STYLE SHEETS
• Used for adding formatting to web documents.
• Provides number of attributes to create dynamic effects
in web page.
• Using style sheets text and image formatting properties
can be predefined in a single list.
• It allows to make global changes to all documents from
a single location.
• Style sheets are said to cascade when they combine to
specify the appearance of a page.
3. DEFINING A STYLE
• To define a style we use
<Style Type=“text/css”>
tag
{
attribute: value;
attribute: value
}
</Style>
4. There are three ways of inserting a style sheet:
1. External style sheet
2. Internal style sheet
3. Inline style
• 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:
External style sheet
6. <html>
<head>
<title>using external style sheet</title>
<link rel="stylesheet" href="71_css_xtstylesheet.css" type="text/css">
</head>
<body>
<h1>heading section in the stylesheet called</h1>
<p>paragraph has been changed in style sheet</p>
</body>
</html>
body
{
font:10pt;
font-family:Serif;
color:blue;
background:pink
}
h1
{
font:24pt;
color:red
}
p
{
margin-left:50px;
margin-right:50px;
}
71_css_xtstylesheet.css
7. 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:
<html>
<head>
<style>
body
{
background-color: linen;
}
h1
{
color: maroon;
margin-left: 60px;
}
</style>
</head>
<body>
<h1> Hi </h1>
</body>
</html>
8. Inline Styles
• An inline style may be used to apply a unique style for a single element.
• An inline style loses many of the advantages of a style sheet (by mixing content
with presentation). Use this method sparingly!
• To use inline styles, add the style attribute to the relevant tag. The style attribute
can contain any CSS property.
• The example shows how to change the color and the left margin of a <h1>
element:
<h1 style="color:blue;margin-left:30px;">This is a heading.</h1>
9. <html>
<head>
<title>using inline styles in html pages</title>
<style>
h2
{
font-size: 40pt;
font-family: "arial";
color:red;
}
</style>
</head>
<body style="background-color:yellow">
<h1 style="font-size: 25pt;font-family: arial;
color: blue">inline use of style over h1 tag in blue colour</h1>
<h1 style="font-size: 40pt;font-family: arial;
color: green">inline use of style over h1 tag in green colour</h1>
<h2>using internal style</h2>
<p>with out style
</body>
</html>
10. FONT ATTRIBUTES
• Font-family = specifies font family name like
sans, serif, times new roman etc.
• Font-style = normal, italic or oblique
• Font-weight = normal, bold, bolder, lighter or
100,200,300 …. 900
• Font-size = in pt
11. COLOR AND BACKGROUND ATTRIBUTES
• Color = sets elements text color.
A color name and color code
• Background-color = color in elements background.
A color name or color code.
• Background-image = sets the background image.
A url or none
• Background-repeat = repeat-x, repeat-y, repeat, no-repeat
• Background-attachment: property sets whether a
background image is fixed or scrolls with the contents of
the page.
12. • Background-Position:
The background-position property sets the starting
position of a background image.
(left top, left center, left bottom, right top, right
center, right bottom, center top, center, center
bottom).
• Background-size:
Specifies the size of the background images
(100%,100%) Stretch the background image to
completely cover the content area,(25%) Stretch the
background image so that exactly four copies fit
horizontally, (50px,50px) specifies the size of
background image
13. TEXT ATTRIBUTES
• Text-decoration = adds decoration to an element like
none, underline, overline, line-through, blink
• Vertical- align= baseline, sub, super, top, text-top,
middle, bottom, text-bottom
• Text-transform = applies transformation to the text.
Capitalize, uppercase, lowercase
• Text-align = left, right, center or justify aligns text within
an element.
• Word-spacing: property specifies the amount of space
between words. Eg: BODY {word-spacing: 10pt}
• letter-spacing: property specifies the amount of space
between letters. Eg: .wide {letter-spacing: 10cm}
14. BORDER ATTRIBUTES
• Border-style = solid, double, groove, ridge, inset, outset
• Border-color = color name or color code
• border-width = thin, medium, thick or length
• Border-top-width = thin, medium, thick or length
• Border-bottom-width = thin, medium, thick or length
• Border-left-width = thin, medium, thick or length
• Border-right-width = thin, medium, thick or length
• Border-top = specifies width, color and style
• Border-bottom = specifies width, color and style
• Border-left= specifies width, color and style
• Border-right=specifies width, color and style
• Border = sets all the properties at once
15. MARGIN ATTRIBUTES
• Margin-top = percent, length or auto
• Margin-bottom = percent, length or auto
• Margin-left = percent, length or auto
• Margin-right = percent, length or auto
• Margin = percent, length or auto
17. CLASSES and ID’S
• Can be used some times in place of inline style.
• Allows to use two different style sheets for the same
tag/attribute without using inline styles.
• ID’s are used as selectors for the style rules, making it possible to
effect a particular element without creating inline style for it.
• ID’s are unique . They are identified by symbol “#”.
• Can be applied to some occurrence of an element but not the
others.
• This can be done by classes, it not need to be unique.
• Many elements can be members of the same class. It is identified
by the symbol “.”
18. USING DIV TAG
• A web page can be divided into segments or divisions.
• It can be achieved using <div>……</div> tags.
• The HTML <div> tag is used for defining a section of your
document.
• With the div tag, you can group large sections of HTML
elements together and format them with CSS.
• Its attribute is
– Align = Defines alignment of the content enclosed in div tag.
(left, right, center and justify)
19. • <div style="color:#00FF00“>
<h3>This is a header</h3>
<p>This is a paragraph.</p>
</div>
• <body>
<div style="background: green">
<h5 >SEARCH LINKS</h5>
<a href="http://www.google.com">Google</a> </div>
</body>
• <div id="menu" align="right" >
<a href="">HOME</a>
<a href="">CONTACT</a>
<a href="">ABOUT</a>
</div>
• <div id="content" align="left" bgcolor="white">
<h5>Content Articles</h5>
<p>This paragraph would be your content paragraph with all of
your readable material.</p>
</div>
20. USING SPAN TAG
• Used to provide the style information to few words or
even few letters.
• It can be achieved by using <span>…… </span>tags.
• Like
<span style="color : #f00;">2ndWord</span>
• <p>My text book color : <span class="blue">light
blue</span> eyes.</p>
• <span style="background-color: #FFFF00">You can
highlight your text any color you like</span>
21. <html>
<head>
</head>
<body>
<span style="color : #f00;">2ndWord</span>
<p>My text book color : <span
class="blue">light blue</span> with flower
images.</p>
<span style="background-color: #FFFF00">You
can highlight your text any color you
like</span>
</body>
</html>
22. <html>
<head>
</head>
<body>
<span style="color : #f00;">2ndWord</span>
<p>My text book color : <span class="blue">light blue</span> with flower images.</p>
<span style="background-color: #FFFF00">You can highlight your text any color you like</span>
<br>
<STYLE TYPE="text/css">
.newtext
{
font-size: 18pt;
color: #ff0000;
font-family: arial
}
#newtext2
{
font-size: 20pt;
color: #ff00ff;
font-family: courier
}
</STYLE>
<SPAN CLASS="newtext">Here's What You Get</SPAN>
<SPAN ID="newtext2">Here's What You Get</SPAN>
</body>
</html>
24. Multiple Style Sheets
• If some properties have been defined for the same selector in different style sheets,
the value will be inherited from the more specific style sheet.
• For example, assume that an external style sheet has the following properties for
the <h1> element:
• then, assume that an internal style sheet also has the following property for the
<h1> element:
• If the page with the internal style sheet also links to the external style sheet the
properties for the <h1> element will be:
• The left margin is inherited from the external style sheet and the color is replaced by
the internal style sheet.
color: orange;
margin-left: 20px;
h1
{
color: orange;
}
h1
{
color: navy;
margin-left: 20px;
}
25. <html>
<head>
<title> Embedding a style sheet</title>
<style>
body
{
background: yellow;
margin-left: 1 in;
margin-right: 1.5 in;
color: green
}
h1
{
font-size: 40pt;
font-family: san-serif;
color:red;
text-align: center;
text-transform:lowercase
}
p
{
font-size: 12pt;
font-family: serif;
color: blue
}
</style>
</head>
<body>
<h2>this tag is reflecting only other effects over the page</h2>
this is the simple text in the page
<h1>THIS TAG implements the embeded effect of h1 headig tag</h1><br>
<p>this tag implements the embeded effect of paragraph tag.<br>
</body>
</html>
Embedding a style sheet
26. Id - css
<html>
<head>
<title>Using ID in html document</title>
<style type="text/css">
#firstparagraph
{
background: yellow
}
#secondparagraph
{
background: red
}
</style>
</head>
<body>
<p>paragraph without using any ID</p>
<h1>Hello</h1>
<h1 id="firstparagraph">Hw r u?</h1>
<p id="firstparagraph">This is implementation of first paragraph ID</p>
<p id="secondparagraph">This is implementation of second paragraph ID</p>
</body>
</html>
27. <html>
<head>
<title>using ids in html document</title>
<style ="text/css">
p#exampleID1
{
background-color: yellow
}
p#exampleID2
{
text-transform: uppercase
}
</style>
</head>
<body>
<p id="exampleID1">This paragraph has an ID name of
"exampleID1" and has a white CSS defined background
<p id="exampleID2">This paragraph has an ID name of
"exampleID2" and has had its text transformed to uppercase letters.
</body>
</html>
Id - css
28. <html>
<head>
<title>Using class in html document</title>
<style>
.firstparagraph
{
background: green
}
.secondparagraph
{
background: red
}
</style>
</head>
<body>
<p>paragraph without using any ID
<p class="firstparagraph">This is implementation of first paragraph
class</p>
<p class="secondparagraph">This is implementation of second
paragraph class</p>
<h2 class="firstparagraph">This is the heading tag</h2>
</body>
</html>
CSS- Classes
29. <html>
<head>
<title>using ids in html document</title>
<style type="text/css">
.exampleID3
{ background-color: red;
color: white
}
</style>
</head>
<body>
<p class='exampleID3'>These paragraphs all have the same styling applied to them and we
used classes because we wanted to reuse our styling!
<p class='exampleID3'>These paragraphs all have the same styling applied to them and we
used classes because we wanted to reuse our styling!
<p class='exampleID3'>These paragraphs all have the same styling applied to them and we
used classes because we wanted to reuse our styling!
</body>
</html>
CSS- Classes
30. <html>
<head>
<title>Using class in html document</title>
<style type="text/css">
.firstparagraph
{
background: blue
}
.secondparagraph
{
background: red
}
</style>
</head>
<body>
<p class="firstparagraph">paragraph without using any ID
<p>This is implementation of first paragraph class</p>
<p class="secondparagraph">This is implementation of second
paragraph class</p>
<h1 class="firstparagraph">hello</h1>
<h2 class="secondparagraph">hellooooooo</h2>
</body>
</html>
CSS- Classes
33. CSS Styling HTML Lists
In HTML, there are two types of lists:
1.Ordered Lists <ol>:Items marked with numbers or letters.
2.Unordered Lists <ul>: Items marked with bullets.
With CSS, you can use your own images as bullets in a list. The CSS list
properties allows you to:
• Set different list item markers for ordered lists.
• Set different list item markers for unordered lists.
• Set an image as the list item marker.
34. ul {
list-style-type: circle;
}
ol {
list-style-type: lower-roman;
}
The following keywords work with
the list-style-type property:
• disc
• circle
• square
• decimal
• decimal-leading-zero
• lower-roman
• upper-roman
• lower-greek
• lower-latin
• upper-latin
• armenian
• georgian
• lower-alpha
• upper-alpha
• none - removes the bullets
35. <html>
<head>
<title> DrSantosh Web Page</title>
<style>
ul {
list-style-type: circle;
}
ol {
list-style-type: lower-roman;
}
</style>
</head>
<body>
<h1> List of Components </h1>
<UL>
<LI> Computer Devices …</LI>
<LI> Computers …</LI>
<OL>
<LI> DELL …</LI>
<LI> TOSHIBA …</LI>
<LI> LENOVA …</LI>
<LI> ACER …</LI>
<LI> MAC …</LI>
</OL>
<LI> Prices …</LI>
</UL>
</body>
</html>
36. ul{
list-style-position: inside;
}
Positioning the List Item Markers
• The list-style-position property lets you set the position of the list on webpage.
• It accepts two values, inside & outside.
• The default value is outside.
Image as the List Item Marker
ul{
list-style-image: url('images/bullet.png');
}
• it is possible to use an image as a bullet marker on your webpage. This
can be done by using the list-style-image property.
• It can either set it to none, or you can provide a url to some image.
37. <!DOCTYPE html>
<html>
<head>
<style>
ul#circle {
list-style-image: url('examples/css/resources/circle.png');
}
</style>
</head>
<body>
<p>Red Circle List Marker:</p>
<ul id="circle">
<li>Game of Thrones</li>
<li>Breaking Bad</li>
<li>Sherlock</li>
</ul>
</body>
</html>
42. CSS Styling HTML Tables
<table class="styled-table">
<thead>
<tr>
<th>Name</th>
<th>Points</th>
</tr>
</thead>
<tbody>
<tr>
<td>Dom</td>
<td>6000</td>
</tr>
<tr class="active-row">
<td>Melissa</td>
<td>5150</td>
</tr>
<!-- and so on... -->
</tbody>
</table>
•.styled-table so we don't tamper with every <table> on the site
•.active-row which will be the "active" row - this class is used to highlight a specific row
43. Styling the table
.styled-table {
border-collapse: collapse;
margin: 25px 0;
font-size: 0.9em;
font-family: sans-serif;
min-width: 400px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
}
•box-shadow to add a subtle transparent shadow around the table
•border-collapse to ensure there is no space between the cell borders
Styling the header .styled-table thead tr {
background-color: #009879;
color: #ffffff;
text-align: left;
}
44. Moving onto the table cells
.styled-table th,
.styled-table td {
padding: 12px 15px;
}
the table rows
.styled-table tbody tr {
border-bottom: 1px solid #dddddd;
}
.styled-table tbody tr:nth-of-type(even) {
background-color: #f3f3f3;
}
.styled-table tbody tr:last-of-type {
border-bottom: 2px solid #009879;
}
It want to do 3 things:
• Add a bottom border to each row for separation
• Add a lighter background to every second row to help readability
• Add a dark border to the very last row to signify the end of the table
45. make the active row look different
.styled-table tbody tr.active-row {
font-weight: bold;
color: #009879;
}