Cascading Style Sheets (CSS) Is A Style Sheet Language Used
Cascading Style Sheets (CSS) Is A Style Sheet Language Used
26
<html> <head>
a.five:visited
<style type="text/css">
{color:#0000ff; text-
a.one:link {color:#ff0000;}
decoration:none;}
a.one:visited
a.five:hover{text-
{color:#0000ff;} a.one:hover
decoration:underline;}
{color:#ffcc00;} a.two:link
a.six:link,a.six:visited
{color:#ff0000;}
{ display:block;
a.two:visited
font-
{color:#0000ff;} a.two:hover
weight:bold;
{font-size:150%;}
color:#FFFFFF;
a.three:link {color:#ff0000;}
background-
a.three:visited
color:#98bf21;
{color:#0000ff;}
width:120px;
a.three:hover
text-
{background:#66ff66;} a.four:link
align:center;
{color:#ff0000;} a.four:visited
</style> </head>
padding:4px;
{color:#0000ff;} a.four:hover
text-
<body>
<p>Mouse over the links to see them change layout.</p>
<p><b><a class="one" href="default.asp" target="_blank">This
link changes color</a></b></p>
<p><b><a class="two" href="default.asp" target="_blank">This
link changes font-size</a></b></p>
<p><b><a class="three" href="default.asp" target="_blank">This
link changes background-color</a></b></p>
<p><b><a class="four" href="default.asp" target="_blank">This
link changes font-family</a></b></p>
<p><b><a class="five" href="default.asp" target="_blank">This
link changes text-decoration</a></b></p>
<p><b><a class="six" href="../tutorial.html"
target="_blank">This link changes Box Color</a></b></p>
</body></html>
List Properties
PropertyDescription
list-style-image Specifies an image as the list-item marker
list-style-position Specifies if the list-item markers should
appear inside or outside the content flow
list-style-type Specifies the type of list-item marker
list-style Sets all the properties for a list in one declaration
ol.t {list-style-
type:upper- roman;}
ol.u {list-style-
type:none;} ol.v {list-
style-image:
url("sqpurple.gif");}
</style> </head>
<body>
<ul class="a">
<li>Circle type</li>
</ul>
<ul class="b">
<li>Disc type</li> </ul>
<ul class="c"> <ol class="r">
<li>Square type</li></ul> <li>Upper-alpha type</li>
<ol class="f"> </ol>
<li>Decimal type</li></ol> <ol class="t">
<ol class="g"> <li>Upper-roman
type</li>
<li>Decimal-leading-
zero type</li> </ol>
<ol class="u">
</ol>
<li>None type</li>
<ol class="n">
</ol>
<li>Lower-alpha <ol class="v">
type</li>
<li>Image type</li>
</ol>
</ol>
<ol class="q">
</body> </html>
<li>Lower-roman
type</li>
Table Properties
Table
Borders
table, th, td
{
border: 1px
solid
red;
}
Notice that the table in the example above has double borders.
This is because both the table and the th/td elements have
separate borders.
To display a single border for the table, use the border-
Collapse Table Width and Height
Borders
The border-collapse property Width and height of a table
sets whether the table borders is defined by the width and
are collapsed into a single height properties.
border or separated: table
table {
{ width:100%;
border-collapse:collapse; }
} th
table, td, th {
{ height:50px;
border:1px solid red; }
}
Table Text Alignment
The text in a table is aligned with the text-align and vertical-align
properties.
The text-align property sets the horizontal alignment, like left,
right, or center
td
{
text-align:right;
}
The vertical-align property sets the vertical alignment, like top,
bottom, or middle:
td
{
height:50px;
vertical-align:bottom;
}
Table Padding
To control the space between the border and content in a table,
use the padding property on td and th elements:
td
{
padding:15px;
}
Table Color
The example below specifies the color of the borders, and the
text and background color of th elements:
table, td, th
{
border:1px solid green;
}
th
{
background-color:green;
color:white;
}
<html> <head> <body>
<style <table>
type="text/css"> table <tr>
<th>Student Name</th>
{ border-
<th>Seminar Topic</th>
collapse:collapse;
</tr>
t width:50%; } <tr>
h height:50px; <td>Madhusuthanan P</td>
{ vertical-align:center; <td>Internet, Intranet
td } and WWW</td>
{ text- } </tr>
align:right; <tr>
table,th,td <td>Roopa S</td>
{ <td>Internet
border:1px Protocols</td>
</tr>
solid red;
</table> </body> </html>
}
</style> </head>
BOX
layout. It is essentially MODEL
In CSS, the term "box model" is used when talking about design and
a box that wraps around HTML elements.
Margin - Clears an area around the border. The margin does not
have a background color, it is completely transparent .
Border - A border that goes around the paddingand content.
The border is affected by the background color of the box.
Padding - Clears an area around the content. The padding is
affected by the background color of the box.
Content - The content of the box, where text and images appear.
39 T
E
Width and Height of an Element
When you set the width and height properties of an element with
CSS, you just set the width and height of the content area.
The total width of an element should be calculated like this:
Total element width = width + left padding + right padding + left
border + right border + left margin + right margin
The total height of an element should be calculated like this:
Total element height = height + top padding + bottom padding +
top border + bottom border + top margin + bottom margin
Exampl width:250px;
e: padding:10px;
border:5px solid
gray; margin:10px;
38
Browsers Compatibility Issue
The example above does not display properly in IE8 and
earlier versions.
IE8 and earlier versions includes padding and border in
the width, if a
DOCTYPE is NOT declared.
To fix this problem, just add a DOCTYPE to the first line of
HTML page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtm
l1/DTD/xhtml1- transitional.dtd">
39
<html> <head>
<style
type="text/css">
{div.ex width:220px;
padding:10px;
border:5px solid
gray; margin:0px;
background-
} color:pink;
</style> </head><body>
<div class="ex">The line
above is 250px wide.<br />
Now the total width of this
element is also 250px.</div>
</body> </html>
40
Border Properties
It allows you to specify the style and color of an element's
border.
Border Style Border Color
The border-style property The border-color property is
specifies what kind of used to set the color of the
border to display. border. The color can be set
Dotted by:
Dashed You can also set the border
8 August
2019
HTML <span>
The <span> Tag
tag is used to group inline-elements in a
document.
The <span> tag provides no visual change by itself.
The <span> tag provides a way to add a hook to a part of a
text or a part of a document.
When the text is hooked in a <span> element you can add
styles to the content, or manipulate the content with for
example JavaScript.
<p>My mother has <span style="color:lightblue;font-
weight:bold " >light blue</span> eyes and my father has
<span style="color:darkolivegreen;font-
weight:bold">dark green
</span> eyes.</p>
inherit
The inherit keywordspecifies that a
property should inherit its value from its parent
element.
The inherit keyword can be used for any CSS property, and
on any HTML element.
<!DOCTYPE html>
<html> <head> <style>
span {
color: blue; border:
1px solid black; }
.extra span
{ color:
inherit;}
<body>
<div> Here is <span>a span element</span>
which is blue, as span elements are set to be.
</div>
<div class="extra" style="color:green">
Here is <span>a span element</span> which is
green, because it inherits from its parent.</div>
<div style="color:red"> Here is <span>a
span element</span>
which is blue, as span elements are set to
be. </div>
</body ></html>
65 V.MAREESWARI / AP(Sr) /
SITE
<div style="font-family:serif; border:1px solid
red; padding:10px;"> This text will be in a
serif font.
<p> This text is also in a serif font, because
font is inherited by default. But the border and
padding properties are not inherited
<div style="font-family:serif; fromsolid
border:1px the
parent div.</p></div><br>
red; padding:10px;"> This text will be in a
serif font.
<p style="border:inherit;"> Now the paragraph also has a
red border. Border properties are not inherited by children,
by default, but because I set border to “inherit”, it is.
</p></div>
66
67 V.MAREESWARI / AP(Sr) /
SITE
use the CSS position property to create a
webpage
Create a blank web page with just html, head, body, and a style tag.
Change the background of the page to be a sky blue and have a background image
of clouds.
Create a div for the grass - position it at the bottom and give it an appropriate
height.
Create a div for the "Farm Party!" banner - position it near the top center area, and
style the text so that it's red. For a bonus, use a fun custom font (like from Google
Web Fonts) and give it the appearance of a black stroke.
For each of the images shown, search for an appropriate image on Google Image
search - it doesn't have to be the exact same. Try searches like "sheep animated
gif" and if you need to, restrict the results to just "clip art". When you find the
image, create a img for it on the page.
Position each of the img elements appropriately. The sheep should be around the
bottom left, the cow should be on the horizon, the dude should be dancing in the
middle, the tree should be on the front right, and the sun should be around the
upper right.
As a bonus, position a picture of your face on top of the dude, and watch yourself
have a farm party!
68