CSS image hyperlink

I know this is probably the dumbest question, but I'm starting to start when it comes to CSS; How do you hyperlink an image to a web page using an image that is derived from CSS? I am trying to set a header image on my site linked to the main page. Thanks!

Edit: Just to make it clear, I am picking my image from CSS, the CSS code for the div header is as follows: -

#header
{
    width: 1000px;
    margin: 0px auto;
    padding: 0px 15px 0px 15px;
    border: none;
    background: url(images/title.png) no-repeat bottom;
    width: 1000px;
    height: 100px;
}

I want to know how to make this div a hyperlink on my web page without making it an anchor, not a div.

+5
source share
11 answers

You control design and styles using CSS, not the behavior of your content.

- <a id="header" href="[your link]">Logo</a>, CSS, :

a#header {
  background-image: url(...);
  display: block;
  width: ..;
  height: ...;
}

div <a> - "" . <a> , . , Javascript , - <a>.

<a> <div>, :)

, JavaScript, <div> :

Document.getElementById("header").onclick = function() {
    window.location='...'; 
}
+15

css-source:

#header { 
display:block;

margin: 0px auto;
padding: 0px 15px 0px 15px;
border: none;
background: url(images/title.png) no-repeat bottom;
width: 1000px;
height: 100px;    
}    

<a id="header" href="blah.html" class="linkedImage">

, , . .

+5

CSS. A, . ( CSS, , , .)

<a href="index.html"><img src="foo" class="whatever" alt="foo alt" /></a>

: ( ), :

<a href="index.html"><img id="header" alt="foo alt" /></a>

HTML , .

+4

, .

Write in your header: [link](http://"link here")

then in your css:

#header a[href="https://link here"] {
          display: inline-block;
          width: 75px;
          height: 75px;
          font-size: 0;
        }
        .side .md a[href="link here"] {
          background: url(%%picture here%%) no-repeat;
        }
+3

- HTML "a" (), . CSS , , - - .

Edit - . , JavaScript, div- :

<div id="header" onclick="window.location='http://google.com';">My Header</div>

, JavaScript .

, cursor: pointer; CSS, div .

+2
<a href="linkto_title_page.html" class="titleLink"></a>

css

.titleLink {
  background-image: url(imageUrl);
}
+2

CSS , . HTML <a href="">. ( ) CSS.

0

HTML - - -.

CSS - , .

a <a> - , <div> JavaScript. jQuery:

$("div#header").click(function() {window.location=XXXXXX;});
0

, . h1, , , div. CSS / . CSS. :

<h1 id="title"><a title="Home" href="index.html>My Title</a></h1>
<div id="title"><a title="Home" href="index.html>My Title</a></div>

CSS:

#title {
position:relative; /*Makes this a containing element*/
}
#title a {
background: transparent url(../images/logo.png) no-repeat scroll 0 0;
display:block;
text-indent:-9999px; /*Hides the anchor text*/
height:50px; /*Set height and width to the exact size of your image*/
width:200px;
}

h1, , div, CSS Resets .

0

HTML5 , div . :

<div href="http://stackoverflow.com"> .... </div>

, HTML5 - , - .

0

- H1 . :

<h1 class="technique-six">
    CSS-Tricks
</h1>

h1.technique-six {
    width: 350px;
    padding: 75px 0 0 0;
    height: 0;
    background: url("images/header-image.jpg") no-repeat;
    overflow: hidden;
}

, IE6 > . H1.

0

All Articles