CSS For Styling
CSS For Styling
<html>
<head>
<style>
body { background-color:lime; }
p{ font-size: x-large ; background-color : yellow }
</style>
</head>
<body>
<p>Hello world</p>
</body>
</html>
CSS Selectors
CSS selectors are used to "find" (or select) HTML elements based on
their element name, id, class, attribute, and more.
.center {
text-align: center;
color: red;
}
<html><HEAD>
<style>
.ex1{
color: green;
font-size: 20px;
line-height: 25px;
}
.ex2{
color: red;
font-size: 30px;
line-height: 25px;
}
</style>
<body>
<ol class="ex1" type="1">
<li>Apple</li>
<li>Orange</li>
<li>Grapefruit</li>
</ol>
<ul class="ex2" type="disc">
<li>Apple</li>
<li>Orange</li>
<li>Grapefruit</li>
</ul>
</body></html>
<html>
<head>
<style>
p.center {
text-align: center;
color: red;
}
p.centerlarge {
font-size: 100%;
}
</style>
</head>
<body>
<h1 class="center">CSS stands for Cascading Style Sheets.</h1>
<p class="center"> CSS is a language that describes the style of an HTML document </p>
<p class="centerlarge"> The class selector selects elements with a specific class attribute </p>
</body>
Grouping Selectors
• If you have elements with the same style definitions, like this:
• In this CSS rules are defined with in the document itself using style tag.
• Internal styles are defined within the <style> element, inside the <head> section
of an HTML page:
Example for Internal Style sheet
<html>
<head>
<title>Cascading Style Sheet</title>
<style>
h2 {
font-family : Tahoma;
color: blue;
text-align: center;
text-transform : uppercase;
}
</style>
</head>
<body>
<h2> Hi guys how r u</h2>
</body>
</html>
Inline Styles
• An inline style may be used to apply a unique style for a single element.
• To use inline styles, add the style attribute to the relevant element.
• The style attribute can contain any CSS property.
• The example below shows how to change the color and the left margin of
a <h1> element:
<html>
<head>
<title>Cascading Style Sheet</title>
</head>
<body>
<h2 style= "font-family : Tahoma;
color: red;
text-align: center;
text-transform : uppercase;">
Hi guys how r u</h2>
</body>
</html>
External Style Sheet
• An external style sheet can be written in any text editor. The file
should not contain any html tags. The style sheet file must be saved
with a .css extension.
• Here is how the "mystyle.css" looks:
mystyle.css:
body {
background-color: lightblue;
}
h1 {
color: navy;
margin-left: 20px;
}
<html>
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
CSS Basic Properties
1. Background Properties
2. Font Properties
3. Text Properties
4. Border Properties
CSS Background Properties
Property Description
background Sets all the background properties in one background: lightblue url("img_tree.gif")
declaration no-repeat fixed center
background-color Sets the background color of an element background-color: green;
font Sets all the font properties in one font: italic bold 12px Georgia, serif;
declaration
font-family Specifies the font family for text font-family: "Times New Roman", Times, serif;