SlideShare uma empresa Scribd logo
1 de 60
CSS Technieken Toegelicht Robin Poort (@rhcpoort) Owner Tweepixels Webdesign (@tweepixels) PFCongres, September 2011
Robin Poort Follow me on Twitter: @rhcpoort and @tweepixels
A Solid Foundation Reset Frameworks Cheatsheets Shorthand Specificity Clear & Clearfix Commenting
Source: http://www.addedbytes.com/cheat-sheets/css-cheat-sheet/
Source: http://meyerweb.com/eric/tools/css/reset/
Source: http://960.gs/demo.html
<div  class= ” clear ” ></div> & <div  class= ” clearfix ” ></div>
HTML markup <div  class= ” wrapper ” > Lorem ipsum <div  class= ” floatbox ” > Floating box </div> </div> Result CSS .wrapper  { background : #FFF; border : 5px solid #29BDBD; margin :   10px; padding : 10px; } .floatbox  { background : #FFF; border : 5px solid #333; padding : 10px; float :   right; }
HTML markup <div  class= ” wrapper ” > Lorem ipsum <div  class= ” floatbox ” > Floating box </div> <div  class= ” clear ” ></div> </div> Result CSS  (in 960 grid system) .clear  { clear : both; display : block; overflow :   hidden; visibility : hidden; width : 0; height : 0; }
HTML markup <div  class= ” wrapper clearfix ” > Lorem ipsum <div  class= ” floatbox ” > Floating box </div> </div> Result CSS  (in 960 grid system) .clearfix:before,.clearfix:after  {   content :  '020' ; display : block; overflow : hidden; visibility : hidden; width : 0; height : 0; } .clearfix:after  { clear : both;} .clearfix  { zoom : 1;} Most frameworks come with built-in clear & clearfix classes.
div.example  { background-color : #FFFFFF; background-image :  url(img.png) ; background-position : left top; background-repeat : repeat-x; border-width : 1px; border-style : solid; border-color : #000000; margin-top : 10px; margin-right : 10px; margin-bottom : 10px; margin-left : 10px padding-top : 10px; padding-right : 15px; padding-bottom : 20px; padding-left : 15px; } div.example2  { font-family : Arial, sans-serif; font-size : 12px; line-height : 1.5em; font-weight : bold; font-style : italic; font-variant : small-caps; list-style-type : disc; list-style-position : inside; list-style-image :  url(img.png) ; }
div.example  { background : #FFFFFF  url(example.png)  left top repeat-x; border : 1px solid #000000; margin :   10px; padding : 10px 15px 20px; } div.example2  { font : bold italic small-caps 1em/1.5em Arial,sans-serif; list-style : disc inside  url(example.png) ; } When using shorthand CSS make sure you use the correct order for the values.
Source: http://www.stuffandnonsense.co.uk/archives/css_specificity_wars.html
*  {}  /* a=0 b=0 c=0 d=0 -> specificity = 0,0,0,0 */ li  {}  /* a=0 b=0 c=0 d=1 -> specificity = 0,0,0,1 */ li:first-line  {}  /* a=0 b=0 c=0 d=2 -> specificity = 0,0,0,2 */ ul li  {}  /* a=0 b=0 c=0 d=2 -> specificity = 0,0,0,2 */ ul ol+li  {}  /* a=0 b=0 c=0 d=3 -> specificity = 0,0,0,3 */ h1 + *[rel=up]  {}  /* a=0 b=0 c=1 d=1 -> specificity = 0,0,1,1 */ ul ol li.red  {}  /* a=0 b=0 c=1 d=3 -> specificity = 0,0,1,3 */ li.red.level  {}  /* a=0 b=0 c=2 d=1 -> specificity = 0,0,2,1 */ #x34y  {}  /* a=0 b=1 c=0 d=0 -> specificity = 0,1,0,0 */ style= &quot;&quot;   /* a=1 b=0 c=0 d=0 -> specificity = 1,0,0,0 */ Source: http://www.w3.org/TR/CSS2/cascade.html
!important
.example   { color :   red  !important } Overrules <div  class= ” example ”  style= ” color : blue; ” > Using !important might confuse you or other developers later. Use with caution!
Commenting ,[object Object],[object Object],[object Object],/* As headers */ h3  { font-size : 1em;} H3  { font-size : 1em;  /* Just this line */ color : red; }
Good to Know Class stacking .class.class Floating & position: absolute CSS selectors #id.class
HTML markup <div  class= ” container ” > <div  class= ” absolute ” > Absolute </div> <div  class= ” floatbox ” > Floating box </div> <div  class= ” clear ” ></div> </div> Result in IE7 CSS .container  {  position : relative; z-index : 1; } .absolute  { right : 10px; position : absolute; top : 10px; z-index : 2; } .floatbox  { float : left; }
HTML markup <div  class= ” container ” > <div> <div  class= ” absolute ” > Absolute </div> </div> <div  class= ” floatbox ” > Floating box </div> <div  class= ” clear ” ></div> </div> Result CSS .container  {  position : relative; z-index : 1; } .absolute  { right : 10px; position : absolute; top : 10px; z-index : 2; } .floatbox  { float : left; }
HTML markup <div  class= ” container ” > <div  class= ” IE-div ” > <div  class= ” absolute ” > Absolute </div> </div> <div  class= ” floatbox ” > Floating box </div> <div  class= ” clear ” ></div> </div> Result CSS .container  {  position : relative; z-index : 1; } .absolute  { right : 10px; position : absolute; top : 10px; z-index : 2; } .floatbox  { float : left; }
<div  class= ” class stacking ” ></div>
HTML markup <div  class= ” blockBigBoldRed ” > Example </div> <div  class= ” blockBigBlue ” > Example </div> Result CSS .blockBigBoldRed  { background : #FFFFFF; border : 1px solid #CCCCCC; margin :   10px; padding : 10px; font-size : 2em; color : red; font-weight : bold; } .blockBigBlue  { background : #FFFFFF; border : 1px solid #CCCCCC; margin :   10px; padding : 10px; font-size : 2em; color : blue; }
HTML markup <div  class= ” block ” > <div  class= ” bigFont ” > <div  class= ” boldFont ” > <div  class= ” redFont ” > Example </div> </div> </div> </div> <div  class= ” block ” > <div  class= ” bigFont ” > <div  class= ” blueFont ” > Example </div> </div> </div> CSS .block  { background : #FFFFFF; border : 1px solid #CCCCCC; margin :   10px; padding : 10px; } .bigFont  { font-size : 2em;} .redFont  { color : red;} .blueFont  { color : blue;} .boldFont  { font-weight : bold;} Result
HTML markup <div  class= ” block bigFont boldFont redFont ” > Example </div> <div  class= ” block bigFont blueFont ” > Example </div> Result CSS .block  { background : #FFFFFF; border : 1px solid #CCCCCC; margin :   10px; padding : 10px; } .bigFont  { font-size : 2em;} .redFont  { color : red;} .blueFont  { color : blue;} .boldFont  { font-weight : bold;} Make sure you divide all classes in the markup with spaces.
.class.class
HTML markup <div  class= ” block bigFont redFont ” > Example <div  class= ” caption redFont ” > Example </div> </div> Result CSS .block  { background : #FFFFFF; border : 1px solid #CCCCCC; margin :   10px; padding : 10px; } .bigFont  { font-size : 2em;} .redFont  { color : red;} .caption  { background : #CCC; padding : 10px; }
HTML markup <div  class= ” block bigFont redFont ” > Example <div  class= ” caption redFont ” > Example </div> </div> Resultaat CSS .block  { background : #FFFFFF; border : 1px solid #CCCCCC; margin :   10px; padding : 10px; } .bigFont  { font-size : 2em;} .redFont  { color : red;} .caption  { background : #CCC; padding : 10px; } .caption.redFont  { color : darkred;} There are spaces between classes in the markup but not in your CSS file.
#id.class
HTML markup <div  id= ” bar1 ”   class= ” grid_4 ” > Example </div> <div  id= ” bar2 ”   class= ” grid_4 ” > Example </div> <div  id= ” bar3 ”   class= ” grid_4 ” > Example </div> CSS .grid_4  { display : inline; float : left; margin-left : 10px; margin-right : 10px; position : relative; width:  300px; }
HTML markup <div  id= ” bar1 ”   class= ” grid_4 ” > Example </div> <div  id= ” bar2 ”   class= ” grid_4 ” > Example </div> <div  id= ” bar3 ”   class= ” grid_4 ” > Example </div> CSS .grid_4  { display : inline; float : left; margin-left : 10px; margin-right : 10px; position : relative; } #bar1.grid_4  { margin-left : 0;} #bar3.grid_4  { margin-right : 0;}
Very useful CSS selectors E F Matches any F element that is a descendant of an E  element. E > F Matches any F element that is a child of an element E. E + F Matches any F element immediately preceded by a  sibling element E. E:first-child Matches element E when E is the first child of its  parent. E[foo] Matches any E element with the &quot;foo&quot; attribute set  (whatever the value). E[foo=&quot;warn&quot;] Matches any E element whose &quot;foo&quot; attribute value is  exactly equal to &quot;warn&quot;. E[foo~=&quot;warn&quot;] Matches any E element whose &quot;foo&quot; attribute value is a  list of space-separated values, one of which is  exactly equal to &quot;warn&quot;. Source: http://www.w3.org/TR/CSS2/selector.html
E > F HTML markup <div  class= ” blog ” > <p> Introduction </p> <div  class= ” story ” > <p> Lorem ipsum dolor </p> <div  class= ” date ” > <p> Date </p> </div> </div> </div> CSS .blog p  { font-family : Arial, sans-serif; font-size : 1em; color : #555; } .story p  { font-size : 1.3em; color : #111; }
E > F HTML markup <div  class= ” blog ” > <p> Introduction </p> <div  class= ” story ” > <p> Lorem ipsum dolor </p> <div  class= ” date ” > <p> Date </p> </div> </div> </div> CSS .blog p  { font-family : Arial, sans-serif; font-size : 1em; color : #555; } .story > p  { font-size : 1.3em; color : #111; }
E + F HTML markup <div  class= ” blog ” > <h1> Title </h1> <h2> Subtitle </h2> <h2> Subtitle </h2> <p> Lorem ipsum </p> <h2> Subtitle </h2> <p> Lorem ipsum </p> </div> CSS h1  { margin : 0 0 1em 0; font-size : 2em; } h2  { margin : 0 0 .5em 0; font-size : 1.4em; color : #000; }
E + F HTML markup <div  class= ” blog ” > <h1> Title </h1> <h2> Subtitle </h2> <h2> Subtitle </h2> <p> Lorem ipsum </p> <h2> Subtitle </h2> <p> Lorem ipsum </p> </div> CSS h1  { margin : 0 0 1em 0; font-size : 2em; } h2  { margin : 0 0 .5em 0; font-size : 1.4em; color : #000; } h1 + h2  { margin-top : -1em; font-style : italic; }
E:first-child HTML markup <div  class= ” blog ” > <h1> Title </h1> <p> Lorem ipsum </p> <p> Lorem ipsum </p> </div> CSS h1  { margin : 0 0 1em 0; font-size : 2em; color : #222; } p  {  color : #444; margin-bottom : 1em; } .blog p:first-child  { font-family : serif; font-style : italic; color : #000; }
E:first-child HTML markup <div  class= ” blog ” > <h1> Title </h1> <div  class= ” story ” > <p> Lorem ipsum </p> <p> Lorem ipsum </p> </div> </div> CSS h1  { margin : 0 0 1em 0; font-size : 2em; color : #222; } p  {  color : #444; margin-bottom : 1em; } .story p:first-child  { font-family : serif; font-style : italic; color : #000; }
E[foo=&quot;warn&quot;] HTML markup <label> Name </label><br /> <input  type= &quot;text&quot;  /> <label> Gender </label><br /> <label> <input  type= &quot;radio&quot;  /> Man </label> <label> <input  type= &quot;radio&quot;  /> Woman </label> CSS input[type=&quot;text&quot;]  { width : 200px; border : 1px solid #CCC; background : #F5F5F5; padding : 5px; } input[type=&quot;radio&quot;]  { margin-left : 1em; }
CSS in use Attribute Styling Drop Caps Google Fonts Styling Images
Source: http://www.google.com/webfonts?subset=latin&sort=pop
HTML markup <!-- place in <head> section --> <link  href= ”http://fonts.googleapis.com/css?family=Yanone+Kaffeesatz|Ubuntu”  rel= ”stylesheet”  type= ”text/css”  /> <!-- place in </head> section --> <h1> Title </h1> <p> The quick brown fox jumps over the lazy dog. </p> CSS h1  { font-family :  'Yanone Kaffeesatz' , arial, serif;} p  { font-family :  'Ubuntu' , arial, serif;} Don't use too many Google Fonts at the same page because MSIE can't handle that.
 
 
HTML markup <ul> <li><a  class= ” doc-icon ”   href= &quot;test.doc&quot; > Lorem ipsum dolor </a></li> <li><a  class= ” pdf-icon ”   href= &quot;test.pdf&quot; > Sit amet consect </a></li> <li><a  class= ” xls-icon ”   href= &quot;test.xls&quot; > Lorem ipsum dolor </a></li> <li><a  class= ” png-icon ”   href= &quot;test.png&quot; > Sit amet consectet </a></li> </ul> CSS li a.doc-icon  { background :  url(doc.gif)  no-repeat; } li a.pdf-icon  { background :  url(pdf.gif)  no-repeat; } li a.xls-icon  { background :  url(xls.gif)  no-repeat; } li a.png-icon  { background :  url(png.gif)  no-repeat; }
HTML markup <ul> <li><a  href= &quot;test.doc&quot; > Lorem ipsum dolor </a></li> <li><a  href= &quot;test.pdf&quot; > Sit amet consectetuer </a></li> <li><a  href= &quot;test.xls&quot; > Lorem ipsum dolor </a></li> <li><a  href= &quot;test.png&quot; > Sit amet consectetuer </a></li> </ul> <ul> <li><a  href= &quot;http://twitter.com/finishjoomla&quot; > Twitter </a></li> <li><a  href= &quot;http://www.facebook.com/profile.php&quot; > Facebook </a></li> <li><a  href= &quot;http://www.linkedin.com/company/&quot; > Linkedin </a></li> <li><a  href= &quot;http://www.youtube.com/user/&quot; > Youtube </a></li> </ul>
CSS li a[href$='.doc'] , li a[href$='.pdf'] , li a[href$='.xls'] , li a[href$='.png'] , li a[href*='twitter.com'] , li a[href*='facebook.com'] , li a[href*='linkedin.com'] , li a[href*='youtube.com']  { padding-left :40px; min-height :24px; display :inline-block; line-height :24px; } This won't work on IE6 and only on IE7+ when a Doctype is declared.
CSS li a[href$='.doc']  { background :  url(doc.gif)  no-repeat; } li a[href$='.pdf']  { background :  url(pdf.gif)  no-repeat; } li a[href$='.xls']  { background :  url(xls.gif)  no-repeat; } li a[href$='.png']  { background :  url(png.gif)  no-repeat; } li a[href*='twitter.com']  { background :  url(twitter.gif)  no-repeat; } li a[href*='facebook.com']  { background :  url(facebook.gif)  no-repeat; } li a[href*='linkedin.com']  { background :  url(linkedin.gif)  no-repeat; } li a[href*='youtube.com']  { background :  url(youtube.gif)  no-repeat; } This won't work on IE6 and only on IE7+ when a Doctype is declared.
 
HTML markup <p> <span  class= ” dropcap ” > L </span> orem ipsum dolor sit amet,  consectetur adipiscing elit... </p> CSS p  { font-family : Arial, sans-serif;} span.dropcap  { font-size : 3em; color : #29BDBD; float : left; margin : 10px 10px 0 0; display : block; }
HTML markup <p  class= ” dropcap ” > Lorem ipsum dolor sit amet, consectetur adipiscing elit... </p> CSS p.dropcap  { font-family : Arial, sans-serif;} p.dropcap:first-letter  { font-size : 3em; color : #29BDBD; float : left; margin : 10px 10px 0 0; } This won't work on IE6 and only on IE7+ when a Doctype is declared.
HTML markup <p  class= ” dropcap ” > Lorem ipsum dolor sit amet, consectetur adipiscing elit... </p> CSS p.dropcap  { font-family :  'Old Standard TT' , Times, serif;} p.dropcap:first-letter  { font-family :  'UnifrakturMaguntia' , Times, serif; font-size : 3em; color : #29BDBD; float : left; margin : 10px 10px 0 0; }
 
 
HTML markup <img  class= ” img1 ”   src= ”image.png”   alt= ” image ”  /> CSS img.img1  { background : #FFF; padding : 2px; border : 2px solid #AAA; }
HTML markup <img  class= ” img2 ”   src= ”image.png”   alt= ” image ”  /> CSS img.img2  { background :  url(seamless.png) ; padding : 4px; } Make sure the background image is a seamless pattern.
HTML markup <img  class= ” img3 ”   src= ”image.png”   alt= ” image ”  /> CSS img.img3  { background :  url(seamless.png) ; padding : 3px; border : 1px solid #000; }
HTML markup <img  class= ” img4 ”   src= ”image.png”   alt= ” image ”  /> CSS img.img4  { background : #000; padding : 1px; border : 2px solid #FFF; outline : 1px solid #AAA; } The outline property is not supported by IE6 and IE7.
Questions?
@rhcpoort Robin Poort [email_address] @tweepixels

Mais conteúdo relacionado

Mais procurados

Johny coba dulu
Johny coba duluJohny coba dulu
Johny coba dulusipali
 
Database Related Comboboxes
Database Related ComboboxesDatabase Related Comboboxes
Database Related Comboboxesozlemyavuz
 
Xml version pakfaizal dot com free download
Xml version pakfaizal dot com free downloadXml version pakfaizal dot com free download
Xml version pakfaizal dot com free downloadFaisal Pak
 
Professional Web Development
Professional Web DevelopmentProfessional Web Development
Professional Web DevelopmentJoseph Chiang
 
Xml Xls ed Excel per la produzione espressa di Html - Chiara Bettaglio
Xml Xls ed Excel per la produzione espressa di Html - Chiara BettaglioXml Xls ed Excel per la produzione espressa di Html - Chiara Bettaglio
Xml Xls ed Excel per la produzione espressa di Html - Chiara BettaglioGirl Geek Dinners Milano
 
Thinking about CSS Architecture
Thinking about CSS ArchitectureThinking about CSS Architecture
Thinking about CSS Architecture拓樹 谷
 
JustJava2008 Facelets
JustJava2008 FaceletsJustJava2008 Facelets
JustJava2008 FaceletsDr. Spock
 
Folleto de daniela cantillo (1)
Folleto de daniela cantillo (1)Folleto de daniela cantillo (1)
Folleto de daniela cantillo (1)danielacantillo
 
XML em Aplicações e-Business
XML em Aplicações e-BusinessXML em Aplicações e-Business
XML em Aplicações e-Businesselliando dias
 
メンテナブルでありつづけるためのCSS設計
メンテナブルでありつづけるためのCSS設計メンテナブルでありつづけるためのCSS設計
メンテナブルでありつづけるためのCSS設計拓樹 谷
 
CSS設計の理想と現実
CSS設計の理想と現実CSS設計の理想と現実
CSS設計の理想と現実拓樹 谷
 
CSS Components
CSS ComponentsCSS Components
CSS Components拓樹 谷
 
Exemplos Aula2
Exemplos Aula2Exemplos Aula2
Exemplos Aula2softeam
 
Doctype html publi1
Doctype html publi1Doctype html publi1
Doctype html publi1Eddy_TKJ
 

Mais procurados (20)

Hyper Text Markup Language
Hyper Text Markup LanguageHyper Text Markup Language
Hyper Text Markup Language
 
Johny coba dulu
Johny coba duluJohny coba dulu
Johny coba dulu
 
Database Related Comboboxes
Database Related ComboboxesDatabase Related Comboboxes
Database Related Comboboxes
 
Creación aplicación Web base struts2
Creación aplicación Web base struts2Creación aplicación Web base struts2
Creación aplicación Web base struts2
 
Xml version pakfaizal dot com free download
Xml version pakfaizal dot com free downloadXml version pakfaizal dot com free download
Xml version pakfaizal dot com free download
 
Ph pmysql
Ph pmysqlPh pmysql
Ph pmysql
 
Professional Web Development
Professional Web DevelopmentProfessional Web Development
Professional Web Development
 
Xml Xls ed Excel per la produzione espressa di Html - Chiara Bettaglio
Xml Xls ed Excel per la produzione espressa di Html - Chiara BettaglioXml Xls ed Excel per la produzione espressa di Html - Chiara Bettaglio
Xml Xls ed Excel per la produzione espressa di Html - Chiara Bettaglio
 
Thinking about CSS Architecture
Thinking about CSS ArchitectureThinking about CSS Architecture
Thinking about CSS Architecture
 
JustJava2008 Facelets
JustJava2008 FaceletsJustJava2008 Facelets
JustJava2008 Facelets
 
Folleto de daniela cantillo (1)
Folleto de daniela cantillo (1)Folleto de daniela cantillo (1)
Folleto de daniela cantillo (1)
 
XML em Aplicações e-Business
XML em Aplicações e-BusinessXML em Aplicações e-Business
XML em Aplicações e-Business
 
メンテナブルでありつづけるためのCSS設計
メンテナブルでありつづけるためのCSS設計メンテナブルでありつづけるためのCSS設計
メンテナブルでありつづけるためのCSS設計
 
Html5
Html5Html5
Html5
 
CSS設計の理想と現実
CSS設計の理想と現実CSS設計の理想と現実
CSS設計の理想と現実
 
CSS Components
CSS ComponentsCSS Components
CSS Components
 
Exemplos Aula2
Exemplos Aula2Exemplos Aula2
Exemplos Aula2
 
Why Sass?
Why Sass?Why Sass?
Why Sass?
 
Johny see book update
Johny see book updateJohny see book update
Johny see book update
 
Doctype html publi1
Doctype html publi1Doctype html publi1
Doctype html publi1
 

Destaque

Mba724 s2 w2 spss intro & daya types
Mba724 s2 w2 spss intro & daya typesMba724 s2 w2 spss intro & daya types
Mba724 s2 w2 spss intro & daya typesRachel Chung
 
Tru definition™ duration® черепица
Tru definition™ duration® черепицаTru definition™ duration® черепица
Tru definition™ duration® черепицаtrav-ve
 
Jews and the Comic Book
Jews and the Comic BookJews and the Comic Book
Jews and the Comic Bookabholtz
 
二制圖34潘品諺(2011.9.1上傳)
二制圖34潘品諺(2011.9.1上傳)二制圖34潘品諺(2011.9.1上傳)
二制圖34潘品諺(2011.9.1上傳)Yan Pin
 
Is it worth it just to lower my rate by a half of percent
Is it worth it just to lower my rate by a half of percentIs it worth it just to lower my rate by a half of percent
Is it worth it just to lower my rate by a half of percentClint Hammond
 
Ig2 assignment brief_updated_27.04.12
Ig2 assignment brief_updated_27.04.12Ig2 assignment brief_updated_27.04.12
Ig2 assignment brief_updated_27.04.12FirstClassProductions
 
Back to school2010 final
Back to school2010 finalBack to school2010 final
Back to school2010 finallaurieao
 
Triumph Classic Motor Onno Ruttenberg
Triumph Classic Motor Onno RuttenbergTriumph Classic Motor Onno Ruttenberg
Triumph Classic Motor Onno Ruttenbergorut
 
02 บทที่ 2-เอกสารที่เกี่ยวข้อง
02 บทที่ 2-เอกสารที่เกี่ยวข้อง02 บทที่ 2-เอกสารที่เกี่ยวข้อง
02 บทที่ 2-เอกสารที่เกี่ยวข้องChalita Vitamilkz
 
Mba724 s3 w2 central tendency & dispersion (chung)
Mba724 s3 w2   central tendency & dispersion (chung)Mba724 s3 w2   central tendency & dispersion (chung)
Mba724 s3 w2 central tendency & dispersion (chung)Rachel Chung
 
Tourism English 3
Tourism English 3Tourism English 3
Tourism English 3Les Davy
 

Destaque (20)

Mba724 s2 w2 spss intro & daya types
Mba724 s2 w2 spss intro & daya typesMba724 s2 w2 spss intro & daya types
Mba724 s2 w2 spss intro & daya types
 
Tru definition™ duration® черепица
Tru definition™ duration® черепицаTru definition™ duration® черепица
Tru definition™ duration® черепица
 
 
Sunu3
Sunu3Sunu3
Sunu3
 
Cooll usersguide 0
Cooll usersguide 0Cooll usersguide 0
Cooll usersguide 0
 
Tarea verbos
Tarea verbosTarea verbos
Tarea verbos
 
Processor CPU
Processor CPUProcessor CPU
Processor CPU
 
Jews and the Comic Book
Jews and the Comic BookJews and the Comic Book
Jews and the Comic Book
 
1 4
1 41 4
1 4
 
二制圖34潘品諺(2011.9.1上傳)
二制圖34潘品諺(2011.9.1上傳)二制圖34潘品諺(2011.9.1上傳)
二制圖34潘品諺(2011.9.1上傳)
 
Diablo keystone
Diablo keystoneDiablo keystone
Diablo keystone
 
Is it worth it just to lower my rate by a half of percent
Is it worth it just to lower my rate by a half of percentIs it worth it just to lower my rate by a half of percent
Is it worth it just to lower my rate by a half of percent
 
Ig2 assignment brief_updated_27.04.12
Ig2 assignment brief_updated_27.04.12Ig2 assignment brief_updated_27.04.12
Ig2 assignment brief_updated_27.04.12
 
Back to school2010 final
Back to school2010 finalBack to school2010 final
Back to school2010 final
 
Triumph Classic Motor Onno Ruttenberg
Triumph Classic Motor Onno RuttenbergTriumph Classic Motor Onno Ruttenberg
Triumph Classic Motor Onno Ruttenberg
 
Photo album
Photo albumPhoto album
Photo album
 
Slide 1
Slide  1Slide  1
Slide 1
 
02 บทที่ 2-เอกสารที่เกี่ยวข้อง
02 บทที่ 2-เอกสารที่เกี่ยวข้อง02 บทที่ 2-เอกสารที่เกี่ยวข้อง
02 บทที่ 2-เอกสารที่เกี่ยวข้อง
 
Mba724 s3 w2 central tendency & dispersion (chung)
Mba724 s3 w2   central tendency & dispersion (chung)Mba724 s3 w2   central tendency & dispersion (chung)
Mba724 s3 w2 central tendency & dispersion (chung)
 
Tourism English 3
Tourism English 3Tourism English 3
Tourism English 3
 

CSS Technieken Toegelicht

  • 1. CSS Technieken Toegelicht Robin Poort (@rhcpoort) Owner Tweepixels Webdesign (@tweepixels) PFCongres, September 2011
  • 2. Robin Poort Follow me on Twitter: @rhcpoort and @tweepixels
  • 3. A Solid Foundation Reset Frameworks Cheatsheets Shorthand Specificity Clear & Clearfix Commenting
  • 7. <div class= ” clear ” ></div> & <div class= ” clearfix ” ></div>
  • 8. HTML markup <div class= ” wrapper ” > Lorem ipsum <div class= ” floatbox ” > Floating box </div> </div> Result CSS .wrapper { background : #FFF; border : 5px solid #29BDBD; margin : 10px; padding : 10px; } .floatbox { background : #FFF; border : 5px solid #333; padding : 10px; float : right; }
  • 9. HTML markup <div class= ” wrapper ” > Lorem ipsum <div class= ” floatbox ” > Floating box </div> <div class= ” clear ” ></div> </div> Result CSS (in 960 grid system) .clear { clear : both; display : block; overflow : hidden; visibility : hidden; width : 0; height : 0; }
  • 10. HTML markup <div class= ” wrapper clearfix ” > Lorem ipsum <div class= ” floatbox ” > Floating box </div> </div> Result CSS (in 960 grid system) .clearfix:before,.clearfix:after { content : '020' ; display : block; overflow : hidden; visibility : hidden; width : 0; height : 0; } .clearfix:after { clear : both;} .clearfix { zoom : 1;} Most frameworks come with built-in clear & clearfix classes.
  • 11. div.example { background-color : #FFFFFF; background-image : url(img.png) ; background-position : left top; background-repeat : repeat-x; border-width : 1px; border-style : solid; border-color : #000000; margin-top : 10px; margin-right : 10px; margin-bottom : 10px; margin-left : 10px padding-top : 10px; padding-right : 15px; padding-bottom : 20px; padding-left : 15px; } div.example2 { font-family : Arial, sans-serif; font-size : 12px; line-height : 1.5em; font-weight : bold; font-style : italic; font-variant : small-caps; list-style-type : disc; list-style-position : inside; list-style-image : url(img.png) ; }
  • 12. div.example { background : #FFFFFF url(example.png) left top repeat-x; border : 1px solid #000000; margin : 10px; padding : 10px 15px 20px; } div.example2 { font : bold italic small-caps 1em/1.5em Arial,sans-serif; list-style : disc inside url(example.png) ; } When using shorthand CSS make sure you use the correct order for the values.
  • 14. * {} /* a=0 b=0 c=0 d=0 -> specificity = 0,0,0,0 */ li {} /* a=0 b=0 c=0 d=1 -> specificity = 0,0,0,1 */ li:first-line {} /* a=0 b=0 c=0 d=2 -> specificity = 0,0,0,2 */ ul li {} /* a=0 b=0 c=0 d=2 -> specificity = 0,0,0,2 */ ul ol+li {} /* a=0 b=0 c=0 d=3 -> specificity = 0,0,0,3 */ h1 + *[rel=up] {} /* a=0 b=0 c=1 d=1 -> specificity = 0,0,1,1 */ ul ol li.red {} /* a=0 b=0 c=1 d=3 -> specificity = 0,0,1,3 */ li.red.level {} /* a=0 b=0 c=2 d=1 -> specificity = 0,0,2,1 */ #x34y {} /* a=0 b=1 c=0 d=0 -> specificity = 0,1,0,0 */ style= &quot;&quot; /* a=1 b=0 c=0 d=0 -> specificity = 1,0,0,0 */ Source: http://www.w3.org/TR/CSS2/cascade.html
  • 16. .example { color : red !important } Overrules <div class= ” example ” style= ” color : blue; ” > Using !important might confuse you or other developers later. Use with caution!
  • 17.
  • 18. Good to Know Class stacking .class.class Floating & position: absolute CSS selectors #id.class
  • 19. HTML markup <div class= ” container ” > <div class= ” absolute ” > Absolute </div> <div class= ” floatbox ” > Floating box </div> <div class= ” clear ” ></div> </div> Result in IE7 CSS .container { position : relative; z-index : 1; } .absolute { right : 10px; position : absolute; top : 10px; z-index : 2; } .floatbox { float : left; }
  • 20. HTML markup <div class= ” container ” > <div> <div class= ” absolute ” > Absolute </div> </div> <div class= ” floatbox ” > Floating box </div> <div class= ” clear ” ></div> </div> Result CSS .container { position : relative; z-index : 1; } .absolute { right : 10px; position : absolute; top : 10px; z-index : 2; } .floatbox { float : left; }
  • 21. HTML markup <div class= ” container ” > <div class= ” IE-div ” > <div class= ” absolute ” > Absolute </div> </div> <div class= ” floatbox ” > Floating box </div> <div class= ” clear ” ></div> </div> Result CSS .container { position : relative; z-index : 1; } .absolute { right : 10px; position : absolute; top : 10px; z-index : 2; } .floatbox { float : left; }
  • 22. <div class= ” class stacking ” ></div>
  • 23. HTML markup <div class= ” blockBigBoldRed ” > Example </div> <div class= ” blockBigBlue ” > Example </div> Result CSS .blockBigBoldRed { background : #FFFFFF; border : 1px solid #CCCCCC; margin : 10px; padding : 10px; font-size : 2em; color : red; font-weight : bold; } .blockBigBlue { background : #FFFFFF; border : 1px solid #CCCCCC; margin : 10px; padding : 10px; font-size : 2em; color : blue; }
  • 24. HTML markup <div class= ” block ” > <div class= ” bigFont ” > <div class= ” boldFont ” > <div class= ” redFont ” > Example </div> </div> </div> </div> <div class= ” block ” > <div class= ” bigFont ” > <div class= ” blueFont ” > Example </div> </div> </div> CSS .block { background : #FFFFFF; border : 1px solid #CCCCCC; margin : 10px; padding : 10px; } .bigFont { font-size : 2em;} .redFont { color : red;} .blueFont { color : blue;} .boldFont { font-weight : bold;} Result
  • 25. HTML markup <div class= ” block bigFont boldFont redFont ” > Example </div> <div class= ” block bigFont blueFont ” > Example </div> Result CSS .block { background : #FFFFFF; border : 1px solid #CCCCCC; margin : 10px; padding : 10px; } .bigFont { font-size : 2em;} .redFont { color : red;} .blueFont { color : blue;} .boldFont { font-weight : bold;} Make sure you divide all classes in the markup with spaces.
  • 27. HTML markup <div class= ” block bigFont redFont ” > Example <div class= ” caption redFont ” > Example </div> </div> Result CSS .block { background : #FFFFFF; border : 1px solid #CCCCCC; margin : 10px; padding : 10px; } .bigFont { font-size : 2em;} .redFont { color : red;} .caption { background : #CCC; padding : 10px; }
  • 28. HTML markup <div class= ” block bigFont redFont ” > Example <div class= ” caption redFont ” > Example </div> </div> Resultaat CSS .block { background : #FFFFFF; border : 1px solid #CCCCCC; margin : 10px; padding : 10px; } .bigFont { font-size : 2em;} .redFont { color : red;} .caption { background : #CCC; padding : 10px; } .caption.redFont { color : darkred;} There are spaces between classes in the markup but not in your CSS file.
  • 30. HTML markup <div id= ” bar1 ” class= ” grid_4 ” > Example </div> <div id= ” bar2 ” class= ” grid_4 ” > Example </div> <div id= ” bar3 ” class= ” grid_4 ” > Example </div> CSS .grid_4 { display : inline; float : left; margin-left : 10px; margin-right : 10px; position : relative; width: 300px; }
  • 31. HTML markup <div id= ” bar1 ” class= ” grid_4 ” > Example </div> <div id= ” bar2 ” class= ” grid_4 ” > Example </div> <div id= ” bar3 ” class= ” grid_4 ” > Example </div> CSS .grid_4 { display : inline; float : left; margin-left : 10px; margin-right : 10px; position : relative; } #bar1.grid_4 { margin-left : 0;} #bar3.grid_4 { margin-right : 0;}
  • 32. Very useful CSS selectors E F Matches any F element that is a descendant of an E element. E > F Matches any F element that is a child of an element E. E + F Matches any F element immediately preceded by a sibling element E. E:first-child Matches element E when E is the first child of its parent. E[foo] Matches any E element with the &quot;foo&quot; attribute set (whatever the value). E[foo=&quot;warn&quot;] Matches any E element whose &quot;foo&quot; attribute value is exactly equal to &quot;warn&quot;. E[foo~=&quot;warn&quot;] Matches any E element whose &quot;foo&quot; attribute value is a list of space-separated values, one of which is exactly equal to &quot;warn&quot;. Source: http://www.w3.org/TR/CSS2/selector.html
  • 33. E > F HTML markup <div class= ” blog ” > <p> Introduction </p> <div class= ” story ” > <p> Lorem ipsum dolor </p> <div class= ” date ” > <p> Date </p> </div> </div> </div> CSS .blog p { font-family : Arial, sans-serif; font-size : 1em; color : #555; } .story p { font-size : 1.3em; color : #111; }
  • 34. E > F HTML markup <div class= ” blog ” > <p> Introduction </p> <div class= ” story ” > <p> Lorem ipsum dolor </p> <div class= ” date ” > <p> Date </p> </div> </div> </div> CSS .blog p { font-family : Arial, sans-serif; font-size : 1em; color : #555; } .story > p { font-size : 1.3em; color : #111; }
  • 35. E + F HTML markup <div class= ” blog ” > <h1> Title </h1> <h2> Subtitle </h2> <h2> Subtitle </h2> <p> Lorem ipsum </p> <h2> Subtitle </h2> <p> Lorem ipsum </p> </div> CSS h1 { margin : 0 0 1em 0; font-size : 2em; } h2 { margin : 0 0 .5em 0; font-size : 1.4em; color : #000; }
  • 36. E + F HTML markup <div class= ” blog ” > <h1> Title </h1> <h2> Subtitle </h2> <h2> Subtitle </h2> <p> Lorem ipsum </p> <h2> Subtitle </h2> <p> Lorem ipsum </p> </div> CSS h1 { margin : 0 0 1em 0; font-size : 2em; } h2 { margin : 0 0 .5em 0; font-size : 1.4em; color : #000; } h1 + h2 { margin-top : -1em; font-style : italic; }
  • 37. E:first-child HTML markup <div class= ” blog ” > <h1> Title </h1> <p> Lorem ipsum </p> <p> Lorem ipsum </p> </div> CSS h1 { margin : 0 0 1em 0; font-size : 2em; color : #222; } p { color : #444; margin-bottom : 1em; } .blog p:first-child { font-family : serif; font-style : italic; color : #000; }
  • 38. E:first-child HTML markup <div class= ” blog ” > <h1> Title </h1> <div class= ” story ” > <p> Lorem ipsum </p> <p> Lorem ipsum </p> </div> </div> CSS h1 { margin : 0 0 1em 0; font-size : 2em; color : #222; } p { color : #444; margin-bottom : 1em; } .story p:first-child { font-family : serif; font-style : italic; color : #000; }
  • 39. E[foo=&quot;warn&quot;] HTML markup <label> Name </label><br /> <input type= &quot;text&quot; /> <label> Gender </label><br /> <label> <input type= &quot;radio&quot; /> Man </label> <label> <input type= &quot;radio&quot; /> Woman </label> CSS input[type=&quot;text&quot;] { width : 200px; border : 1px solid #CCC; background : #F5F5F5; padding : 5px; } input[type=&quot;radio&quot;] { margin-left : 1em; }
  • 40. CSS in use Attribute Styling Drop Caps Google Fonts Styling Images
  • 42. HTML markup <!-- place in <head> section --> <link href= ”http://fonts.googleapis.com/css?family=Yanone+Kaffeesatz|Ubuntu” rel= ”stylesheet” type= ”text/css” /> <!-- place in </head> section --> <h1> Title </h1> <p> The quick brown fox jumps over the lazy dog. </p> CSS h1 { font-family : 'Yanone Kaffeesatz' , arial, serif;} p { font-family : 'Ubuntu' , arial, serif;} Don't use too many Google Fonts at the same page because MSIE can't handle that.
  • 43.  
  • 44.  
  • 45. HTML markup <ul> <li><a class= ” doc-icon ” href= &quot;test.doc&quot; > Lorem ipsum dolor </a></li> <li><a class= ” pdf-icon ” href= &quot;test.pdf&quot; > Sit amet consect </a></li> <li><a class= ” xls-icon ” href= &quot;test.xls&quot; > Lorem ipsum dolor </a></li> <li><a class= ” png-icon ” href= &quot;test.png&quot; > Sit amet consectet </a></li> </ul> CSS li a.doc-icon { background : url(doc.gif) no-repeat; } li a.pdf-icon { background : url(pdf.gif) no-repeat; } li a.xls-icon { background : url(xls.gif) no-repeat; } li a.png-icon { background : url(png.gif) no-repeat; }
  • 46. HTML markup <ul> <li><a href= &quot;test.doc&quot; > Lorem ipsum dolor </a></li> <li><a href= &quot;test.pdf&quot; > Sit amet consectetuer </a></li> <li><a href= &quot;test.xls&quot; > Lorem ipsum dolor </a></li> <li><a href= &quot;test.png&quot; > Sit amet consectetuer </a></li> </ul> <ul> <li><a href= &quot;http://twitter.com/finishjoomla&quot; > Twitter </a></li> <li><a href= &quot;http://www.facebook.com/profile.php&quot; > Facebook </a></li> <li><a href= &quot;http://www.linkedin.com/company/&quot; > Linkedin </a></li> <li><a href= &quot;http://www.youtube.com/user/&quot; > Youtube </a></li> </ul>
  • 47. CSS li a[href$='.doc'] , li a[href$='.pdf'] , li a[href$='.xls'] , li a[href$='.png'] , li a[href*='twitter.com'] , li a[href*='facebook.com'] , li a[href*='linkedin.com'] , li a[href*='youtube.com'] { padding-left :40px; min-height :24px; display :inline-block; line-height :24px; } This won't work on IE6 and only on IE7+ when a Doctype is declared.
  • 48. CSS li a[href$='.doc'] { background : url(doc.gif) no-repeat; } li a[href$='.pdf'] { background : url(pdf.gif) no-repeat; } li a[href$='.xls'] { background : url(xls.gif) no-repeat; } li a[href$='.png'] { background : url(png.gif) no-repeat; } li a[href*='twitter.com'] { background : url(twitter.gif) no-repeat; } li a[href*='facebook.com'] { background : url(facebook.gif) no-repeat; } li a[href*='linkedin.com'] { background : url(linkedin.gif) no-repeat; } li a[href*='youtube.com'] { background : url(youtube.gif) no-repeat; } This won't work on IE6 and only on IE7+ when a Doctype is declared.
  • 49.  
  • 50. HTML markup <p> <span class= ” dropcap ” > L </span> orem ipsum dolor sit amet, consectetur adipiscing elit... </p> CSS p { font-family : Arial, sans-serif;} span.dropcap { font-size : 3em; color : #29BDBD; float : left; margin : 10px 10px 0 0; display : block; }
  • 51. HTML markup <p class= ” dropcap ” > Lorem ipsum dolor sit amet, consectetur adipiscing elit... </p> CSS p.dropcap { font-family : Arial, sans-serif;} p.dropcap:first-letter { font-size : 3em; color : #29BDBD; float : left; margin : 10px 10px 0 0; } This won't work on IE6 and only on IE7+ when a Doctype is declared.
  • 52. HTML markup <p class= ” dropcap ” > Lorem ipsum dolor sit amet, consectetur adipiscing elit... </p> CSS p.dropcap { font-family : 'Old Standard TT' , Times, serif;} p.dropcap:first-letter { font-family : 'UnifrakturMaguntia' , Times, serif; font-size : 3em; color : #29BDBD; float : left; margin : 10px 10px 0 0; }
  • 53.  
  • 54.  
  • 55. HTML markup <img class= ” img1 ” src= ”image.png” alt= ” image ” /> CSS img.img1 { background : #FFF; padding : 2px; border : 2px solid #AAA; }
  • 56. HTML markup <img class= ” img2 ” src= ”image.png” alt= ” image ” /> CSS img.img2 { background : url(seamless.png) ; padding : 4px; } Make sure the background image is a seamless pattern.
  • 57. HTML markup <img class= ” img3 ” src= ”image.png” alt= ” image ” /> CSS img.img3 { background : url(seamless.png) ; padding : 3px; border : 1px solid #000; }
  • 58. HTML markup <img class= ” img4 ” src= ”image.png” alt= ” image ” /> CSS img.img4 { background : #000; padding : 1px; border : 2px solid #FFF; outline : 1px solid #AAA; } The outline property is not supported by IE6 and IE7.
  • 60. @rhcpoort Robin Poort [email_address] @tweepixels