Forum Moderators: not2easy

Message Too Old, No Replies

Appropriate Use of the style attribute

When is the style attribute to be used?

         

trevordixon

11:11 pm on Jul 6, 2006 (gmt 0)

10+ Year Member



Is it ever best to use style attributes instead of id or class selectors?

Programmers

3:47 am on Jul 7, 2006 (gmt 0)

10+ Year Member



Stick with ID and CLASS mate.

bbmatt

11:20 am on Jul 7, 2006 (gmt 0)

10+ Year Member



Depends what your trying to do.

If you have a complex stylesheet and have just a single instance where you would want to modify something slightly, sure.

Or perhaps you have the following scenario - a series of floated box areas, all of which may require a specific width, you could define the generic styles for a box in your stylesheet and then use a combination of that and style :-

<div class="myboxfloat" style="width:120px">

Remember though, it's harder to maintain this.

Robin_reala

11:38 am on Jul 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've come across preceisely one situation in my working career when I needed to use an inline style - a page of text with an image+caption float left at the top. The img and caption were in a <div> which needed to size itself to the picture which could be any size. I ended up writing out an inline style onto the div when the page was generated... But that was it.

penders

12:23 am on Jul 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I suppose it comes down to separating 'style' from content. Using an inline style does break that - but it's a tempting quick fix!