cascading style sheet

23
Cascading Style Sheet Bayu Priyambadha, S.Kom

Upload: brittania-sellers

Post on 30-Dec-2015

31 views

Category:

Documents


0 download

DESCRIPTION

Cascading Style Sheet. Bayu Priyambadha, S.Kom. Definition. Cascading Style Sheets (CSS) form the presentation layer of the user interface. Structure (HTML ) Behavior (Client-Side Scripting) Presentation (CSS) Tells the browser agent how the element is to be presented to the user. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Cascading Style Sheet

Cascading Style SheetBayu Priyambadha, S.Kom

Page 2: Cascading Style Sheet

Definition• Cascading Style Sheets (CSS) form the

presentation layer of the user interface.– Structure (HTML)– Behavior (Client-Side Scripting)– Presentation (CSS)

• Tells the browser agent how the element is to be presented to the user.

Page 3: Cascading Style Sheet

Why CSS?• CSS removes the presentation attributes from the structure

allowing reusability, ease of maintainability, and an interchangeable presentation layer.

• HTML was never meant to be a presentation language. Proprietary vendors have created tags to add presentation to structure.– <font>– <b>– <i>

• CSS allows us to make global and instantaneous changes easily.

Page 4: Cascading Style Sheet

Using Style Sheets• External Style Sheet

<link href=“stylesheet” type=“text/css” href=“location.css” />

• Embedded Styles<style type=“text/css”>

body {}

</style>

• Inline Styles<p style=“font-size: 12px”>Lorem ipsum</p>

Page 5: Cascading Style Sheet

CSS Syntaxselector/element {

property: value;

}

The selector can either be a grouping of elements, an indentifier, class, or single XHTML element (body, div, etc)

Page 6: Cascading Style Sheet

Type (Element) SelectorSpecify the style(s) for a single XHTML

element.

body { margin: 0; padding: 0; border-top: 1px solid #ff0;}

Page 7: Cascading Style Sheet

Grouping ElementsAllows you to specify a single style for multiple

elements at one time.

h1, h2, h3, h4, h5, h6 { font-family: “Trebuchet MS”, sans-serif;}

Page 8: Cascading Style Sheet

The Class Selector<p class=“intro”>This is my introduction text</p>

.intro { font: 12px verdana, sans-serif; margin: 10px;}

Page 9: Cascading Style Sheet

The Identifier Selector<p id=“intro”> This is my introduction text</p>

#intro { border-bottom: 2px dashed #fff;}

Page 10: Cascading Style Sheet

CSS Selectors• Identifier or class? What’s the difference?

– An identifier is specified only once on a page and has a higher inheritance specificity than a class.

– A class is reusable as many times as needed in a page.

– Use identifiers for main sections and sub-sections of your document.

Page 11: Cascading Style Sheet

CSS Fonts• Font-family• Font-weight• Font-style• Font-size

Page 12: Cascading Style Sheet

CSS Units & Colors• Units

– %– in– cm– mm– em– px – pt

• Colors– color name (red, etc)– rgb(x,x,x)– #rrggbb (HEX)

Page 13: Cascading Style Sheet

CSS Layout• Margin• Padding• Border• Z-index• Positioning• Width• Height• Float• Text-align• Vertical-align

Page 14: Cascading Style Sheet

CSS Text• Text-indent• Text-align• Text-decoration• Letter-spacing• Text-transform• Word-spacing• White-space

Page 15: Cascading Style Sheet

CSS Background• Background-color• Background-image• Background-position• Background-repeat

Page 16: Cascading Style Sheet

CSS Lists• List-style• List-style-image• List-style-position• List-style-type

Page 17: Cascading Style Sheet

CSS Shorthand• Consolidates many styles into a single declaration.

font-family: verdana, sans-serif;font-weight: bold;font-size: 12px;

font: bold 12px verdana, sans-serif;

padding-top: 5px;padding-right: 8px;padding-bottom: 5px;padding-left: 10px;

padding: 5px 8px 5px 10px;

Page 18: Cascading Style Sheet

Example 1

<html><head><style type="text/css">body{

background-color:#b0c4de;}</style></head>

<body>

<h1>My CSS web page!</h1><p>Hello world! This is a W3Schools.com example.</p>

</body></html>

Page 19: Cascading Style Sheet

Example 2<html><head><style type="text/css">body{background-image:url('img_tree.png');background-repeat:no-repeat;background-position:right top;margin-right:200px;}</style></head><body><h1>Hello World!</h1><p>W3Schools background no-repeat, set postion example.</p><p>Now the background image is only show once, and positioned away

from the text.</p><p>In this example we have also added a margin on the right side, so

the background image will never disturb the text.</p></body></html>

Page 20: Cascading Style Sheet

Example 3

<html><head><style type="text/css">body {color:red;}h1 {color:#00ff00;}p.ex {color:rgb(0,0,255);}</style></head>

<body><h1>This is heading 1</h1><p>This is an ordinary paragraph. Notice that this text is red. The

default text-color for a page is defined in the body selector.</p><p class="ex">This is a paragraph with class="ex". This text is

blue.</p></body></html>

Page 21: Cascading Style Sheet

Example 4<html><head><style type="text/css">p.one {border-style:solid;border-width:5px;}p.two {border-style:solid;border-width:medium;}p.three{border-style:solid;border-width:1px;}</style></head>

<body><p class="one">Some text.</p><p class="two">Some text.</p><p class="three">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>

Page 22: Cascading Style Sheet

Example 5

<head><style type="text/css">div.ex{width:220px;padding:10px;border:5px solid gray;margin:0px;}</style></head>

<body><hr /><div class="ex">The line above is 250px wide.<br />The total width of this element is also 250px.</div>

<p><b>Important:</b> This example will not display correctly in IE!<br />

However, we will solve that problem in the next example.</p>

</body></html>

Page 23: Cascading Style Sheet

Questions?