BarCampTampa2011 WriteBetterHTML PDF
BarCampTampa2011 WriteBetterHTML PDF
<head>
{autoVersion}/css/global/dynamic.css{/autoVersion}
{autoVersion}/css/landing/dynamic.css{/autoVersion}
$fileArray = array(
'/css/global/structure.css',
'/css/global/buttons.css',
'/css/global/lightbox.css',
'/css/global/form.css'
);
$fileArray = array(
'/css/landing/structure.css',
'/css/landing/table.css',
'/css/landing/else.css',
'/css/landing/signup.css',
'/css/landing/tour.css'
);
<head>
organized by
site section
2 DON’T OVER
THINK IT
Good thinking Well intentioned
BIG FANCY STYLE GUIDE
• Primary color #BADA55 / Secondary color #F00
• Headers should be 20px from navigation and
15px from following content
• Logo should have 30px of padding around it
• Links should have 1px dotted bottom borders
that’s what
GLOBAL.CSS
is for
NEED TO DEVIATE?
Really? Do you?
BY
SECTION
NEED TO DEVIATE?
Really? Do you?
STYLE
ONLY
NEED TO DEVIATE?
Really? Do you?
TOTALLY
UNIQUE
DON’T
OVER
THINK
IT
3 PSEUDO
ELEMENTSpseudo class
:visited :hover :active :link
selectors
:first-child :last-child :nth-child() :nth-of-type()
:enabled :disabled :checked :indeterminate
:focus :target :root :lang()
http://css-tricks.com/pseudo-class-selectors/
:before
:after
HTML <div>In</div>
div:before {
content: "Robots ";
}
CSS
In
HTML <div>In</div>
div:before {
content: "Robots ";
}
CSS
div:after {
content: " Disguise";
}
Robots In Disguise
So what’s with
the different name?
Pseudo selectors select elements that
already exist (perhaps in different states).
div:before {
content: "Robots ";
CSS
}
div:after {
content: " Disguise";
}
Robots In Disguise
Resulting <div>
HTML In
(sorta) </div>
Robots
Resulting <div>
HTML In
(sorta) </div>
Disguise
M E LOT!
CA
M E LOT!
CA
.button {
/* Awesome gradients and stuff */
}
CSS
.button img {
/* Probably some margin and stuff */
}
alt=""
equals
.button {
/* Awesome gradients and stuff */
}
CSS
.button-gallery:before {
content: url(/https/www.scribd.com/images/icon_gallery.png);
}
x200
<a class=”button” href=”http://wufoo.com/gallery/”>
<img src=”/images/icon_gallery.png” alt=””>
Visit Our Form Gallery
</a>
CSS h1:before {
content: “Wufoo”;
}
h2:before {
content: “Making forms easy + fast + fun”;
}
Bad for accessibility
Bad semantically
Bad for SEO
SCREEN READERS
NVDA doesn’t read
content: -webkit-linear-gradient(...);
Needs dimensions
ATTRIBUTE
content: attr(href);
content: attr(data-city);
On list items COUNTER
content: counter(li);
counter-increment: li;
counter-reset: li;
On list
NOTHING
content: “”;
HTML
content: “<h1>Nope</h1>”;
TEXT / STRING
<div class="price">30</div>
<div class="price" lang="cn">100</div>
[lang=‘cn’] .price:before,
.price[lang=‘cn’]:before {
content: ‘\00a5’;
}
COUNTER
ol {
counter-reset: li;
}
ol > li:before {
content: counter(li);
counter-increment: li;
}
http://www.456bereastreet.com/lab/styling-ordered-list-numbers/
ATTRIBUTE
<a href=”#” data-tooltip=”is hot.”>
Your mom
</a>
a[data-tooltip] {
position: relative;
}
a[data-tooltip]:after {
content: attr(data-tooltip);
position: absolute;
/* Fancy styles */
opacity: 0;
}
a[data-tooltip]:hover:after {
opacity: 1;
}
COMBINING WITH MEDIA QUERIES
mobile portrait
mobile landscape
tablet
small monitor
large monitor
http://css-tricks.com/css-media-queries/
You can’t talk about Pseudo Elements
without talking about...
Nicolas
“Dr. Pseudo Element”
Gallagher
http://nicolasgallagher.com/
@necolas
Shapes!
e a re e asy.
Thes
re le ss e a sy.
These a
.star {
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 100px solid red;
position: relative;
}
.star:after {
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-top: 100px solid red;
position: absolute;
content: "";
top: 30px;
left: -50px;
}
http://css-tricks.com/examples/ShapesOfCSS/
http://nicolasgallagher.com/pure-css-gui-icons/demo/
Remember, CSS TWO not THREE
Browser Support
CSS-Tricks
97% 85% Other tech
92%
3.5+
1+
3.0- positioning issues
9+
8 :: / :hover / z-index 1.3+ 6+
7-
http://css-tricks.com/browser-support-pseudo-elements/
MORE
http://css-tricks.com/9516-pseudo-element-roundup/
Links
http://necolas.github.com/normalize.css/
http://snook.ca/archives/html_and_css/font-size-with-rem
http://particletree.com/notebook/automatically-version-your-css-and-javascript-files/
http://css-tricks.com/855-specifics-on-css-specificity/
Photos
http://www.flickr.com/photos/webel/347801397/
Type
Gotham Condensed
Gotham Rounded
TUNGSTEN
Whitney
Thanks!
http://bit.ly/???