Wednesday, September 17, 2014

CSS Intermediate: an explanation of CSS Advanced

Introduction:

You're probably wondering at this point: Daniel, you've gone in the wrong order!  Well... kinda :)  Chances are some of the CSS you'd seen last time was interesting to look at but you had no clue what each section was attempting to do with various non alpha-numeric characters used in each declaration.  That's why an intermediate blog is in order.

Onto the explanation of last week's coding fun.  Below is the code from layout.css:


* (asterisk) takes care of all classes in the calling page.
body takes care of the body tag that exists on the calling page.
header takes care of all generic header tags that exist on the calling page.
header h2 takes care of the specific header h2 tag(s) and extends the css from header that was defined above it and modifies all h2 tags that exist on the calling page.
.container takes care of all elements with the id of container on the calling page.

This is some cool stuff!

From the file slideshow.cs we have even more interesting samples:


span.cap takes care of all span tags with the id of cap that exist on the calling page.  Think of this logic in the form of (tag type).(id of tag type).

That covers the bulk of the page layout except for one other declaration type on the page:  span#slide1:target ~ ul.slider li.lArrow a.  Where the . selector uses all generic (id=tag) tags # calls out a specific tag name.  The ~ (tilde/squiggle/twiddle) selector allows you to call a sibling element of the first id'd item getting css'ified to simplify the declarations you declare.

Here's another code sampling from last time, this time a portion of the index.html code written to call the CSS files used for the last tutorial:



for the css declaration span#slide7:target ~ ul.slider li.track .tr7 that makes  the class "tr7" within the list item (li) class "track" within unordered list (ul) have the background color of #f00 (this is the hexadecimal value for Red).

Enjoy!

Source:


No comments:

Post a Comment