Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!
Archive for the ‘Uncategorized’ Category
Hello world!
Friday, July 2nd, 2010Using jQuery to mimic CSS3's :nth-last-child
Wednesday, June 24th, 2009I came across the need for using CSS3′s :nth-last-child pseudo-selector recently. What does this do? Nth-last-child lets you select the nth (2nd, 3rd, 4th, etc) child of some element starting from the last one. For example:
li:nth-last-child(-n+4) would select the last four list items in a list.
To style the 2nd-to-last list item only, this example would work:
li:nth-last-child(-n+2)
The situation I had was there is a list of authors for a site. More than wp_list_authors, it was a custom-generated list of certain users. The list is styled to look like a box with two columns. There are dividers between each author both horizontally and vertically, with the bottom two authors having no bottom divider.
This list:
<ul id="authors"> <li class="even"><span><a class="authorImg" href=""> <img src="avatar.jpg" height="30px" alt="" /></a> <a class="authorName" href="">John Doe</a></span></li> <li class="odd"><span><a class="authorImg" href=""> <img src="avatar.jpg" height="30px" alt="" /></a> <a class="authorName" href="">Hap Pill</a></span></li> ...(snip)... <li class="odd"><span><a class="authorImg" href=""> <img src="avatar.jpg" height="30px" alt="" /></a> <a class="authorName" href="">John Hancock</a></span></li> <li class="even"><span><a class="authorImg" href=""> <img src="avatar.jpg" height="30px" alt="" /></a> <a class="authorName" href="">Lorem Ipsum</a></span></li> <li class="odd"><span><a class="authorImg" href=""> <img src="avatar.jpg" height="30px" alt="" /></a> <a class="authorName" href="">Jane Doe</a></span></li> </ul>
… needs to look like this:
Removing the border on the last list item’s span is easy. Use the :last-child pseudo-selector and the border’s gone.
#authors li.odd:last-child span { border-bottom: none; }
Removing the border on the 2nd-to-last one should be this easy:
#authors li:nth-last-child(-n+2) span { border-bottom: none; }
But for now, that only works in Safari 4. (and maybe Opera?) so how to get that effect in Safari 3 and Firefox 3? (I have not gotten this to work in IE7 or 6. Those are coming.) Use jQuery and a three-line script.
Here’s what I cobbled together from digging through the jQuery documentation:
//removes bottom border from next-to-last span in the authors listings var $curr = $('#authors li:last'); $curr = $curr.prev().children('span'); $curr.css('border-bottom','none');
The script first locates the last list item. Then it looks for the previous element of that type, then drills down to the children elements that are spans. In this case, there’s only one. Lastly, the script applies a CSS rule of no border to the span.
Is it perfect? Almost. I’ll need to figure out how to get IE7 and, unfortunately for this job, IE6 to render the next-to-last item correctly.
How to Override Inline CSS Styles
Tuesday, May 26th, 2009Craig Buckler writes on the SitePoint Blogs on How to Override Inline CSS Styles.
His conclusion is spot-on & should be noted:
…this technique is not something you should use on a day-to-day basis. Keep your CSS clean and only override inline styles when there is absolutely no alternative.
CSS Specificity – the basics
Thursday, April 30th, 2009Specificity is one of the most difficult topics to grasp in CSS but it doesn’t have to be. It requires two things:
- Basic math. (How to add, really.)
- How to tell the difference between an HTML element (a tag), a class, an id, and a pseudo-element
That’s it. Let’s look at an example:
Say you’ve got this in your styles:
ul li { color: black; }
li { color: red; }
What will the color of list items (li) be? Is it red, because it comes last? Is it black because we’ve got two tags in the style? The correct answer is black, but not just because we have two tags in the style. It’s because that style declaration’s specificity is greater.
Here’s the specificity math:
element selectors (HTML tags) = 1
pseudo-element selectors = 1
class selectors = 10 (also psuedo-classes and attributes)
id selectors = 100
inline style = 1000
Looking back at the list items, the style with both the ul tag and the li tag has a specifity value of 2 (1 + 1) while the li by itself has a value of 1.
Let’s look at some of the styles on slash25.com.
p {
line-height: 1.5em;
margin-bottom: 1.5em;
}
Specificity = 1
div.entry div p {
font-family: "gill sans",helvetica, sans-serif;
font-weight: 100;
font-size: 90%;
letter-spacing: 1px;
}
Specificity = 13
10 for .entry, 1 for div, 1 for div, 1 for p
What about the link styles?
a {
color: #00a0ea;
text-decoration: none;
border-bottom: 1px dotted #00a0ea;
}
Specificity = 1
a:hover, a:focus {
color: #000;
border-bottom: 1px solid #000;
}
Specificity = 11 (there are two styles, each with a specificity value of 11)
10 for :hover (or :focus), 1 for a
#subNav li li a:hover,#subNav li li a:focus {
color: #000;
border-bottom: none;
}
Specificity = 113 for each.
100 for #subNav, 10 for :hover (or :focus), 1 for li, 1 for li, 1 for a
Remember these basics and you’ll be able to calculate specificity like a pro. Then, the order in which a style appears in the CSS won’t matter as much because you’ll be able to increase the specificity of a style and have your desired effect come to life.
Are there caveats? Like all things in life, yes. The linked URL in this goes to a wonderful Smashing Magazine article in which they go into great depth. I would recommend if you’re stuck and everything seems to not work, drop us a comment or visit that article and see if you can’t figure it out.
The Art of Alt
Monday, April 13th, 2009The alt attribute. One of the two easiest to implement but often unused features of HTML. It’s a required attribute of the img tag. What is it? It’s the textual alternative of the image. In other words, if you can’t see the image, it’s what conveys the information — the meaning, you’re unable to see.
Why is it important?
First off, not all users of the Web are able to see.
A person who is blind is completely capable of using the Web through assistive technology such as a screen reader. This is a piece of software that reads out a Web page. Not just the text sighted users would see, but also the semantics of various elements on a page. Text wrapped in strong tags, emphasis tags, headings, language shifts, etc. When a screen reader encounters an image, the image is identified as such, then the alt attribute is read. If an image is used for a link, the link is identified, then the image, then the alt attribute is read.
If no alt attribute is present, the screen reader identifies the image and the user is left to his or her imagination as to what it might be. If you publish a website, it’s somewhat inherent in that action that you want people to satisfactorily browse your site. Alt attributes help make that possible for the non-sighted audience.
A second reason is that non-sighted software programs might visit your site, too.
Search engine spiders and bots. These programs do not contain eyeballs. When they encounter an img tag, without an alt attribute, the exact meaning and purpose of that image is not known. You include an alt attribute and you’ve just enhanced the meaning of the pages on your site. This is additional information to add to your page’s search relevancy and just might assist in better search rankings.

