190 likes | 368 Views
CSS. Chained classes. Julien BRAURE – julien@jazar.co.uk. CSS – Chained classes. What is CSS ? Quick overview Chained classes Examples Conclusion Questions and maybe answers. CSS – Chained classes. What is CSS ?. CSS : Cascading Style Sheet Separate Content and Presentation
E N D
CSS Chained classes Julien BRAURE – julien@jazar.co.uk
CSS – Chained classes • What is CSS ? • Quick overview • Chained classes • Examples • Conclusion • Questions and maybe answers CSS – Chained classes
What is CSS ? • CSS : Cascading Style Sheet • Separate Content and Presentation • Save server load • Reduce maintenance time • Change in the design ? only update the CSS file + = HTML Page 2 HTML Page 1 CSS body { color: #fff; } HTML <html> <body> CSS Page1 ? Page 2 ? CSS – Chained classes
Quick overview HTML <markup class=“class1” id=“this-one” /> CSS markup.class1#this-one { /* here goes the declarations */ color: #f00; border: 1px solid #000; } classes are prefix with a dot (.) id is prefix with a sharp (#) CSS – Chained classes
Chained classes (HTML side) • In HTML the class attribute, may have multiple classes, space separated • <p class=“class1 class2 ... classN”> HTML <p class=“class1”> Loremipsumdolor sit amet. </p> <p class=“class2”> Loremipsumdolor sit amet. </p> <p class=“class1 class2”> Loremipsumdolor sit amet. </p> CSS p.class1{ color: red; } p.class2{ font-weight: bold; } CSS declarations are merging ... This paragraph is red AND bold CSS – Chained classes
Chained classes (CSS side) • In HTML the class attribute, may have multiple classes, space separated • <p class=“class1 class2 ... classN”> HTML <p class=“class1”> Loremipsumdolor sit amet. </p> <p class=“class2”> Loremipsumdolor sit amet. </p> <p class=“class1 class2”> Loremipsumdolor sit amet. </p> CSS p.class1{ color: red; } p.class2{ font-weight: bold; } p.class1.class2{ text-decoration: underline; } CSS declarations are merging ... This paragraph is red, bold AND underlined This declarations only applies to markup with class1 AND class2 • Chained classes : • HTML : space separated • CSS : concatenated CSS – Chained classes
Chained classes (CSS side) • In HTML the class attribute, may have multiple classes, space separated • <p class=“class1 class2 ... classN”> HTML <p class=“class1”> Loremipsumdolor sit amet. </p> <p class=“class2”> Loremipsumdolor sit amet. </p> <p class=“class1 class2”> Loremipsumdolor sit amet. </p> CSS p.class1{ color: red; } p.class2{ font-weight: bold; } p.class1.class2{ text-decoration: underline; color: green; } overwrites CSS – Chained classes
Chained classes – Example 1 Messages: success, error, info CSS – Chained classes
Chained classes - Example HTML CSS <p class=“message success”> Great ! It has been done. </p> <p class=“message error”> Bad luck ! Some error happens. </p> <p class=“message info”> Some important information. </p> p.message { border: 2px solid; padding: 16px 8px 16px 48px; background-repeat: no-repeat; background-position: 8px center; } p.message.success { border-color: green; color: green; background-image: url(img/message.success.gif); } p.message.error { border-color: red; color: red; background-image: url(img/message.error.gif); } p.message.info { border-color: blue; color: blue; background-image: url(img/message.info.gif); } Common declarations CSS – Chained classes
Chained classes – Example 2 - Site wide organisation • Insurance website • Static contents • Faq’s • Legal informations • Some other contents • Dynamic sections • Cars insurance • Houses insurance • Design • Static: • Grey • Dynamic: • Car section: red • House section: blue CSS – Chained classes
Chained classes – Example 2 - Site wide organisation • Basic layout: <div id=“header”> </div> <div class=“page”> <h1>title of the page</h1> <p>some content</p> <p>some content</p> <p>some content</p> </div> <div id=“footer”> </div> CSS – Chained classes
Chained classes – Example 2 - Site wide organisation • Sample sitemap .page .static .dynamic .faq .car #q1 #q2 #step1 #step2 #step1 #step2 ... .legal #tos .house #contact CSS – Chained classes
Chained classes – Example 2 - Site wide organisation • Sample sitemap .page .static .dynamic .faq .car <div class=“page dynamic house” id=“step2”> </div> #q1 #q2 #step2 #step1 #step1 #step2 ... .legal #tos .house #contact CSS – Chained classes
Chained classes – Example 2 - Site wide organisation • Sample sitemap .page .static .dynamic .faq .car #q1 #q2 #step1 #step2 #step1 #step2 ... .legal #tos .house <div class=“page static legal” id=“tos”> </div> #contact CSS – Chained classes
Chained classes – Example 2 - Site wide organisation CSS .page h1 { font-size: 16px; } .page.static h1 { background-color: grey; } .page.dynamic.car h1 { background-color: red; } .page.dynamic.house h1 { background-color: blue; } Common declarations CSS – Chained classes
Chained classes – Example 2 - Site wide organisation .page.dynamic.car.message.success{ background-image: url(img/dynamic/car/message.success.gif); } Customized messages on car pages ? CSS – Chained classes
Conclusion • Real separation between content and presentation • Ability to deploy rapidly alternative design, for Christmas for example • In my HTML: what I want to say • In my CSS: how I want to render it • Avoid presentation related classes in HTML • Eg: bold, small, rounded, ... To keep in mind CSS – Chained classes
Questions ? Any questions ? CSS – Chained classes