Presentation is loading. Please wait.

Presentation is loading. Please wait.

Cascading Styles Sheets Positioning HTML elements.

Similar presentations


Presentation on theme: "Cascading Styles Sheets Positioning HTML elements."— Presentation transcript:

1 Cascading Styles Sheets Positioning HTML elements

2 The CSS Box Model The CSS Box Model is a crucial building block of CSS-P. Each element in a document is considered to be a rectangular box, as shown below. This box consists of a content area surrounded by padding, a border, and margins.

3

4 CSS Positioning Properties The browsers render elements in the order that they appear in the XHTML source code. Specifying the location of an element on the page –the absolute pixel location, –the location relative to where the element would normally display floating on the page –modify the way an element displays –cause an element to appear partially or completely over another element.

5 Absolute Positioning Absolute positioning is used to specify the location of an element precisely in a browser window. Use the position:absolute property along with either a left, right, and/or top property to configure the placement. Style code example: #content { position: absolute; left: 200px; top: 100px; font-family: Arial, sans-serif; width: 300px; }

6

7 Relative Positioning Relative positioning is used to change the location of an element slightly, relative to where it would otherwise appear in normal flow. Use the position:relative property along with either a left, right, and/or top property.

8 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> CSS - Relative Positioning h1 { background-color: #cccccc; padding: 5px; color: #000000; } #Content { position: relative; left: 30px; font-family: Arial,sans-serif; } Relative Positioning This paragraph uses CSS relative positioning to be placed 30 pixels in on the left side. Using the style in red will make the div below display relative to the h1 above it by moving 30 pixels to the left of the h1.

9

10 Float Property Elements that seem to float on the right or left side of either the browser window or another element are often configured using the float property. The browser renders these element using normal flow, and then shifts them as far as possible within their container. Other content will flow around the float. To stop this flow, use the clear property. #picture { float: right; margin: 0 0 5px 5px; border: solid; } top, right, bottom, left

11 HTML code: Floating an Image The heading and paragraph follow normal flow. The racer pictured on the right is Axel Merckx. He is the son of world famous cyclist Eddy Merckx. This year Axel rides for the T-Mobile team in Germany.

12 Change code to float:left;

13 Change the margins - margin: 0 0 5px 0;

14

15 To clear the effect of a float use the clear property. clear:right; Without the clear property:

16 Clear: right; in style rule for all three images

17 The z-index Property The z-index property is used to modify the stacking order of elements on a Web page. #axel {position:absolute; left:100px; top:100px; width:300px; z-index:1; } #cat {position:absolute; left:160px; top:110px; width:300px; z-index:2; } #parrot {position:absolute; left:220px; top:120px; width:300px; z-index:3; }

18 Position those HTML elements


Download ppt "Cascading Styles Sheets Positioning HTML elements."

Similar presentations


Ads by Google