views:

100

answers:

3

I have a CSS entry that looks like this:

.header {
    background-image: url("./images/embouchure.jpg");
    background-repeat: no-repeat;
    height:160px;
    padding-left:280px;
    padding-top:50px;
    width:470px;
    color: #eaeaea;
    border-bottom:1px solid #eaeaea;


}

How can I add the link to the the background image in that CSS?

The full CSS can be found here and the html that uses is there.

A: 

You can not add links from CSS, you will have to do so from the HTML code explicitly. For example, something like this:

<a href="whatever.html"><li id="header"></li></a>
Sarfraz
+2  A: 

Using only CSS it is not possible at all to add links :) It is not possible to link a background-image, nor a part of it, using HTML/CSS. However, it can be staged using this method:

<div class="wrapWithBackgroundImage">
    <a href="#" class="invisibleLink"></a>
</div>

.wrapWithBackgroundImage {
    background-image: url(...);
}
.invisibleLink {
    display: block;
    left: 55px; top: 55px;
    position: absolute;
    height: 55px width: 55px;
}
Simeon
This will not work properly, by making the invisibleLink absolute it will be pulled out of the document flow and the div will collapse.
Rob van Groenewoud
It does work wonderfully. However, the solution might have to be adjusted to fit the specific needs of this specific case.
Simeon
@Simeon: I've tested it in Firefox. It seems to work only if there is enough content to fill the 55px vertical space. I agree that any tailoring would be needed.
Rob van Groenewoud
I understand what you mean. Adding overflow: visible; might fix that problem. And I also understand if you don't think this is a complete answer, I could have had a look at the links that was provided. However, this methodology is a way to solve the problem, and if he needs a more specific example, someone or me might find time to provide that.
Simeon
+1  A: 

Try wrapping the spans in an anchor tag and apply the background image to that.

HTML:

<div class="header">
    <a href="/">
        <span class="header-title">My gray sea design</span><br />
        <span class="header-title-two">A beautiful design</span>
    </a>
</div>

CSS:

.header {
    border-bottom:1px solid #eaeaea;
}

.header a {
    display: block;
    background-image: url("./images/embouchure.jpg");
    background-repeat: no-repeat;
    height:160px;
    padding-left:280px;
    padding-top:50px;
    width:470px;
    color: #eaeaea;
}
Rob van Groenewoud