Dynamic CSS

Discussion in 'ASP General' started by JWL, Jun 29, 2006.

  1. JWL

    JWL Guest

    Hi

    I need to create a bunch of sites with slightly dynamic CSS. Basically,
    all the image paths in the CSS need to be dynamic, depending on the
    values of certain ASP variables.

    I can think of 3 ways to do this:

    1. Write a script to create a semi-dynamic CSS file, which will be run
    whenever we need to make changes to the ASP variables controlling the
    image paths.

    2. Have an ASP script generate the CSS on the fly:

    <link href="dynamiccss.asp" rel="stylesheet" type="text/css">

    3. Put all static CSS in a normal CSS file, and have a special dynamic
    style sheet for only those rules that require variability. We could
    either use method 2 above to generate a second style sheet, or place
    dynamic rules directly in the actual asp pages.

    I'm not sure what to do. (1) has the disadvantage that the CSS is not
    truly dynamic. (2)... well, I'm not sure if (a) this is legal by W3C
    standards and whether there's a performance hit involved. (3) has the
    disadvantage that it places rules for the same elements in different
    locations, which could lead to confusion.

    Is there a generally accepted way to solve this problem?
     
    JWL, Jun 29, 2006
    #1
    1. Advertising

  2. JWL

    Mike Brind Guest

    JWL wrote:
    > Hi
    >
    > I need to create a bunch of sites with slightly dynamic CSS. Basically,
    > all the image paths in the CSS need to be dynamic, depending on the
    > values of certain ASP variables.
    >
    > I can think of 3 ways to do this:
    >
    > 1. Write a script to create a semi-dynamic CSS file, which will be run
    > whenever we need to make changes to the ASP variables controlling the
    > image paths.
    >
    > 2. Have an ASP script generate the CSS on the fly:
    >
    > <link href="dynamiccss.asp" rel="stylesheet" type="text/css">
    >
    > 3. Put all static CSS in a normal CSS file, and have a special dynamic
    > style sheet for only those rules that require variability. We could
    > either use method 2 above to generate a second style sheet, or place
    > dynamic rules directly in the actual asp pages.
    >
    > I'm not sure what to do. (1) has the disadvantage that the CSS is not
    > truly dynamic. (2)... well, I'm not sure if (a) this is legal by W3C
    > standards and whether there's a performance hit involved. (3) has the
    > disadvantage that it places rules for the same elements in different
    > locations, which could lead to confusion.
    >
    > Is there a generally accepted way to solve this problem?


    The generally accepted way is to do whatever works best for you with
    the minimum amount of work. Another alternative is to dynamically
    generate the <link href="style.css" rel="stylesheet" type="text/css">
    tag using a SELECT CASE, and have a number of hardcoded style sheets to
    link to.

    With regard to your points and comments on them:

    1. So what if it's not truly dynamic (whatever that means)? If it
    works, it works.
    2. The browser has no idea what generated the CSS file. It either
    validates, or it doesn't. However, generating a style sheet every time
    a page is requested seems unnecessary.
    3. You're right - you are overcomplicating things.

    --
    Mike Brind
     
    Mike Brind, Jun 29, 2006
    #2
    1. Advertising

  3. JWL

    dp Guest

    JWL wrote:
    > Hi
    >
    > I need to create a bunch of sites with slightly dynamic CSS.
    > Basically, all the image paths in the CSS need to be dynamic,
    > depending on the values of certain ASP variables.
    >
    > I can think of 3 ways to do this:
    >
    > 1. Write a script to create a semi-dynamic CSS file, which will be run
    > whenever we need to make changes to the ASP variables controlling the
    > image paths.
    >
    > 2. Have an ASP script generate the CSS on the fly:
    >
    > <link href="dynamiccss.asp" rel="stylesheet" type="text/css">
    >
    > 3. Put all static CSS in a normal CSS file, and have a special dynamic
    > style sheet for only those rules that require variability. We could
    > either use method 2 above to generate a second style sheet, or place
    > dynamic rules directly in the actual asp pages.
    >
    > I'm not sure what to do. (1) has the disadvantage that the CSS is not
    > truly dynamic. (2)... well, I'm not sure if (a) this is legal by W3C
    > standards and whether there's a performance hit involved. (3) has the
    > disadvantage that it places rules for the same elements in different
    > locations, which could lead to confusion.
    >
    > Is there a generally accepted way to solve this problem?


    You don't have to use the .css extension for an included style sheet. You
    can acutally use a .asp extension and intersperse asp and css much the same
    way you would if you had html interspersed within an asp page. You just have
    to set the content type of the .asp css file to text/css.

    An example of what's in an .asp file linked to instead of a .css file is...
    THE HTML
    ------------------
    <link rel="stylesheet" type="text/css" href="/stylesheet.asp?margin=10">


    THE stylesheet.asp FILE
    ---------------------------------
    <%
    Response.ContentType="text/css"
    Dim strImageMargin
    strImageMargin = Request.QueryString("margin")
    %>

    img {margin:<%=Trim(strImageMargin)%>px;

    --
    dp
     
    dp, Jul 11, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eric
    Replies:
    4
    Views:
    734
    clintonG
    Dec 24, 2004
  2. tom watson

    print.css and screen.css

    tom watson, Sep 9, 2003, in forum: HTML
    Replies:
    1
    Views:
    472
    Jukka K. Korpela
    Sep 9, 2003
  3. Joshua Beall
    Replies:
    1
    Views:
    439
    Bertilo Wennergren
    Dec 10, 2003
  4. Noozer
    Replies:
    10
    Views:
    2,109
    Mitja
    Oct 13, 2004
  5. Titus A Ducksass - AKA broken-record
    Replies:
    6
    Views:
    655
    Titus A Ducksass - AKA broken-record
    Nov 15, 2004
Loading...

Share This Page