stylin
play

Stylin Cascading Style Sheets (CSS) Separate formatting from - PowerPoint PPT Presentation

Stylin Cascading Style Sheets (CSS) Separate formatting from content More flexibly specify HTML formatting Do layout better than vanilla HTML (although still difficult) Use element style instead of: Lots of different


  1. Stylin ’ • Cascading Style Sheets (CSS) – Separate formatting from content – More flexibly specify HTML formatting – Do layout better than vanilla HTML (although still difficult) • Use element style instead of: – Lots of different attributes (align, valign, size, etc) – Lots of inline tags (<b></b>, <em></em>, <font></font> etc) – Tables and frames for visual layout

  2. The sheet part • Inline styles are still messy and should be rare – Fails to separate formatting from content • Internal style sheet, in the <head> <style type=“text/ css ”>…</style> • External style sheet, in the <head> <link rel =“ stylesheet ” type=“text/ css ” href =“style.css” />

  3. Selectors • Style sheet contains style rules – selector { property:value; property:value ; … } • The selector indicates what elements the rule applies to – All elements of a certain type • p { color:blue; } – All elements with a certain id attribute • #myid { text-align:center; } – All elements with a certain class attribute • .myclass { text-align:right; } – Mix-and-match type, class and id • p.myclass { color:yellow; }

  4. Selectors • More advanced selectors: – Matching multiple selectors • p, div, h1 – Matching elements that are inside other matching elements • p.calendar ul { padding-right: 10px; } – Matching elements that are direct children of other matching elements • p.calendar>ul>li { font-weight: bold; } – Elements with a certain attribute value • a[title=portrait] • Plenty of references are out there, e.g.: – http://www.w3schools.com/cssref/css_selectors.asp

  5. The cascading part • Multiple sheets can be used – Multiple rules may apply to the same element – Those rules may have conflicting property values – Conflicts are resolved in the order sheets are included in the HTML file • Inline styles always win, so they are used for exceptions

  6. Inline styles <body bgcolor =“red”> vs. <body style=“background -color:red ”> <font size=“4”></font> vs. <p style=“font - size:20px”></p> Bunch of <table> tags vs. <div style=“ position:fixed ; top:50px; right: 100px”> </div>

  7. All the styles you could want • http://www.w3schools.com/css/default.asp • Notable properties: – visibility:hidden • The element isn’t shown, but it still takes up space – display:block • Has line breaks before and after it, like <p> – display:inline • No line breaks, only takes up the space it needs, like <a> – display:none • The element isn’t shown, and takes up no space at all – position:static/fixed/relative/absolute • Static is normal HTML flow, the others allow different layouts • Modified by top/left/right/bottom properties

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend