210 likes | 364 Views
CSS II. Webdesign og Webkommunikation 02.10.2008 IT University of Copenhagen. Goals of the lecture. Revise the basics of CSS Colors and backgrounds Properties of the box model. Revision of CSS. A single style sheet can be used by many XHTML documents. Style sheet. XHTML-document.
E N D
CSS II Webdesign og Webkommunikation 02.10.2008 IT University of Copenhagen
Goals of the lecture • Revise the basics of CSS • Colors and backgrounds • Properties of the box model
Revision of CSS • A single style sheet can be used by many XHTML documents Style sheet XHTML-document XHTML-document XHTML-document
Syntax • CSS • HTML selector {property: value;} Declaration <element attribute=“value”> . . . </element>
Adding styles • 3 ways: • Inline: style added within element tag • Embedded: styles added in the head of the HTML document • External style sheet: separate css document containing all styles <p style=“color: red;”>Text</p> <style> p {color: red;} </style> <link rel=“stylesheet” type=“text/css” href=“styles.css” />
Class and id • class: group similar elements • id: identify a unique element <li class=“menuitem”>CV</li> li.menuitem {font-family: Verdana;} <div id=“header”>…</div> <div id=“menu”>…</div> div#header {background-color: red;} #header {background-color: red;}
Naming the colors • RGB color: • R: 241 = #F1 • G: 21 = #15 • B: 109 = #6D h1 { color: #F1156D; color: rgb(241,21,109); color: rgb(95%, 8%, 43%); color: blue; } 17 colors
Foreground color • Color of text p { border: 2px solid; color: #F1156D; }
Background color p { border: 2px solid; color: #F1156D; background-color: silver; padding: 5px; }
Background image p { border: 2px solid; color: #004A51; background-color: silver; padding: 5px; background-image: url(logo_en.gif); }
Background image II p { border: 2px solid; color: #004A51; background-color: silver; padding: 5px; background-image: url(logo_en.gif); background-repeat: repeat-x; }
Background image III • Text should be readable • Background colour should be similar to the colour of the image
Box model margin padding Content area height width Inner edge Border Outer edge
Width and height I <div id=“tall”>We would like to see as much CSS1 as possible. CSS2 should be limited to widely-supported elements only.</div> <div id=“wide”>We would like to see as much CSS1 as possible. CSS2 should be limited to widely-supported elements only.</div> #tall { width: 200px; height: 300px; } #wide { width: 300px; height: 200px; }
Width and height II • Width and height refer to the dimensions of the content area • Total size: • Margins + borders + paddings + content area • Length: • Pixels, ems, percentage… • Percentages refer to parent element h1 { width: 200px; margin: 10px; padding: 10px; }
Padding h1 { padding-top: 5px; padding-right: 10px; padding-bottom: 15px; padding-left: 20px; } h1 { padding: 5px 10px 15px 20px; } top right bottom left TRouBLe 5px 10px 20px 15px
Border • Style • Width • Color div { border-style: dashed; border-width: 10px; border-color: blue; }
Margin h1 { margin-top: 3px; margin-right: 20px; margin-bottom: 3px; margin-left: 20px; } h1 { margin: 3px 20px 3px 20px; }
Margin II: margin collapse • Vertical margins collapse: only the largest value is used • Horizontal margins never collapse h1.top {margin: 10px 20px 10px 20px;} h1.bottom {margin: 20px 20px 20px 20px;} <h1 class=“top”>Lorem ipsum dolor sit amet,</h1> <h1 class=“bottom”>consectetuer adipiscing elit.</h1>
Final advise • Try your website in different browsers