Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add URL link in CSS Background Image?

Tags:

html

css

url

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.

like image 887
neversaint Avatar asked Apr 15 '10 07:04

neversaint


People also ask

How do I add a link to an image in CSS?

Complete HTML/CSS Course 2022 To use image as a link in HTML, use the <img> tag as well as the <a> tag with the href attribute. The <img> tag is for using an image in a web page and the <a> tag is for adding a link. Under the image tag src attribute, add the URL of the image. With that, also add the height and width.

Can you make a background image a link?

You can't. Background images are not part of the HTML; they are part of the CSS. To make images clickable aka hyperlinked you need to insert them into your HTML.

How do I link a url in CSS?

The url() CSS function is used to include a file. The parameter is an absolute URL, a relative URL, a blob URL, or a data URL. The url() function can be passed as a parameter of another CSS functions, like the attr() function.


1 Answers

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;
}
like image 82
Rob van Groenewoud Avatar answered Oct 08 '22 18:10

Rob van Groenewoud