Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 9 of 9

Thread: Dynamic CSS

  1. #1
    Senior Member mossoi's Avatar
    Join Date
    Apr 2003
    Location
    Englandshire, United Kingdomsville y'all!
    Posts
    1,111
    Member #
    1206
    Liked
    1 times
    We're all aware of using JavaScript to point the browser to a specific stylesheet depending on resolution, browser, etc.

    I'm currently using a dynamic CSS page that builds using JavaScript and ASP to allow for both browser differences and user preferences (ie. the user can choose his own font size, color etc. settings without having to opt to one 'skin' which defines all these settings en masse).

    I've put checking in there so that if no preference is selected, or JavaScript is disabled, the default settings are selected.

    The style sheet is saved as an ASP page and contains lines such as:

    .thread {color: <%=strColor%> }

    to apply the users preferences.

    Now the question is, are there any problems using this method? To me, it seems to give a great deal more flexibility than the redirect method and means that there is only one file to define all the styles for the site.

    The reason I ask is that I don't see any references to this type of stylesheet around the Web and the only thing that is really discussed is pointing the browser to a different stylesheet when necessary.

  2.  

  3. #2
    Dan
    Dan is offline
    Member
    Join Date
    Feb 2003
    Posts
    39
    Member #
    707
    I've tried this with PHP and had a LOAD of problems doing it any way but having the code in the page itself. It only wants to include CSS files etc etc etc..

  4. #3
    Senior Member mossoi's Avatar
    Join Date
    Apr 2003
    Location
    Englandshire, United Kingdomsville y'all!
    Posts
    1,111
    Member #
    1206
    Liked
    1 times
    Yes. I made my stylesheet as an ASP file and then included it in the head as a SSI.

  5. #4
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    There are no problems that I can think of. In fact it's far better than Javascript because it doesn't require anything on the client's part.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  6. #5
    Senior Member mossoi's Avatar
    Join Date
    Apr 2003
    Location
    Englandshire, United Kingdomsville y'all!
    Posts
    1,111
    Member #
    1206
    Liked
    1 times
    Good, that's what I was hoping to hear!

    I've had no operational problems with it at all, it's just strange that you don't see this method around very often.

  7. #6
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,657
    Member #
    1234
    Liked
    138 times
    Well, I don't know anything about ASP, but it sounds like a great idea. You might want to do a quick write up about this and turn it into a tutorial, could earn yourself a quick $20 Turtle Dollars!
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com

  8. #7
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    Originally posted by mossoi
    I've had no operational problems with it at all, it's just strange that you don't see this method around very often.
    You probably can't see the method simply because it's transparent to your end.

    I for one never use it because I try to avoid hard-coding any strings in my programs. I use templates instead for HTML generation. Templates in JSP using Tiles and Struts can be fairly interesting, too, albeit quite complicated.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  9. #8
    Senior Member mossoi's Avatar
    Join Date
    Apr 2003
    Location
    Englandshire, United Kingdomsville y'all!
    Posts
    1,111
    Member #
    1206
    Liked
    1 times
    I'll write a quick tutorial on how to do this. Something simple like font size and color to show how it's done.

  10. #9
    Senior Member mossoi's Avatar
    Join Date
    Apr 2003
    Location
    Englandshire, United Kingdomsville y'all!
    Posts
    1,111
    Member #
    1206
    Liked
    1 times
    You don't seem to see this method in tutorials or codebanks though.

    I know what you mean about hard-coding strings but I use a work around for that by making all my modules black box.

    In effect any string is fed into a module that does any sort of manipulation by defining the string with a standard name (strModify for example).

    I just change the string name before the module and change it back again. The beauty of this is that it can be used as a server side include and inserted as many times as there are strings that need the manipulation. This is good for cleaning text from a form. As long as you rename the string before it goes in the box and then back to it's original name when it comes out there are no problems.

    With my stylesheets I do something similar and define any variable values as an include at the top of each page. Then if I want the users profile to overwrite anything I use the DB values to redefine the variable and then apply the stylesheet.

    This means that all the values that matter are kept in a separate SSI that defines the stylesheet making updating even easier than it already is!

    In fact, I've now got my site to the point where I don't need to do any coding to update any part of it - except for new pages and major overhauls of course. Everthing is stored in a DB and called when needed.

    Like I say, I'll post a tutorial to make that all a bit clearer - it'll be in ASP but can easily be implemented in PHP.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 09:58 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com