Background Image clickable & Responsive

3.5k views Asked by At

Was try to make a background image clickable. I used the follow: <a href="http://goggle.com" title="me Consulting" id="range-logo"></a> as html code and the following:

#range-logo {
    background-image:url(http://midwaycinema7.com/wp-content/uploads/2015/12/home-specialism-section-2.jpg);
    display:block;
    height:600px;
    width:1240px;
}

as CSS code.

I was able to achieve making the background image clickable but the image in repeated which is not what I wanted. I want the image be full screen without repeating on any device (responsive). A code to achieve that will be helpful . Thanks in advance.

JSFiddle: https://jsfiddle.net/qfpqdzk2/

PS: Trying to implement this on wordpress.

3

There are 3 answers

0
R.K.Bhardwaj On

please check this link: https://ran.ge/2009/11/11/css-trick-turning-a-background-image-into-a-clickable-link/

#range-logo {
    background-image:url(http://midwaycinema7.com/wp-content/uploads/2015/12/home-specialism-section-2.jpg);
    display:block;
    height:500px;
    text-indent:-9999px;
    width:613px;
}
<a href="http://midwaycinema7.com/about" title="me Consulting" id="range-logo"></a>

0
AudioBubble On

This fix is specific to this image because it has a white background

#range-logo {
margin:0 auto;
  background-image: url(http://midwaycinema7.com/wp-content/uploads/2015/12/home-specialism-section-2.jpg);
  background-repeat: no-repeat;
  background-size: cover;
  display: block;
  max-width:100vh;
  height: 100vh;
  width: 1240px;
}
<a href="http://midwaycinema7.com/about" title="me Consulting" id="range-logo"></a>

0
Elle Orlando On

You can create a transparent hover state on the background image and then where the hover state is called in the HTML you can wrap that in an anchor tag.

.hover-state {
    position: absolute;
    top: -1px;
    bottom: 0;
    left: 0;
    right: 0;
    height: auto;
    width: auto;
    opacity: 0;
    padding:  0;
    transition: .5s ease;
    opacity: 0;
    @include respond ("altmax-1024") {
        opacity: .4;
    }
    &--transparent {
        background-color: transparent;
    }
}

.hover-state-item:hover .hover-state--transparent {
    opacity: 0;
}