Page 1

Courseware-CSS

What is CSS? •

CSS stands for Cascading Style Sheets

Styles define how to display HTML elements

Styles are normally stored in Style Sheets

Styles were added to HTML 4.0 to solve a problem

External Style Sheets can save you a lot of work

External Style Sheets are stored in CSS files

Multiple style definitions will cascade into one

Styles Solve a Common Problem HTML tags were originally designed to define the content of a document. They were supposed to say "This is a header", "This is a paragraph", "This is a table", by using tags like <h1>, <p>, <table>, and so on. The layout of the document was supposed to be taken care of by the browser, without using any formatting tags. As the two major browsers - Netscape and Internet Explorer - continued to add new HTML tags and attributes (like the <font> tag and the color attribute) to the original HTML specification, it became more and more difficult to create Web sites where the content of HTML documents was clearly separated from the document's presentation layout. To solve this problem, the World Wide Web Consortium (W3C) - the non profit, standard setting consortium, responsible for standardizing HTML created STYLES in addition to HTML 4.0. All major browsers support Cascading Style Sheets.

Style Sheets Can Save a Lot of Work Styles sheets define HOW HTML elements are to be displayed, just like the font tag and the color attribute in HTML 3.2. Styles are normally saved in external .css files. External style sheets enable you to change the appearance and layout of all the pages in your Web, just by editing one single CSS document!

Page 1 of 40


Courseware-CSS

CSS is a breakthrough in Web design because it allows developers to control the style and layout of multiple Web pages all at once. As a Web developer you can define a style for each HTML element and apply it to as many Web pages as you want. To make a global change, simply change the style, and all elements in the Web are updated automatically.

Multiple Styles Will Cascade Into One Style sheets allow style information to be specified in many ways. Styles can be specified inside a single HTML element, inside the <head> element of an HTML page, or in an external CSS file. Even multiple external style sheets can be referenced inside a single HTML document.

Cascading Order What style will be used when there is more than one style specified for an HTML element? Generally speaking we can say that all the styles will "cascade" into a new "virtual" style sheet by the following rules, where number four has the highest priority: 1. Browser default 2. External style sheet 3. Internal style sheet (inside the <head> tag) 4. Inline style (inside an HTML element) So, an inline style (inside an HTML element) has the highest priority, which means that it will override a style declared inside the <head> tag, in an external style sheet, or in a browser (a default value).

CSS Syntax The CSS syntax is made up of three parts: a selector, a property and a value:

Page 2 of 40


Courseware-CSS

selector {property: value}

The selector is normally the HTML element/tag you wish to define, the property is the attribute you wish to change, and each property can take a value. The property and value are separated by a colon, and surrounded by curly braces: body {color: black}

Note: If the value is multiple words, put quotes around the value: p {font-family: "sans serif"}

Note: If you wish to specify more than one property, you must separate each property with a semicolon. The example below shows how to define a center aligned paragraph, with a red text color: p {text-align:center;color:red}

To make the style definitions more readable, you can describe one property on each line, like this: p { text-align: center; color: black; font-family: arial }

Grouping You can group selectors. Separate each selector with a comma. In the example below we have grouped all the header elements. All header elements will be displayed in green text color:

Page 3 of 40


Courseware-CSS

h1,h2,h3,h4,h5,h6 { color: green }

The class Selector With the class selector you can define different styles for the same type of HTML element. Say that you would like to have two types of paragraphs in your document: one right-aligned paragraph, and one center-aligned paragraph. Here is how you can do it with styles: p.right {text-align: right} p.center {text-align: center}

You have to use the class attribute in your HTML document: <p class="right"> This paragraph will be right-aligned. </p> <p class="center"> This paragraph will be center-aligned. </p>

Note: Only one class attribute can be specified per HTML element! The example below is wrong: <p class="right" class="center"> This is a paragraph. </p>

You can also omit the tag name in the selector to define a style that will be used by all HTML elements that have a certain class. In the example below, all HTML elements with class="center" will be center-aligned:

Page 4 of 40


Courseware-CSS

.center {text-align: center}

In the code below both the h1 element and the p element have class="center". This means that both elements will follow the rules in the ".center" selector: <h1 class="center"> This heading will be center-aligned </h1> <p class="center"> This paragraph will also be center-aligned. </p>

NOTE: Do NOT start a class name with a number! It will not work in Mozilla/Firefox.

The id Selector You can also define styles for HTML elements with the id selector. The id selector is defined as a #. The style rule below will match the element that has an id attribute with a value of "green": #green {color: green} The style rule below will match the p element that has an id with a value of "para1": p#para1 { text-align: center; color: red }

NOTE: Do NOT start an ID name with a number! It will not work in Mozilla/Firefox

Page 5 of 40


Courseware-CSS

CSS Comments Comments are used to explain your code, and may help you when you edit the source code at a later date. A comment will be ignored by browsers. A CSS comment begins with "/*", and ends with "*/", like this: /* This is a comment */ p { text-align: center; /* This is another comment */ color: black; font-family: arial }

How to Insert a Style Sheet When a browser reads a style sheet, it will format the document according to it. There are three ways of inserting a style sheet:

External Style Sheet An external style sheet is ideal when the style is applied to many pages. With an external style sheet, you can change the look of an entire Web site by changing one file. Each page must link to the style sheet using the <link> tag. The <link> tag goes inside the head section: <head> <link rel="stylesheet" type="text/css" href="mystyle.css" /> </head>

Page 6 of 40


Courseware-CSS

The browser will read the style definitions from the file mystyle.css, and format the document according to it. An external style sheet can be written in any text editor. The file should not contain any html tags. Your style sheet should be saved with a .css extension. An example of a style sheet file is shown below: hr {color: sienna} p {margin-left: 20px} body {background-image: url("images/back40.gif")}

NOTE: Do NOT leave spaces between the property value and the units! If you use "margin-left: 20 px" instead of "margin-left: 20px" it will only work properly in IE6 but it will not work in Mozilla/Firefox or Netscape.

Internal Style Sheet An internal style sheet should be used when a single document has a unique style. You define internal styles in the head section by using the <style> tag, like this: <head> <style type="text/css"> hr {color: sienna} p {margin-left: 20px} body {background-image: url("images/back40.gif")} </style> </head>

The browser will now read the style definitions, and format the document according to it. Note: A browser normally ignores unknown tags. This means that an old browser that does not support styles, will ignore the <style> tag, but the content of the <style> tag will be displayed on the page. It is possible to

Page 7 of 40


Courseware-CSS

prevent an old browser from displaying the content by hiding it in the HTML comment element:

<head> <style type="text/css"> <!-hr {color: sienna} p {margin-left: 20px} body {background-image: url("images/back40.gif")} --> </style> </head>

Inline Styles An inline style loses many of the advantages of style sheets by mixing content with presentation. Use this method sparingly, such as when a style is to be applied to a single occurrence of an element. To use inline styles you use the style attribute in 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 paragraph: <p style="color: sienna; margin-left: 20px"> This is a paragraph </p>

Multiple Style Sheets If some properties have been set for the same selector in different style sheets, the values will be inherited from the more specific style sheet. For example, an external style sheet has these properties for the h3 selector: h3 { color: red;

Page 8 of 40


Courseware-CSS

text-align: left; font-size: 8pt }

And an internal style sheet has these properties for the h3 selector: h3 { text-align: right; font-size: 20pt } If the page with the internal style sheet also links to the external style sheet the properties for h3 will be: color: red; text-align: right; font-size: 20pt The color is inherited from the external style sheet and the text-alignment and the font-size is replaced by the internal style sheet.

CSS Background Properties The CSS background properties allow you to control the background color of an element, set an image as the background, repeat a background image vertically or horizontally, and position an image on a page. Browser support: IE: Internet Explorer, F: Firefox, N: Netscape.

Property

Description

Values

background

A shorthand

background-color

property for

background-image

setting all

background-repeat background

background

-attachment background-position

properties in one declaration

Page 9 of 40


Courseware-CSS

background-

Sets

whether

a scroll

attachment

background image fixed is fixed or scrolls with the rest of the page

background-color

Sets the

color-rgb,color-hex

background color

color-name,transparent

of an element background-image

Sets an image as url the background

background-position

Sets

the

none

starting top left

position of a

top center

background image top right center left center center center right bottom left bottom center bottom right x-% y-% x-pos y-pos background-repeat

Sets if/how a

repeat

background image repeat-x will be repeated

repeat-y no-repeat

Example for Background Properties <html> <head> <style type="text/css"> body

Page 10 of 40


Courseware-CSS

{ background: #00ff00 url('smiley.gif') no-repeat fixed center; } p {background-color: rgb(250,0,255)} </style> </head> <body> <h1>This is header 1</h1> <h2>This is header 2</h2> <p>This is a paragraph</p> </body> </html>

CSS Text Properties The CSS text properties allow you to control the appearance of text. It is possible to change the color of a text, increase or decrease the space between characters in a text, align a text, decorate a text, indent the first line in a text, and more. Browser support: IE: Internet Explorer, F: Firefox, N: Netscape. Property

Description

Values

color

Sets the color of a text color

direction

Sets the text direction ltr rtl

letter-spacing

Increase or decrease normal the space between

length

characters text-align

text-decoration

Aligns the text in an

Left,right,center

element

justify

Adds text

decoration

to None,underline overline line-through

Page 11 of 40


Courseware-CSS

blink text-indent

Indents the first line of length text in an element

text-shadow

% none color length

text-transform

Controls the letters in none an element

capitalize uppercase lowercase

unicode-bidi

normal embed bidi-override

white-space

word-spacing

Sets how white space normal inside an element is

pre

handled

nowrap

Increase or decrease normal the

space

between length

words

Exanple <html> <head> <style type="text/css"> h1 {color: #00ff00;letter-spacing: 5px;text-decoration: overline} .h2 {color: red;text-decoration: line-through} p {color: rgb(0,0,255);text-align: right;text-decoration: underline;} .highlight { background-color:yellow; text-transform: uppercase

Page 12 of 40


Courseware-CSS

} </style> </head> <body> <h1>This is header 1</h1> <span class="highlight"><h2 class="h2">This is header 2</h2></span> <p>This is a paragraph</p> </body> </html>

CSS Font Properties The CSS font properties allow you to change the font family, boldness, size, and the style of a text. Note: In CSS1 fonts are identified by a font name. If a browser does not support the specified font, it will use a default font. Browser support: IE: Internet Explorer, F: Firefox, N: Netscape. Property

Description

Values

font

A shorthand property font-style for setting all of the font-variant properties for a font in font-weight one declaration

font-size/lineheight font-family caption icon menu message-box small-caption status-bar

font-family

A prioritized list of font family-name

Page 13 of 40


Courseware-CSS

family names and/or generic-family generic family names for an element font-size

Sets the size of a font xx-small x-small small medium large x-large xx-large smaller larger length %

font-size-adjust

Specifies

an

aspect none

value for an element number that will preserve the x-height of the firstchoice font font-stretch

Condenses or expands normal the current font-family wider narrower ultra-condensed extra-condensed condensed semi-condensed semi-expanded

font-style

Sets the style of the normal font

italic oblique

font-variant

Displays

text

in

a normal

Page 14 of 40


Courseware-CSS

small-caps font or a small-caps normal font font-weight

Sets the weight of a Normal,bold,bolder font

lighter,100 to 900

Example: <html> <head> <style type="text/css"> .p1 { font: italic small-caps 900 12px arial } .p2 { font: normal normal 500 14px times } </style> </head> <body> <p class="p1">This is a paragraph1</p> <p class="p2">This is a paragraph2</p> </body> </html> CSS Border Properties The CSS border properties allow you to specify the style and color of an element's border. In HTML we use tables to create borders around a text, but with the CSS border properties we can create borders with nice effects, and it can be applied to any element. Browser support: IE: Internet Explorer, F: Firefox, N: Netscape. Property

Description

Values

Page 15 of 40


Courseware-CSS

border

A shorthand property border-width for setting all of the

border-style

properties for the four border-color borders in one declaration border-bottom

A shorthand property border-bottomfor setting all of the

width

properties for the

border-style

bottom border in one border-color declaration border-bottom-

Sets the color of the

border-color

color

bottom border

border-bottom-

Sets the style of the

style

bottom border

border-bottom-

Sets the width of the

thin

width

bottom border

medium

border-style

thick length border-color

Sets the color of the color four borders, can have from

one

to

four

colors border-left

A shorthand property border-left-width for setting all of the border-style properties for the left border-color border in one declaration

border-left-color

Sets the color of the border-color left border

border-left-style

Sets the style of the border-style left border

Page 16 of 40


Courseware-CSS

border-left-width

Sets the width of the thin left border

medium thick length

border-right

A shorthand property border-right-width for setting all of the border-style properties for the right border-color border in one declaration

border-right-color Sets the color of the border-color right border border-right-style Sets the style of the border-style right border border-right-width Sets the width of the Thin,medium right border border-style

thick,length

Sets the style of the None,hidden,dotted four borders, can have dashed,solid,double from one to four styles groove,ridge,inset outset

border-top

A shorthand property border-top-width for setting all of the border-style properties for the top border-color border in one declaration

border-top-color

Sets the color of the border-color top border

border-top-style

Sets the style of the border-style top border

border-top-width

Sets the width of the Thin, medium top border

border-width

thick, length

A shorthand property thin

Page 17 of 40


Courseware-CSS

for setting the width medium of the four borders in thick one

declaration,

can length

have from one to four values

Examples: Set the style of the four borders <html> <head> <style type="text/css"> p.dotted {border-style: dotted} p.dashed {border-style: dashed} p.solid {border-style: solid} p.double {border-style: double} p.groove {border-style: groove} p.ridge {border-style: ridge} p.inset {border-style: inset} p.outset {border-style: outset} </style> </head> <body> <p class="dotted">A dotted border</p> <p class="dashed">A dashed border</p> <p class="solid">A solid border</p> <p class="double">A double border</p> <p class="groove">A groove border</p> <p class="ridge">A ridge border</p> <p class="inset">An inset border</p> <p class="outset">An outset border</p> </body> </html>

Page 18 of 40


Courseware-CSS

Different border color <html> <head> <style type="text/css"> p.one { border-style: solid; border-color: #0000ff } p.two { border-style: solid; border-color: #ff0000 #0000ff } p.three { border-style: solid; border-color: #ff0000 #00ff00 #0000ff } p.four { border-style: solid double groove ridge; border-color: #ff0000 #00ff00 #0000ff rgb(250,0,255) } </style> </head> <body> <p class="one">One-colored border!</p> <p class="two">Two-colored border!</p> <p class="three">Three-colored border!</p> <p class="four">Four-colored border!</p>

Page 19 of 40


Courseware-CSS

<p><b>Note:</b> The "border-color" property does not work if it is used alone. Use the "border-style" property to set the borders first.</p> </body> </html>

ALL Boarder property <html> <head> <style type="text/css"> p { border: medium double rgb(250,0,255) } </style> </head> <body> <p>Some text</p> </body> </html>

Background Properties <html> <head> <style type="text/css"> p.one { border-style: solid; border-width: 5px } p.two { border-style: solid;

Page 20 of 40


Courseware-CSS

border-width: 5px 10px } p.three { border-style: solid; border-width: 5px 10px 1px } p.four { border-style: solid; border-width: 5px 10px 1px medium } </style> </head> <body> <p class="one">Some text</p> <p class="two">Some text</p> <p class="three">Some text</p> <p class="four">Some text</p> <p><b>Note:</b> The "border-width" property does not work if it is used alone. Use the "border-style" property to set the borders first.</p> </body> </html>

Note: The "border-width" property does not work if it is used alone. Use the "border-style" property to set the borders first.

CSS Margin Properties The CSS margin properties define the space around elements. It is possible to use negative values to overlap content. The top, right, bottom, and left margin can be changed independently using separate properties. A shorthand margin property can also be used to change all of the margins at once.

Page 21 of 40


Courseware-CSS

Note: Netscape and IE give the body tag a default margin of 8px. Opera does not! Instead, Opera applies a default padding of 8px, so if one wants to adjust the margin for an entire page and have it display correctly in Opera, the body padding must be set as well! Browser support: IE: Internet Explorer, F: Firefox, N: Netscape. Property

Description

Values

margin

A shorthand property margin-top for setting the margin margin-right properties

in

one margin-bottom

declaration margin-bottom

Sets

margin-left

the

bottom auto

margin of an element length % margin-left

Sets the left margin of auto an element

length %

margin-right

Sets the right margin auto of an element

length %

margin-top

Sets the top margin of auto an element

length %

Example: <html> <head> <style type="text/css"> p.margin {margin: 2cm 4cm 3cm 4cm} </style> </head>

Page 22 of 40


Courseware-CSS

<body> <p>This is a paragraph with no specified margins</p> <p class="margin">This is a paragraph with specified margins</p> <p>This is a paragraph with no specified margins</p> </body> </html>

CSS Padding Properties The CSS padding properties define the space between the element border and the element content. Negative values are not allowed. The top, right, bottom, and left padding can be changed independently using separate properties. A shorthand padding property is also created to control multiple sides at once. Browser support: IE: Internet Explorer, F: Firefox, N: Netscape. Property

Description

Values

padding

A shorthand property padding-top for setting all of

the padding-right

padding properties in padding-bottom one declaration padding-bottom

Sets

the

padding-left bottom length

padding of an element % padding-left

Sets the left padding length of an element

padding-right

Sets the right padding length of an element

padding-top

%

%

Sets the top padding length of an element

%

Page 23 of 40


Courseware-CSS

Example: <html> <head> <style type="text/css"> td.test1 {padding: 1.5cm} td.test2 {padding: 0.5cm 2.5cm} </style> </head> <body> <table border="1"> <tr> <td class="test1"> This is a tablecell with equal padding on each side. </td> </tr> </table> <br> <table border="1"> <tr> <td class="test2"> This tablecell has a top and bottom padding of 0.5cm and a left and right padding of 2.5cm. </td> </tr> </table> </body> </html>

CSS List Properties The CSS list properties allow you to place the list-item marker, change between different list-item markers, or set an image as the list-item marker.

Page 24 of 40


Courseware-CSS

Browser support: IE: Internet Explorer, F: Firefox, N: Netscape. Property

Description

Values

list-style

A shorthand property list-style-type for setting all of the list-style-position properties for a list in list-style-image one declaration

list-style-image

Sets an image as the none list-item marker

list-style-position

url

Sets where the list- inside item marker is placed outside in the list

list-style-type

Sets the type of the none list-item marker

disc circle square decimal decimal-leadingzero lower-roman upper-roman lower-alpha upper-alpha lower-greek lower-latin upper-latin hebrew armenian georgian cjk-ideographic hiragana katakana

Page 25 of 40


Courseware-CSS

hiragana-iroha katakana-iroha marker-offset

auto length

Examples: Unordered list <html> <head> <style type="text/css"> ul.disc {list-style-type: disc} ul.circle {list-style-type: circle} ul.square {list-style-type: square} ul.none {list-style-type: none} </style> </head> <body> <ul class="disc"> <li>Coffee</li> <li>Tea</li> <li>Coca Cola</li> </ul> <ul class="circle"> <li>Coffee</li> <li>Tea</li> <li>Coca Cola</li> </ul>

<ul class="square"> <li>Coffee</li> <li>Tea</li> <li>Coca Cola</li>

Page 26 of 40


Courseware-CSS

</ul> <ul class="none"> <li>Coffee</li> <li>Tea</li> <li>Coca Cola</li> </ul> </body> </html>

Ordered list <html> <head> <style type="text/css"> ol.decimal {list-style-type: decimal} ol.lroman {list-style-type: lower-roman} ol.uroman {list-style-type: upper-roman} ol.lalpha {list-style-type: lower-alpha} ol.ualpha {list-style-type: upper-alpha} </style> </head> <body> <ol class="decimal"> <li>Coffee</li> <li>Tea</li> <li>Coca Cola</li> </ol> <ol class="lroman"> <li>Coffee</li> <li>Tea</li> <li>Coca Cola</li> </ol> <ol class="uroman">

Page 27 of 40


Courseware-CSS

<li>Coffee</li> <li>Tea</li> <li>Coca Cola</li> </ol> <ol class="lalpha"> <li>Coffee</li> <li>Tea</li> <li>Coca Cola</li> </ol> <ol class="ualpha"> <li>Coffee</li> <li>Tea</li> <li>Coca Cola</li> </ol> </body> </html>

Image as list marker <html> <head> <style type="text/css"> ul { list-style-image: url('arrow.gif') } </style> </head> <body> <ul> <li>Coffee</li> <li>Tea</li> <li>Coca Cola</li>

Page 28 of 40


Courseware-CSS

</ul> </body> </html>

CSS Dimension Properties The CSS dimension properties allow you to control the height and width of an element. It also allows you to increase the space between two lines. Browser support: IE: Internet Explorer, F: Firefox, N: Netscape. Property

Description

Values

height

Sets the height of an auto element

length %

line-height

Sets

the

distance normal

between lines

number length %

max-height

Sets

the

maximum none

height of an element

length %

max-width

Sets

the

maximum none

width of an element

length

Page 29 of 40


Courseware-CSS

% min-height

Sets

the

minimum length

height of an element min-width

Sets

the

minimum length

width of an element width

%

%

Sets the width of an auto element

% length

Example: <html> <head> <style type="text/css"> p.small {line-height: 0.4cm} p.big {line-height: 1.9cm} </style> </head> <body> <p> This is a paragraph with a standard line-height. This is a paragraph with a standard line-height. This is a paragraph with a standard line-height. This is a paragraph with a standard line-height. </p> <p class="small"> This is a paragraph with a smaller line-height. This is a paragraph with a smaller line-height. This is a paragraph with a smaller line-height. This is a paragraph with a smaller line-height.

Page 30 of 40


Courseware-CSS

</p> <p class="big"> This is a paragraph with a bigger line-height. This is a paragraph with a bigger line-height. This is a paragraph with a bigger line-height. This is a paragraph with a bigger line-height. </p> </body> </html> CSS Classification Properties The CSS classification properties allow you to control how to display an element, set where an image will appear in another element, position an element relative to its normal position, position an element using an absolute value, and how to control the visibility of an element. Browser support: IE: Internet Explorer, F: Firefox, N: Netscape. Property

Description

Values

clear

Sets the sides of an left element where other right floating elements are both not allowed

cursor

none

Specifies the type of url cursor to be displayed auto crosshair default pointer move e-resize ne-resize nw-resize n-resize se-resize

Page 31 of 40


Courseware-CSS

sw-resize s-resize w-resize text wait help display

Sets how/if an element none is displayed

inline block list-item run-in compact marker table inline-table table-row-group table-headergroup table-footer-group table-row table-columngroup table-column table-cell table-caption

float

Sets where an image left or a text will appear in right another element

position

none

Places an element in a static static, absolute

relative, relative or

fixed absolute

Page 32 of 40


Courseware-CSS

position visibility

Sets

if

fixed an

element visible

should be visible invisible

or hidden collapse

Example For display <html> <head> <style type="text/css"> p {display: inline} div {display: none} </style> </head> <body> <p>A display property with a value of "inline" results in</p> <p>no distance between two elements.</p> <div>And this div section is not displayed!</div> </body> </html>

Use of float property <html> <head> <style type="text/css"> img { float:right } </style> </head> <body>

Page 33 of 40


Courseware-CSS

<p>In

the

paragraph

below,

we

have

added

an

image

with

style

<b>float:right</b>. The result is that the image will float to the right in the paragraph.</p> <p> <img src="logocss.gif" width="95" height="84" /> This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. </p> </body> </html>

AN image float with caption <html> <head> <style type="text/css"> div { float:right; width:120px; margin:0 0 15px 20px; padding:15px; border:1px solid black; text-align:center; } </style> </head> <body>

Page 34 of 40


Courseware-CSS

<div> <img src="logocss.gif" width="95" height="84" /><br /> CSS is fun! </div> <p> This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. </p> <p> In the paragraph above, the div element is 120 pixels wide and it contains the image. The div element will float to the right. Margins are added to the div to push the text away from the div. Borders and padding are added to the div to frame in the picture and the caption. </p> </body> </html>

Creating horizantol menu

<html>

Page 35 of 40


Courseware-CSS

<head> <style type="text/css"> ul { float:left; width:100%; padding:0; margin:0; list-style-type:none; } a { float:left; width:6em; text-decoration:none; color:white; background-color:purple; padding:0.2em 0.6em; border-right:1px solid white; } a:hover {background-color:#ff3300} li {display:inline} </style> </head> <body> <ul> <li><a href="#">Link one</a></li> <li><a href="#">Link two</a></li> <li><a href="#">Link three</a></li> <li><a href="#">Link four</a></li> </ul> <p>

Page 36 of 40


Courseware-CSS

In the example above, we let the ul element and the a element float to the left. The li elements will be displayed as inline elements (no line break before or after the element). This forces the list to be on one line. The ul element has a width of 100% and each hyperlink in the list has a width of 6em (6 times the size of the current font). We add some colors and borders to make it more fancy. </p> </body> </html>

Creating home page without table <html> <head> <style type="text/css"> div.container { width:100%; margin:0px; border:1px solid gray; line-height:150%; } div.header,div.footer { padding:0.5em; color:white; background-color:gray; clear:left; } h1.header { padding:0;

Page 37 of 40


Courseware-CSS

margin:0; } div.left { float:left; width:160px; margin:0; padding:1em; } div.content { margin-left:190px; border-left:1px solid gray; padding:1em; } </style> </head> <body> <div class="container"> <div class="header"><h1 class="header">IIHT</h1></div> <div class="left"><p>"Never increase, beyond what is necessary, the number of entities required to explain anything." William of Ockham (12851349)</p></div> <div class="content"> <h2>Free Web Building Tutorials</h2> <p>At W3Schools you will find all the Web-building tutorials you need, from basic HTML and XHTML to advanced XML, XSL, Multimedia and WAP.</p> <p>IIHT is the leading trainer in web designing</p></div> <div class="footer">Copyright of IIHT.</div> </div> </body>

Page 38 of 40


Courseware-CSS

</html>

Make an element hidden and visible <html> <head> <style type="text/css"> h1.visible {visibility:visible} h1.invisible {visibility:hidden} </style> </head> <body> <h1 class="visible">This is a visible heading</h1> <h1 class="invisible">This is an invisible heading</h1> </body> </html>

Change the cursor <html> <body> <p>Move the mouse over the words to see the cursor change:</p> <span style="cursor:crosshair"> Crosshair</span><br /> <span style="cursor:default"> Default</span><br /> <span style="cursor:pointer"> Pointer</span><br /> <span style="cursor:move"> Move</span><br /> <span style="cursor:e-resize"> e-resize</span><br /> <span style="cursor:ne-resize">

Page 39 of 40


Courseware-CSS

ne-resize</span><br /> <span style="cursor:nw-resize"> nw-resize</span><br /> <span style="cursor:n-resize"> n-resize</span><br /> <span style="cursor:se-resize"> se-resize</span><br /> <span style="cursor:sw-resize"> sw-resize</span><br /> <span style="cursor:s-resize"> s-resize</span><br /> <span style="cursor:w-resize"> w-resize</span><br /> <span style="cursor:wait"> wait</span><br /> <span style="cursor:help"> help</span> </body> </html>

Page 40 of 40

CSS  

Cascading style sheet