4

I have a banner on a website with the following less/css class:

.element-link {
    display: block;
    background: url('url to image') repeat-x center center; 
    height: 71px; 
    background-size: cover; 
    cursor: pointer; 
    width: 100%;
  }

and the html

<a class="element-link" href="url to other site" target="_blank"></a>

But, when there is no images on url('url to image') (This is a border case, but we must to resolve it), the banner doesn't appears (that's good, it gave us the flexibility to remove banners simply deleting the image in the server), BUT the link continues to work.

EDIT: So, what I need to do is: detect that there is no image on

background: url('url to image') repeat-x center center 

and in that case change the height: 71px; to height: 0px; I know that I can do this in javascript, but because the site is not mine, I want to know if I could do this in less before offer them a javascript solution.

Nisanio
  • 4,056
  • 5
  • 34
  • 46
  • 2
    Possible duplicate of [Is it possible to detect broken/unloaded (error) images with CSS?](http://stackoverflow.com/questions/21148820/is-it-possible-to-detect-broken-unloaded-error-images-with-css) – War10ck Sep 12 '16 at 16:04
  • Could you please explain what you are trying to achieve in a more detailed manner? As far as I understand your question, you want to somehow detect a broken image link and also delete it? – Anselm Sep 12 '16 at 16:04
  • If you use a backend language, you can CURL to the image URL to see in advance if this URL is still valid – The One and Only ChemistryBlob Sep 12 '16 at 16:05
  • I understand you wanting to use something you already employ to do this but what would be the advantage of not using jQuery, something that is basically tailor-made for doing these things? That's really the question you should be asking. – Kyle L. Sep 12 '16 at 16:06
  • @War10ck This is not a duplicate because detecting broken background images in CSS is a whole other issue! – Anselm Sep 12 '16 at 16:06
  • CSS can't **detect** anything. It can only style based on a rule. So your answer is NO / YOU CAN'T – Paulie_D Sep 12 '16 at 16:14

0 Answers0