I have an image icon in an HTML page that should show right to a label only when some condition is true. If the condition is false, it should not show, but it should still take up the same space.
I’m sure most of you have done something like this and I got a couple of solutions.
- Put the
imgtag as usual but add to its style attributevisibility: hiddenwhen the condition is false. - Specify the
widthandheightstyle attribute for theimgtag and use a transparent 1 X 1 image when the condition is false.
I don’t like either since it seems like pre-CSS 3. Does anyone know the best practice of doing this?
EDIT: When the image does not show, I don’t need the image, but I need its space not to disrupt the positioning of the rest of the elements.
CSS 3 isn’t really supported all that well and still includes most things from 1 and 2 anyway. I see absolutely nothing wrong with your first option.
option 2 is not as clean but certainly viable if you’re expecting it to be viewed by something that doesn’t support CSS.