M2 Part6
M2 Part6
What is CSS?
• CSS stands for Cascading Style Sheet.
• CSS is used to add styling description to the html content.
• CSS is used to separate the webpage content and presentation
design style.
• This allows the usage of one presentation design style to be used
in multiple webpage content.
• CSS files are stored with an extension .css
• CSS has a separate syntax and rules to be adapted.
• Each rule is a combination of one or more selectors.
Advantages of CSS
• It is very simple and easy to use
• Follows Global Web Standards and hence
trustable
• It is platform independent
• Saves lot of time through the usage of internal and
external styling
• Since the styling is written separately in external
css, the html page gets loaded faster.
Structure of CSS
Webpage
Style-
Structure
formatting
HTML or
CSS
XHTML
What is a Selector?
A selector is a pattern that is used to select a particular element to be
styled. The selector is made up of three parts namely;
Selector-name { property: value}
<head>
<style>
p[style] { background-color: red; }
font[text~=blue] { background-color: blue; }
</style>
</head>
<body>
<p style> Hi! I am in Red…</p>
<p style="text-align: center;"> Hi! I also in Red…</p>
<p style="background-color: yellow"> Hi! I am in Yellow….</p>
<font style text=blue> Hi! I am Blue….</font><br><br>
<font style text=pink> Hi! I am not in Blue….</font>
</body>
</html>
Types of CSS
- Inline Stylesheet: the styling codes are written directly in
the specific element itself
<body>
<h2> Welcome to CSS …. </h2>
<h3> Welcome to CSS Internal Styling….. </h3>
<p> This is also called as Embedded Styling….</p>
</body>
</html>
Structure of External CSS
• An External CSS is written as a separate file and saves with an
extension .css
• This way of writing allows the usage of the same stylesheet to be
used in many html documents.
• The link between the html and css file is established through a
<link> tag in the html code, using ‘href’ attribute to specify the
path of the css file. This path can either be a relative URL or
absolute.
• This link tag is usually written inside the <head> tag for it to be
loaded before starting with the body content.
<html>
<head> External CSS
<link rel=“stylesheet” type=“text/css” href=“extstyle.css”>
</head>
<body>
<h2> Welcome to CSS …. </h2>
<h3> Welcome to CSS Internal Styling….. </h3>
<p> This is also called as Embedded Styling….</p>
</body>
</html>
extstyle.css
h3 {
font-family: ‘Times New Roman’;
color: blue;
text-decoration: italics;”
}
p,h2 {
color: red;
}