SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot Egghead's Avatar
    Join Date
    Feb 2002
    Posts
    197
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dynamic CSS or inline style statements

    Would anybody be prepared to discuss the pros/cons of dynamically achieving different styles on a web page.

    Two methods I would really like to consider are:
    1. Use server-side scripting (PHP) to generate an externally linked CSS. (As shown in the thread: Dynamic CSS: another way??)
    2. Use server-side scripting to create different inline style statements in the HTML pages.
    Are there any other ways I should consider?

  2. #2
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    40,339
    Mentioned
    179 Post(s)
    Tagged
    6 Thread(s)
    Hi,

    Well I think the structured way is to offer alternative stylesheets through php (or some other serverside language ). Then armed with the proper browser the user can decide etc.

    If you are going to dynamically write the styles inline where does this leave the accessibility issues. Obviously you can offer alternatives but disabled users are varied in their disabilities and abilities and would probably prefer to set their own user stylesheets as inline styles can't be overwritten.

    If you use inline styles then your html is going to increase and be harder to manage (unless it's just the odd tag etc).

    It's obviously harder to maintain several stylesheets than to dynamically change one so I can see why tou would want to.
    Are there any other ways I should consider?
    I find php styleswitchers quite slow and cumbersome to use (depending on site size) and another alternative would be to offer a javascript stylechanger that defaults to php if javascript is disabled etc. The benefits of the javascript changer is that things happen straight away and make them very usable. Offering php as a backup would cure the accessibility issue. I did have a working model of this but I seem to have mislaid it somewhere .

    These are my first (probably incoherrent) thoughts and I hope they are of some use.

    Paul

  3. #3
    SitePoint Zealot Egghead's Avatar
    Join Date
    Feb 2002
    Posts
    197
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the quality input Paul. (There doesn't seem to be a rating system anymore but you have definitely earnt your Brownie Points from me).

    I kind of imagined offering alternative style sheets was the way to go but as the changes will only be a few lines each, I figured I would end up with several style sheets (harder to manage as you point out) and in the interest of keeping the number of files and changes small, I thought serving up inline styles would be an efficient method, as the only files I would be changing would be the standard PHP site pages that build the HTML.

    I feel creating the style sheets on the fly is overkill, as the PHP scripts are already serving up plenty by themselves; I considered increasing the load on the server by dynamically building the stylesheets a bit excessive. It would be nice to think that the whole site could be generated on the fly but I don't want to slow things down any more than necessary. My server is shared and heavily worked anyway - If there is a quicker more efficient way to do things then I'm all for it!

    I hadn't really considered the accessibility issues of inline styles and now you have pointed them out I believe this is something to avoid entirely. I was a bit worried about the browser compatibility issues with inlines but standards compliancy is really all about making the site accessible in the first place so I think case closed for me on that one. Thanks for bringing it to my attention.

    Well, I've probably kicked the ar*e out of this for now. I've certainly gained insight into the problems with inline styles. One thing I am avoiding at the moment is the @import possibility because I know very little about it - not that I know much about anything else CSS based but I'm learning (trying ).

    A joy to read your comments Paul, and a fantastic, resourceful forum for me to peruse a bit more often. Once I've got through the Sitepoint CSS book and thrashed out all my mistakes I may be able to give back a little. Cheers one and all.

    Regards,
    Egghead


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
  •