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
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts

    Question CSS and random image question?

    This is a two part question.

    First part:

    CSS wont work if used in my page when a linked CSS file is used already?
    If I cut out a section of the CSS and paste it in my document it doesn't work.


    Second part:
    How to get random images based on CSS value entries?
    Currently am using different CSS files for different pages.

    Page_one.php => page_one.css attached.
    Page_two.php => page_two.css attached.


    This is not the way I prefer to code my sites.
    How to fix?

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    First part:
    CSS wont work if used in my page when a linked CSS file is used already?
    If I cut out a section of the CSS and paste it in my document it doesn't work.
    The external CSS might be in a different folder, then the image paths will be relative to the CSS file, not with html
    Second part:
    How to get random images based on CSS value entries?
    Currently am using different CSS files for different pages.
    Page_one.php => page_one.css attached.
    Page_two.php => page_two.css attached.
    You haven't specified the element on to which you are applying image(hopefully background). Anyway the best methode to set a page dependent background is, to write that particular CSS in the same file.
    PS: I don't think it's a PHP related question.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,548
    Thanks
    8
    Thanked 1,094 Times in 1,085 Posts
    You can use inline CSS for things that change (in that one instance) ...

    Example, the background image here will overwrite the one in the CSS file.
    <body style="background: url(mynewpic.jpg);">

    For random images, javascripting or PHP. I recommend PHP myself.

  • #4
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts

    Question

    Thank you for your response here guys.
    I may not have it to clear in my first question or problem.

    On my page I have this:
    PHP Code:
    <head>
    <
    link href="css/style.css" rel="stylesheet" type="text/css" />
    </
    head
    I would like to have only this part in my pages head section, but still have the css file attached.
    Currrently this does not work.
    PHP Code:
    <head>
    <
    link href="css/style.css" rel="stylesheet" type="text/css" />
    <
    style type="text/css">
    #header {
    margin0px;
    width774px;
    height:100px;
    background-imageurl(../images/image_1.jpg);/* this part I would like to make random*/
    background-repeatno-repeat;
    position:relative;
    }
    </
    style>
    </
    head
    Any ideas?
    Last edited by student101; 11-07-2007 at 09:24 PM. Reason: More info...

  • #5
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,548
    Thanks
    8
    Thanked 1,094 Times in 1,085 Posts
    Try this ... not fully what you're looking for, but it might trigger some ideas ...

    <head>
    <link href="css/style.css" rel="stylesheet" type="text/css" />
    <link href="css/header.css" rel="stylesheet" type="text/css" />
    </head>


    This is the file called: header.css

    #header {
    margin: 0px;
    width: 774px;
    height:100px;
    background-image: url(../images/image_1.jpg);/* this part I would like to make random*/
    background-repeat: no-repeat;
    position:relative;
    }

    It's OK to specify more than 1 CSS file in your <head> section.

    Now the random part ... will be trickier.

  • #6
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    Thanks, didn't see that one.

    Here is the random part.
    PHP Code:
    <img src="images/image_<?php echo(rand(1,3)); ?>.jpg" /> // This is for your idea in previous post.
    PHP Code:
    //This is for my idea in my resolve
    #header {
    margin: 0px;
    width: 774px;
    height:100px;
    background-image: url(../images/image_<?php echo(rand(1,3)); ?>.jpg);/* this part I would like to make random*/
    background-repeat: no-repeat;
    position:relative;
    }
    Have fun

    Thanks again, will try it though.
    Last edited by student101; 11-07-2007 at 09:48 PM.

  • #7
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    Sorry forgot to add that you would name your image files like this:

    image_1.jpg
    image_2.jpg
    image_3.jpg

    Then it would work.

    Cheers

  • #8
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    awesome code!
    thanks

  • #9
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    Glad you like, but problem still not solved.

  • #10
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Post the current code you're using and what exactly doesn't work.

  • #11
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    Sorry never got the mail.

    Problem is solved by copying entire CSS code above </head> section.

    Cheers

  • #12
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,927
    Thanks
    6
    Thanked 1,041 Times in 1,014 Posts
    Another waste of time of four members here due to the inability to switch on the brain before posting and to provide enough information.


  •  

    Posting Permissions

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