Forum Moderators: not2easy

Message Too Old, No Replies

absolute img positionning and XHTML

can we use it?

         

irotte

6:38 pm on Mar 1, 2004 (gmt 0)

10+ Year Member



When I begin my file with this:
<html>
<head>

wich is a plain HTML syntax, I can easely position my image using this code:
<DIV ID="image1" STYLE="position:absolute; top:125; left:0;">
<IMG SRC="image.gif" BORDER="0" alt="blablabla" width="20" height="20">
</DIV>

If I begin the file with this:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

I really don't get the same results for the same img code. What to do?

HarryM

7:31 pm on Mar 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



XHTML need units of measure specified. Try changing top:125; to top:125px; etc. Also width="20" should be width="20px" etc.

If that doesn't work try validating the page. This should always be done anyway - it shows up all sorts of problems.

Another point is that XHTML is case sensitive, and the recommendation is to use lower case for tags and attributes.

irotte

7:52 pm on Mar 1, 2004 (gmt 0)

10+ Year Member



thank you very much HarryM!

grahamstewart

10:54 pm on Mar 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



also width="20" should be width="20px" etc

No, it should just be width="20". CSS requires a unit of measurement but HTML always uses pixels unless you specify it as a percentage.

See [w3.org...] for the W3C DTD definition of length in HTML.

Purple Martin

1:10 am on Mar 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



grahamstewart gave the link to the HTML DTD, and as the question is specifically about XHTML I looked up the XHTML DTD. I was surprised to find that XHTML also always uses pixels unless you specify it as a percentage.

<!ENTITY % Length "CDATA">
<!-- nn for pixels or nn% for percentage length -->

[w3.org...]

HarryM

1:44 am on Mar 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, it should just be width="20".

Yes, you're right. I removed a "px" from one of my pages and it still validated.

HarryM

12:48 pm on Mar 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



irotte,

As I mentioned before it would be worthwhile validating your pages. For instance, I have just noticed something else in your code that is invalid in XHTML.

Your <IMG SRC="image.gif" BORDER="0" alt="blablabla" width="20" height="20"> should end height="20" /> (with a space between the "20" and the /> ). All tags have to be closed. For instance a <br> tag must be written <br />, and a <p> tag must be followed by a </p> tag, etc.

All this stuff is actually very simple and an easy habit to get into. One advantage is that a page written in valid XHTML will also work as HTML.