I just read a great article on css-tricks about how the nth-child selector works.  What really shone out to me was the use of using a negative n value plus a number as in, ‘-n+5′.  What this would do is only select the top 5 rows!  This is very clever and I’m definitely going to be using this in the future.

A practical use of this technique is to imagine a high score table with lots of rows each detailing a person’s high score.  You want to highlight the top three to indicate that these people are the ones to be commended and enlarge the top scorer to emphasise their achievement.  You would use this css:

table#highscores tr td {
    background-color: #666; /* default values */
    height: 20px;
}

table#highscores tr:first-child td {
    height: 40px; /* increase the row height of the top scorer */
}

table#highscores tr:nth-child(-n+3) td {
    background-color: #889; /* emphasise the top three */
}

Unforunately and unsurprisingly, this doesn't work in the most popular* browser in the world, Internet Explorer 8 and below.  For those, you'll have to use jQuery and its implementation of nth-child.  Like what was mentioned in the article on css-tricks though, this technique shouldn't really be used for fundamental website design where the layout or usability would be effected by it not being implemented.  Allowing the website to degrade gracefully for browsers with no implementation is key.

* By most popular, I really mean most widely-used.  I doubt that a large proportion of the internet population are using IE8 because they actually prefer IE8 to other browsers or they wouldn't switch if they had the opportunity, such as business users whose systems are locked down

 

A pretty simple philosophy: If you make the primary action on a form or web page stand out, users will be more likely to click it. By emphasising these buttons or actions you are attempting to draw the user’s focus toward it.  And by primary action, I mean the submit, send, save etc buttons; actions where the user is making progress. Secondary actions could be buttons like back, undo or cancel

There are a number of ways to emphasise the primary action. One of the easiest and yet still effective methods is to colour the button brightly to draw attention. Similarly you could reduce the saturation of the cancel button. The human eye is drawn to areas of colour which stand out from the page. Also culturally the colour green is associated with a positive action and so if the user is in a hurry or just speedily going through the form, when they see the green button they will know it’s the button that submits the information. Chances are that they won’t actually read the text of the button!

Continue reading »

 

Just thought I’d let you all know of a quick trick to get your text to vertically align within an element without using nasty padding or margin hacks. If you know that your element is going to be a certain height, then you can use the css attribute ‘line-height’ and give it the same value as the height of the object. Please note that this will only work where there is only a single line of text.

The background colour I’m using is #EFF8F8

Here I have a pseudo-button and actually it’s just a text link within a <p>. Here’s the HTML and css:

<p class="actionbutton"><a href="/BuyingAndSelling/BuyHoliday">Buy Holiday</a></p>

p.actionbutton
{
margin:0 auto 1em auto; /*center the button on the page*/
text-align:center;
width:124px;
height:44px;
}

p.actionbutton a
{
line-height:44px; /* same height as actionbutton element */
font-size:1.2em;
display:block; /* makes the whole area clickable rather than just the text */
text-decoration:none;
color:Black;
background-image: url('smartbutton.gif');
}

/*rollover*/
p.actionbutton a:hover
{
color:DarkOrange;
background-image: url('smartbutton-down.gif');
}

Here are the source images for you to play around with

Normal button state

On mouse rollover



© 2011 athe.la blog Suffusion theme by Sayontan Sinha