Add URL link in CSS Background Image?

前端 未结 3 1248
暖寄归人
暖寄归人 2020-12-15 07:57

I have a CSS entry that looks like this:

.header {
    background-image: url(\"./images/embouchure.jpg\");
    background-repeat: no-repeat;
    height:160px         


        
相关标签:
3条回答
  • 2020-12-15 08:16

    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;
    }
    
    0 讨论(0)
  • 2020-12-15 08:19

    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;
    }
    
    0 讨论(0)
  • 2020-12-15 08:30

    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>
    
    0 讨论(0)
提交回复
热议问题