Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New Coder
    Join Date
    Feb 2008
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    randomize in css sheet

    i was wondering if u can randomize something in the css sheet.
    example:
    Code:
    #header{height:450px; background:url(images/flash.jpg) top repeat; text-align:left;}
    i want to randomize the "images/flash.jpg" part. so like randomize flash1, flash2, flash3 thxs in advanced.

  • #2
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,958
    Thanks
    120
    Thanked 76 Times in 76 Posts
    You can't. Use java script, or possible server side language, if jou are refreshing whole page each time.

  • #3
    New Coder
    Join Date
    Feb 2008
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts
    o ok. is there a code snippet i can use for a resource? thanks

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    Quote Originally Posted by BubikolRamios View Post
    You can't. Use java script, or possible server side language, if jou are refreshing whole page each time.
    You can do it easily by the help of PHP!

    Just save your CSS file with a php extension, say style.php of style.css.php

    Then add a header at the top of your file, like
    Code:
    <?php
    header( 'Content-type: text/css' ); 
    ?>
    Now you can add and execute any PHP codes inside your file anywhere within PHP tags.

    PS: the above would be applicable to any server-side languages, but simply I don't know
    Last edited by abduraooft; 07-18-2008 at 08:09 AM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    Senior Coder jerry62704's Avatar
    Join Date
    Oct 2007
    Location
    Springfield, IL
    Posts
    1,100
    Thanks
    13
    Thanked 87 Times in 87 Posts
    I wonder if you have looked at expressions? I don't use them, but they allow you to dynamically change the css.
    .
    .
    ...and gladly would he learn and gladly teach

    Visit www.LiberalsWin.com for humor and the unique Bush/Obama Approval Polls

  • #6
    Regular Coder BoldUlysses's Avatar
    Join Date
    Jan 2008
    Location
    Winston-Salem, NC
    Posts
    938
    Thanks
    10
    Thanked 190 Times in 187 Posts
    Can't randomize the CSS but you can randomize the markup (HTML, XHTML) using PHP fairly easily. Rename the file extension of your page to .php and add:

    PHP Code:
    <?php
    $image 
    rand(130);
    echo 
    '<img src="images/IMG_'.$image.'.jpg" "alt=Image '.$image.'" title=""/>';
    ?>
    Where 1 and 30 are the upper and lower limits on the range of random numbers generated. Adjust as needed.
    matt | design | blog

  • #7
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    Quote Originally Posted by jerry62704 View Post
    I wonder if you have looked at expressions? I don't use them, but they allow you to dynamically change the css.
    AFAIK, they work only in IE, and it'd be hard to write a long procedure in the CSS expression
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #8
    Senior Coder jerry62704's Avatar
    Join Date
    Oct 2007
    Location
    Springfield, IL
    Posts
    1,100
    Thanks
    13
    Thanked 87 Times in 87 Posts
    I didn't know they were browser dependend. I don't use them as I'm afraid of the performance hit as they are evaluated for every move of the mouse on the page as well as start up and end time. I've got to look into that.

    Thanks for the heads up.
    .
    .
    ...and gladly would he learn and gladly teach

    Visit www.LiberalsWin.com for humor and the unique Bush/Obama Approval Polls

  • #9
    The Apostate Apostropartheid's Avatar
    Join Date
    Oct 2007
    Posts
    3,215
    Thanks
    16
    Thanked 265 Times in 263 Posts
    Quote Originally Posted by msuffern View Post
    Can't randomize the CSS but you can randomize the markup (HTML, XHTML) using PHP fairly easily. Rename the file extension of your page to .php and add:

    PHP Code:
    <?php
    $image 
    rand(130);
    echo 
    '<img src="images/IMG_'.$image.'.jpg" "alt=Image '.$image.'" title=""/>';
    ?>
    Where 1 and 30 are the upper and lower limits on the range of random numbers generated. Adjust as needed.
    Um, of course you can randomize a CSS stylesheet. PHP can send a HTTP Content-Type header for CSS and that's all that's needed. It's not an exclusive markup thing, you know...

  • #10
    Regular Coder BoldUlysses's Avatar
    Join Date
    Jan 2008
    Location
    Winston-Salem, NC
    Posts
    938
    Thanks
    10
    Thanked 190 Times in 187 Posts
    I stand corrected. So how would I structure a CSS stylesheet file to accept PHP input? Or rather, I suppose, how would I structure a PHP file so the browser treats it like a stylesheet?
    matt | design | blog

  • #11
    The Apostate Apostropartheid's Avatar
    Join Date
    Oct 2007
    Posts
    3,215
    Thanks
    16
    Thanked 265 Times in 263 Posts
    abdura has already said; simply make PHP output a CSS header.
    PHP Code:
    <?php
      header
    ("Content-Type: text/css");
    ?>
    @charset "utf-8";
    html {
      font: 75%/1.8 'lucida sans unicode', 'lucida grande', sans-serif;
    }
    /* Et cetera */

  • #12
    Regular Coder BoldUlysses's Avatar
    Join Date
    Jan 2008
    Location
    Winston-Salem, NC
    Posts
    938
    Thanks
    10
    Thanked 190 Times in 187 Posts
    That's what I get for not scrolling up! Thanks
    matt | design | blog


  •  

    Posting Permissions

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