Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML and CSS: using background image as a clickable link

Tags:

html

css

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>
like image 782
user25976 Avatar asked Aug 21 '14 09:08

user25976


People also ask

How do you make a background image clickable in CSS?

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 use an image as a background link in HTML?

The most common & simple way to add background image is using the background image attribute inside the <body> tag. The background attribute which we specified in the <body> tag is not supported in HTML5. Using CSS properties, we can also add background image in a webpage.

How do you make an image clickable in HTML?

How To Create A Clickable Image In HTML? The <img> and the <a> tags together is the most common way of adding a clickable image link in HTML. In a webpage, after adding an image using the <img> tag, make it clickable by adding a <a> tag along with it.


1 Answers

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;
}
like image 106
4dgaurav Avatar answered Sep 28 '22 08:09

4dgaurav