I want to show an image with the link on the menubar. My code is as below:
<a href="#" class="login" title="Login"></a>
The login class in css is as below:
.login{background: url(../img/user.png) no-repeat 6px center;}
But, I am not able to view the image in the browser. If I tried like
<a href="#" class="login" title="Login">Login</a>
then image appears in the background. But I want to use only image and not the text. how can I do that?
You'll have to set dimensions on the a tag, and set it to display: block; . Of course replace dimensions with the correct ones. If you add the image directly to the a tag like you have at the bottom of your answer, the anchor seems to overflow underneath the image a little bit.
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.
You can also set an image as the background of an HTML element rather than the entire web page. For example, you could place HTML elements inside a div, then target the div with the CSS properties we used above.
You'll have to set dimensions on the a
tag, and set it to display: block;
.
.login { background: url(../img/user.png) no-repeat 6px center; width: 100px; height: 100px; display: block; }
Of course replace dimensions with the correct ones.
Alternatively you could put the image directly into the a
tag like so:
<a href="#" class="login" title="Login"><img src="../img/user.png" /></a>
You can use the following:
<a href="#" class="login" title="Login"><img src="../img/user.png" /></a>
EDIT: I forgot to mention this would mean you have to remove the background image from your CSS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With