CSS (Cascading Style Sheet)
CSS (Cascading Style Sheet)
What is CSS?
CSS stands for Cascading Style
Sheets,
Design language intended to simplify
the process of making web pages
presentable
handles the look and feel part of a
web page
Advantages of CSS
CSS saves time
Pages load faster
Easy maintenance
Superior styles to HTML
Multiple Device Compatibility
Global web standards
SYNTAX
Selector: A selector is an HTML tag at which a style
will be applied. This could be any tag like <h1> or
<table> etc.
Property: A property is a type of attribute of HTML
tag. Put simply, all the HTML attributes are
converted into CSS properties. They could be color,
border, etc.
Value: Values are assigned to properties. For
example, color property can have the value either
red or #F1F1F1 etc.
h1, h2, h3 {
color: black;
font-weight: normal;
letter-spacing: .4em;
margin-bottom: 1em;
text-transform: lowercase;
}
External Style
Sheet(Cont…)
Now you can include this file mystyle.css in
any HTML document as follows:
<head>
<link href="mystyle.css“ rel="stylesheet"/>
</head>
Priorities of Style Sheet
Inline
Internal
External
CSS Comments
/* This is an external style sheet file */
h1, h2, h3 {
color: #36C;
font-weight: normal;
letter-spacing: .4em;
margin-bottom: 1em;
text-transform: lowercase;
}
/* end of style rules. */
Selectors
Class selector
Id selector
Descendant Selector
Child Selectors
Attribute Selectors
Grouping Selectors
Class selector
.black
{
color: red;
}
ul li
{
color: red;
}
Child Selectors
body > p
{
color: #000000;
}
background-color
background-image
background-repeat
background-position
background-attachment
background property
Set the Background Color
<p style="background-color:yellow;">
This text has a yellow background color.
</p>
Set the Background Image
<table style="background-
image:url(/images/pattern1.gif);">
<tr><td>
This table has background image set.
</td></tr>
</table>
Repeat the Background Image
<table style="background-
image:url(/images/pattern1.gif);
background-repeat: repeat;">
<tr><td>
This table has background image which
repeats multiple times.
</td></tr>
</table>
Repeat the Background
Image(Cont…)
Horizontally:
<table style="background-
image:url(/images/pattern1.gif);
background-repeat: repeat-x;">
<tr><td>
This table has background image set which will repeat
horizontally.
</td></tr>
</table>
Repeat the Background
Image(Cont…)
Vertically:
<table style="background-
image:url(/images/pattern1.gif);
background-repeat: repeat-y;">
<tr><td>
This table has background image set which
will repeat vertically.
</td></tr>
</table>
background-position
<table style="background-
image:url(/images/pattern1.gif);
background-position:100px 200px;">
<tr><td>
This table has background image positioned
100
pixels away from the left and 200 pixels from
the top.
</td></tr>
</table>
Set the Background
Attachment
<p style="background-
image:url(/images/pattern1.gif);
background-attachment:fixed;">
This parapgraph has fixed background image.
</p>
<p style="background-
image:url(/images/pattern1.gif);
background-attachment:scroll;">
This parapgraph has scrolling background image.
</p>
CSS Fonts
CSS Fonts
font-family property
font-style property
font-variant property
font-weight property
font-size property
font-family property
<p style="font-
family:georgia,garamond,serif;">
This text is rendered in either georgia,
garamond, or the default
serif font depending on which font you have at
your system.
</p>
It will produce the following result:
font-style property
<p style="font-style:italic;">
This text will be rendered in italic style
</p> t-style:italic;">
Explore it by yourself
CSS Links
CSS Links
:link signifies unvisited hyperlinks.
:visited signifies visited hyperlinks.
:hover signifies an element that currently
has the user's mouse pointer hovering
over it.
:active signifies an element on which the
user is currently clicking.
Explore it by yourself
CSS Tables
CSS Tables
border-collapse specifies whether the browser should
control the appearance of the adjacent borders that touch
each other or whether each cell should maintain its style.
border-spacing specifies the width that should appear
between table cells.
caption-side captions are presented in the <caption>
element. By default, these are rendered above the table in
the document. You use the caption-side property to control
the placement of the table caption.
empty-cells specifies whether the border should be shown
if a cell is empty.
table-layout allows browsers to speed up the layout of a
table by using the first width properties it comes across for
the rest of a column rather than having to load the whole
table before rendering it.
CSS Border
CSS Border
The border properties allow you to specify how
the border of the box representing an element
should look. There are three properties of a
border you can change:
<a href="http://www.w3schools.com">w3schools.com</a>
<a href="http://www.wikipedia.org">wikipedia.org</a>
</body>
</html>
Mouse Hover Example
Output