Add link to image by * .CSS file

1

I have a *.css file that determined the position and size of the image I have in my header, you can add a hyperlink to that image in the *.css file itself, and then when I assign that image that id file *.css does it already take the link too?

    
asked by anonymous 27.06.2017 / 21:49

1 answer

4

In CSS there is no property that can handle the image file of the img element. If this is really the case I suggest you to switch to the div element and specify the image in CSS

Example:

CSS:

#div_img {
  background-image:url('http://www.sitedaimagem.com/img/header.png'); /* url */
  width:396px; /* largura */
  height:153px; /* altura */
}

HTML:

<div id="div_img"></div>

1 # Edited:

Via CSS it is not possible to manipulate the link, or you set it directly in HTML or JavaScript

2 # Edited:

New example using JQuery: CSS:

#div_img {
  background-image:url('http://www.sitedaimagem.com/img/header.png'); /* url */
  width:396px; /* largura */
  height:153px; /* altura */
}

HTML:

<a id="div_link" href="http://www.uol.com.br"><div id="div_img"></div></a>

JQuery:

$(document).ready(function() {
  $('#div_link').attr('href','http://www.google.com');
})
    
27.06.2017 / 22:07