Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: How to add a link to a header image?

  1. #1
    Join Date
    Aug 2007
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to add a link to a header image?

    Hi there

    I am unsure how to add a link to my header at the top of my page. My header is a jpeg which has been defined in a CSS as a background image.

    I have read some complicated code to do this, none of which I have had success with, and I'm sure there must be an easier way! (Here's hoping!)

    Many thanks in advance,
    Rachael

  2. #2
    Join Date
    Mar 2007
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Do you mean make an image into a link?

    Here is what you need if thats the case.
    HTML Code:
    <A HREF="The URL of the site"><img src="The URL of the image"></A>
    
    Example: <A HREF="www.dynamicdrive.com"><img src="images/car.gif"></A>

  3. #3
    Join Date
    Aug 2007
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    No, the image is defined in the CSS as a background image, so I can't just add a straightforward link like I would to a regular image that is in the HTML.

    Thanks for replying to me though. Hopefully someone will come up with an answer for me!

    Rachael

    PS: Hope you sorted your problem with display differences in IE/Firefox. I had the same problem too - I kept fiddling around until it suddenly worked. Still don't quite understand why though!

  4. #4
    Join Date
    Sep 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>background image link</title>
    
    <style type="text/css">
    
    #logo span, #logo a {
    	display:block;
    	width:780px; /* whatever your image is */
    	height:200px; /* whatever your image is */
    	padding:0;
    	border-style:none;
    	background:url('header.jpg') no-repeat;
    	}
    	
    </style>
    </head>
    
    <body>
    
    <div id="logo">
    	<span>
    		<a href="/"></a>
      	</span>
    </div>
    
    </body>
    </html>
    hth

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    If your image is important enough to have a link, it's not suitable as a background image. Background images are for images that have no semantic meaning: they can't have alternative text. Images with semantic meaning should be marked up using the <img> element and given a suitable non-blank alt attribute.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Sep 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey View Post
    If your image is important enough to have a link, it's not suitable as a background image. Background images are for images that have no semantic meaning: they can't have alternative text. Images with semantic meaning should be marked up using the <img> element and given a suitable non-blank alt attribute.
    I disagree slightly on that issue. Using an image as a header image that links back to your main page is widely used, yet most people pop their image in the css so it preloads while the content is laid out. I can also think of using an image as a forwards and backwards button in combination with js where I'd prefer to use css.

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Using an image as a header image that links back to your main page is widely used, yet most people pop their image in the css so it preloads while the content is laid out.
    It's still bad practice. There are other ways of doing it, such as setting the background on an invisible element, if you'd like to use CSS to preload the images.
    I can also think of using an image as a forwards and backwards button in combination with js where I'd prefer to use css.
    Firstly, there are forward and back buttons on the browser toolbar; duplicating browser functionality is bad practice. Secondly, why use CSS there?

    If you use CSS for these images, people with non-visual user agents (e.g. screenreaders) will be unable to use the links they provide. This is, obviously, bad. To do so misses the whole point of CSS. CSS was designed to abstract the design from the content. If your image is a link to another page, then it is part of the content, and should be marked up in the HTML. To use CSS for this purpose is an abuse.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Sep 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Your wholly right with your points, however, I didn't explain myself enough I guess.

    Forward and back buttons for content within a set page, such as a CSS styled image slideshow with a touch of js to allow movement between images is where I have used background-image and tucked the <span> text out the left in the same way as you would do with SIFr. So maintaining accessability & usability but also allowing visually stimulating buttons as required. I'm on your side (web standards), just trying to explain what I mean better.

  9. #9
    Join Date
    Aug 2007
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi guys

    I have just followed Shagura's method to link my CSS defined background image to my home page, and all works fine, so thank you. I've just come back to the forum to thank you, and have read the other messages and am now confused. Is it best for me to add my header image as a CSS defined background image, or is it best to have it as just an image?

    I did try doing the latter method, but I can't get the image to fit the screen without causing the vertical scroll bar to appear, which I really dont' want.


    Please can someone clarify which is the best way forward, as I've gone from confused, to "problem solved", to back to square one again.

    Many thanks in advance!
    Rachael

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It's best to just have it as an image.
    Forward and back buttons for content within a set page, such as a CSS styled image slideshow with a touch of js to allow movement between images is where I have used background-image and tucked the <span> text out the left in the same way as you would do with SIFr.
    But why? This is a hack to simulate the <img> element's alt attribute, and as they go it's not a bad one, but I'm failing to see the benefits. Also, I'm proud to say I've never used and quite possibly never will use sIFR. Maybe when vector images are better supported so the user can resize the text still.
    So maintaining accessability & usability but also allowing visually stimulating buttons as required.
    How does using the CSS background-image allow for more visually pleasing buttons over a simple <img>?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •