36

I am designing templates in Channel Advisor for eBay store and it doesn't allow javascript/jQuery. Also, the CSS3 doesn't work in various IE versions specially the img[src=] implementation is broken.

When I use template tags in img like:

<img src="{{THUMB(ITEMIMAGEURL1)}}"/> 

where {{THUMB(ITEMIMAGEURL1)}} is the image path, if the image is missing and the template is posted to eBay then the end result would be like this:

<img src=""/> 

and this shows a broken image.

Is there a way to hide <img src=""/> with HTML or CSS that works in IE7+

Mr. Alien
  • 153,751
  • 34
  • 298
  • 278

3 Answers3

96

You can use [attr=val] selector

img[src=""] {
   display: none;
}

The above selector will simply match, if the src attribute has no value. This selector is a general one and will match all the img tag in the document with an empty src, if you want to target specific ones, than use more specific selector like

.class_name img[src=""] {
    display: none;
}

Demo

Demo (Without the above selector, see that red line?)

Alternatively, if you want to reserve the space taken by img tag, you might like to use visibility: hidden; instead of display: none; as display: none; will simply mess your layout where visibility: hidden; will reserve the space, it will just hide the img

See the difference between display: none; and visibility: hidden;

Demo (visibility: hidden;, reserves space)

Demo 2 (display: none;, won't reserve space)


Note: None of the above selectors will REMOVE the img tag from the DOM, it will simply hide it from the front end

Mr. Alien
  • 153,751
  • 34
  • 298
  • 278
  • 1
    For SEO issues leaving `src` empty is not good that's why I personally use `#` as src. The global Seo friendly selector would be `img[src=""], img[src="#"], img:not([src])` – Farzad Yousefzadeh Jul 12 '16 at 11:39
10

[attr=value] selector is CSS2, you should be ok.

img[src=""] {
  display:none;
}
Mr. Alien
  • 153,751
  • 34
  • 298
  • 278
Shalom Aleichem
  • 2,987
  • 2
  • 22
  • 34
0

If src attribute is missing altogether:

img:not([src]), img[type='src'], img[type='src'] {
display:none !important;
}

Reference

estinamir
  • 435
  • 5
  • 11