user25976 user25976 - 2 months ago 16
CSS Question

HTML and CSS: using background image as a clickable link

I'm trying to use a html and css trick to give the impression of using a background image as a clickable link following this tutorial. I can't get to work, however, due to two issues:

1) The link is not filling the space of the background image

2) The link will not move off the screen

I'm using an html code integration block for a weebly website. I'm a beginner to html and CSS.

<a href="website.net/link" title="photo" id=«photo»>photo</a>

<a class="photo"></a>

<style type="text/css">

.photo {
background-image: url(myImageLink.jpg);
background-size: 300px;
background-repeat: no-repeat;
background-position: center;
border-radius: 50%;
background-clip: border-box;
transition: background-size 0.2s;
transition-timing-function: cubic-bezier(.07,1.41,.82,1.41);

display: block;
width: 190px;
height: 190px;
text-decoration: none;
cursor: pointer;
overflow: hidden;
text-indent: 100%;
white-space:nowrap;
}

.photo:hover {
background-size: 500px;
}

</style>

Answer

Demo

You need a single <a> tag, style a background to it, give required href to it and make it display: block

html

<a class="photo" href="website.net/link" title="photo" id="photo">photo</a>

css

.photo {
    background-image: url('http://www.thinksnaps.com/wp-content/uploads/2014/07/images-background.jpg');
    background-size: 300px;
    background-repeat: no-repeat;
    background-position: center;
    border-radius: 50%;
    background-clip: border-box;
    transition: background-size 0.2s;
    transition-timing-function: cubic-bezier(.07,1.41,.82,1.41);

    display: block;
    width: 190px;
    height: 190px;
    text-decoration: none;
    cursor: pointer;
    overflow: hidden;
    text-indent: 100%;
    white-space:nowrap;
}

.photo:hover {
    background-size: 500px;
}
Comments