Results 1 to 5 of 5

Thread: CSS image link

  1. #1
    Join Date
    Aug 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default CSS image link

    So I've been having trouble. I want to do different style sheets and I thought it would be awesome until I came to this problem...
    I have an index page. and on that page it has an image link how can I change that image so that when they load a new theme it's a new image link? Or am I forced to use that same image no matter what theme?

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    I think you would want to use javascript for what you are asking.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Aug 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    how would that work?
    wouldn't I have to change the image as in even when the load the style the image won't change because i cannot edit that element in css since it's an image link and not just a regular link?

  4. #4
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    I use divs and background images, that way, the image isnt actually embedded directly in the HTML.

    For example, in your html, insert a div container for your image and give it an id. Then within it, put your hyperlink code:
    <div id="homepic"> <a href="index.php" title="Home"></a> </div>

    Now reference the div container using its id in the stylesheet, and add a background image to it:
    Code:
    div#homepic {
    position:absolute; top:92px; left:17px;
    display:block;
    width:166px; height:142px;
    background: url("../images/style1pic.jpg") 0 0 no-repeat; 
    }
    As you can see, the div container, and therefore the image too, is referenced in the stylesheet and not directly in the HTML.

    To change the image, in your second stylesheet simply reference the same div container, but this time with a different image, and it will magically pop into view when you load your second stylesheet, like this:
    Code:
    div#homepic {
    position:absolute; top:92px; left:17px;
    display:block;
    width:166px; height:142px;
    background: url("../images/style2pic.jpg") 0 0 no-repeat; 
    }
    Hope that helps

  5. #5
    Join Date
    Aug 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    yeah that's what I did too but I guess I messed up on the coding so it didn't work. but now it works but thanks your code is very helpful as well!

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
  •