SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is using the "style" property in HTML bad form?

    I am building a website that occasionaly needs columns in a <div> where the main content goes. The columns contain text.

    The amount of columns and the width of the columns may vary from page to page.

    My solution:
    I have a defined:

    Code CSS:
    #column {float: left; padding: 1em}

    in my external css style sheet.

    Whenever I need a column a certain width I just add the style property:

    Code HTML:
    <div id="column" style="width: 120px;">

    Is it semantic/efficient to do this?

    Thanks

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,595
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    What happens when you change the content and need it to be 130 pixels wide instead or decide to completely redo the style of the entire site? Any stylesheet entries in the individual pages will all need to be changed.

    If you keep all the styles in an external stylesheet then you can reformat the entire site just by changing that one file.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's not wrong, but it's generally not a good idea. You are mixing presentation with your content, which is every bit as 'bad' as using <font> and <center> tags. You will have to edit the HTML document if you want to change the presentation.

    It would be better to assign a class to the element and specify the width for that class in your external style sheet.
    Code HTML4Strict:
    <div id="column" class="special">
    Code CSS:
    #column {float:left; padding:1em}
    .special {width:120px}
    Birnam wood is come to Dunsinane

  4. #4
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your advice guys


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •