I have the following code:
<div>
<img src="../images/curry.jpg" height="242" width="300"
alt="Can't find image (http://localhost/images/curry.jpg)">
</div>
I am trying to precisely lay out a page so, even if the image is not found, I would like the Alt text to occupy the given height & width.
1) is that now how HTML/CSS works?
2) if not, since I generating the HTML from PHP, is there anything I can do to achieve what I want? For instance, would it work if I check for non-existence and instead of an IMG tage, generate a Fieldset of the desired size, containing my Alt text?
The answer to you first question is Yes. Alt attribute is for SEO purposes, and behaves as you have seen it.
It is possible although I must warn you of additional overhead, there is a function file_exists() to check if the image is existent.
If that function returns false instead of echoing the image just echo
"<p>Can't find image (http://localhost/images/curry.jpg)</p>
"
and add a style attribute to the wrapping div that states your desired width and height
<div style='height: 242px;width: 300px'>
If you're generating the page using PHP you can just fix the width / height of the div.
As for the "Alt Text" could you show a small screenshot of what you want? I don't really understand by what you mean by occupying the given size.
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