640 likes | 791 Views
Explore the exciting world of CSS in this insightful presentation by Rob Porter from Penn State's TLT Studio. Discover various ways to enhance your website's styling through advanced CSS techniques, including substring matching attribute selectors, pseudo-elements, and child selectors. Learn how to efficiently apply styles based on element attributes, create styled content before and after elements, and leverage sibling combinators for flexible design structures. Dive into practical examples and elevate your web development skills!
E N D
Adding More Cowbell to your Site with CSS Rob Porter - Penn State - TLT Studio @robzonenet Examples from the talk: https://dl.dropboxusercontent.com/u/7733060/cowbell-talk/index.html
CSS is Awesome http://www.zazzle.com/css_is_awesome_coffee_mug-168716435071981928
http://inspectelement.com/wp-content/uploads/2013/03/Q3cUg29.gifhttp://inspectelement.com/wp-content/uploads/2013/03/Q3cUg29.gif
Substring Matching Attribute Selectors • Attribute selectors let you target an element based on its attributes.
Substring Matching Attribute Selectors • [att=value] exact value • [att~=value] whitespace separated list of words • [att|=value] starts with and is immediately followed by - • [att^=value] starts with • [att$=value] ends with • [att*=value] contains
Substring Matching Attribute Selectors [att=value]“exact value” example input[type="text"] { width: 200px; }
Substring Matching Attribute Selectors [att$=value] “ends with” example a[href$=".png"] { background: url(mypngicon.gif) no-repeat left 50%; padding: 2px 0 2px 20px; }
Substring Matching Attribute Selectors [att*=value] “contains” example ul li a[href*="google.com"] { background-image: url(demo-images/google.png); }
Pseudo-elements • ::first-letter • ::first-line • ::before • ::after
Pseudo-elements ::before, ::after Adding Content to your site HTML <ul> <li class="email-address">robzonenet@gmail.com</li> </ul> CSS .email-address::before { content: "Email address: "; } Result • Email address: robzonenet@gmail.com
Pseudo-elements ::before, ::after Adding Content to your site HTML <a href=“http://studio.tlt.psu.edu/“>TLT STUDIO</a> is great CSS @media print { #content a::after { content: " (" attr(href) ") "; } } Printed Paper TLT STUDIO (http://studio.tlt.psu.edu) is great
Child Selectors ul > li { margin: 0 0 5px 0; }
Child Selectors ul > li { margin: 0 0 5px 0; } ul li { margin: 0 0 5px 0; }
Child Selectors ul > li { margin: 0 0 5px 0; } Descendants ul li { margin: 0 0 5px 0; } Children
Child Selectors • HTML • <ul> • <li>List item one</li> • <li>List item two • <ol> • <li>Nested list item one</li> • <li>Nested list item two</li> • </ol></li> • <li>List item three</li> • </ul> CSS Children ul li { color: red; } Descendants ul > li { color: yellow; }
Child Selectors • HTML • <ul> • <li>List item one</li> • <li>List item two • <ol> • <li>Nested list item one</li> • <li>Nested list item two</li> • </ol></li> • <li>List item three</li> • </ul> CSS Children ul li { color: red; } Descendants ul > li { color: yellow; }
Child Selectors • HTML • <ul> • <li>List item one</li> • <li>List item two • <ol> • <li>Nested list item one</li> • <li>Nested list item two</li> • </ol></li> • <li>List item three</li> • </ul> CSS Children ul li { color: red; } Descendants ul > li { color: yellow; }
Adjacent Sibling Combinators p + p { color: red; }
Adjacent Sibling Combinators CSS p + p { color: red; } div + p { color: yellow; } • HTML • <div> • <p>Line One</p> • <p>Line Two</p> • <div>Box</div> • <p>Line Three</p> • </div>
Adjacent Sibling Combinators CSS p + p { color: red; } div + p { color: yellow; } • HTML • <div> • <p>Line One</p> • <p>Line Two</p> • <div>Box</div> • <p>Line Three</p> • </div>
Adjacent Sibling Combinators CSS p + p { color: red; } div + p { color: yellow; } • HTML • <div> • <p>Line One</p> • <p>Line Two</p> • <div>Box</div> • <p>Line Three</p> • </div>
General Sibling Combinators p ~ p { color: red; }
General Sibling Combinators CSS p ~ p { color: red; } div ~ p { color: yellow; } • HTML • <div> • <p>Line One</p> • <p>Line Two</p> • <div>Box</div> • <p>Line Three</p> • </div>
General Sibling Combinators CSS p ~ p { color: red; } div ~ p { color: yellow; } • HTML • <div> • <p>Line One</p> • <p>Line Two</p> • <div>Box</div> • <p>Line Three</p> • </div>
General Sibling Combinators CSS p ~ p { color: red; } div ~ p { color: yellow; } • HTML • <div> • <p>Line One</p> • <p>Line Two</p> • <div>Box</div> • <p>Line Three</p> • </div>
Pseudo-classes • :link • :visited • :hover • :active
Pseudo-classes • :first-child • :last-child • :nth-child(N) • :nth-of-type(N) • :first-of-type • :last-of-type
Pseudo-classes:first-child CSS p:first-child { color: red; } • HTML • <div> • <p>Line One</p> • <p>Line Two</p> • <p>Line Three</p> • <div>**Box**</div> • <p>Line Four</p> • <p>Line Five</p> • </div>
Pseudo-classes:first-child CSS p:first-child { color: red; } • HTML • <div> • <h2>H2</h2> • <p>Line One</p> • <p>Line Two</p> • <p>Line Three</p> • <div>**Box**</div> • <p>Line Four</p> • <p>Line Five</p> • </div>
Pseudo-classes:nth-child(N) CSS p:nth-child(3) { color: red; } • HTML • <div> • <p>Line One</p> • <p>Line Two</p> • <p>Line Three</p> • <div>**Box**</div> • <p>Line Four</p> • <p>Line Five</p> • </div>
Pseudo-classes:nth-child(N) CSS p:nth-child(2n) { color: red; } • HTML • <div> • <p>Line One</p> • <p>Line Two</p> • <p>Line Three</p> • <div>**Box**</div> • <p>Line Four</p> • <p>Line Five</p> • </div>
Pseudo-classes:nth-child(N) CSS p:nth-child(2n+1) { color: red; } • HTML • <div> • <p>Line One</p> • <p>Line Two</p> • <p>Line Three</p> • <div>**Box**</div> • <p>Line Four</p> • <p>Line Five</p> • </div>
Pseudo-classes:nth-child(N) p:nth-child(An+B) A = Cycle Size n = Counter starting at zero(A*0, A*1, A*2,…) B = Offset value used to determine where the iteration will begin
Pseudo-classes:nth-child(N) p:nth-child(odd) p:nth-child(even)
Pseudo-classes:nth-last-child(N) p:nth-last-child(2n+3)
Pseudo-classes:nth-of-type(N) CSS p:nth-of-type(2n+1) { color: red; } • HTML • <div> • <p>Line One</p> • <p>Line Two</p> • <p>Line Three</p> • <div>**Box**</div> • <p>Line Four</p> • <p>Line Five</p> • </div>
Math in CSS? calc()
Math in CSS? .sidebar { width: 35%; float: left; margin-right: 1em; } .content { width: calc(65% - 1em); float: right; }
Math in CSS? .column-1-12 { width: 8.333%; } .column-2-12 { width: 16.6667%; } .column-3-12 { width: 25%; }
Math in CSS? .column-1-12 { width: calc(100% / 12); } .column-2-12 { width: calc(100% / 12 * 2); } .column-3-12 { width: calc(100% / 12 * 3); } .column-1-12 { width: 8.333%; } .column-2-12 { width: 16.6667%; } .column-3-12 { width: 25%; } =>
Font Icons • Actually Font Characters • Scales nicely • aria-hidden="true"
Free Font Icons • http://icomoon.io/ • http://fortawesome.github.io/Font-Awesome/icons/ • http://fontello.com/