473,396 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

<img> placed in unexpected position

Hey, I've come across a strange behaviour that shows itself in IE 7.0
and Firefox 3 and probably other browsers.

In the code below, which is a complete HTML document which validates
as XHTML 1.0 Strict, I display an image named Images/DivLine1.jpg
(which is a simple 1x5 pixel blue line) inside two divs across 100% of
their width, the first of which has 50px height and the second of
which has 100px height. In both cases, I set the image to vertical-
align:bottom, and I expect the image to rest against the bottom of the
div box. But in each case, the bottom of the image is displayed at
(apparently) exactly 20 pixels from the top of the div. What is going
on?

--------------------code--------------------
<!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" xml:lang="en" lang="en">

<head>
<title>Test</title>
</head>

<body>

<div style="background-color:red; height:50px;"><img src="Images/
DivLine1.jpg" alt="DivLine1" width="100%" height="5px" style="vertical-
align:bottom" /></div>
<div><br /></div>

<div style="background-color:red; height:100px;"><img src="Images/
DivLine1.jpg" alt="DivLine1" width="100%" height="5px" style="vertical-
align:bottom" /></div>

</body>

</html>
--------------------code--------------------

Thanks,

bgold12
Aug 18 '08 #1
4 1969
In article
<93**********************************@m73g2000hsh. googlegroups.com>,
bgold12 <bg*****@gmail.comwrote:
Hey, I've come across a strange behaviour that shows itself in IE 7.0
and Firefox 3 and probably other browsers.

In the code below, which is a complete HTML document which validates
as XHTML 1.0 Strict, I display an image named Images/DivLine1.jpg
(which is a simple 1x5 pixel blue line) inside two divs across 100% of
their width, the first of which has 50px height and the second of
which has 100px height. In both cases, I set the image to vertical-
align:bottom, and I expect the image to rest against the bottom of the
div box. But in each case, the bottom of the image is displayed at
(apparently) exactly 20 pixels from the top of the div. What is going
on?

--------------------code------

There are many things to puzzle about with inline images, what quite is
puzzling you about

<http://netweaver.com.au/alt/inlineImages/twoDivs.html>

It will help you to see what is going on if you keep changing the text
size (up the point of the text wrapping)

--
dorayme
Aug 18 '08 #2
In article <do**********************************@web.aioe.org >,
dorayme <do************@optusnet.com.auwrote:
In article
<93**********************************@m73g2000hsh. googlegroups.com>,
bgold12 <bg*****@gmail.comwrote:
Hey, I've come across a strange behaviour that shows itself in IE 7.0
and Firefox 3 and probably other browsers.

In the code below, which is a complete HTML document which validates
as XHTML 1.0 Strict, I display an image named Images/DivLine1.jpg
(which is a simple 1x5 pixel blue line) inside two divs across 100% of
their width, the first of which has 50px height and the second of
which has 100px height. In both cases, I set the image to vertical-
align:bottom, and I expect the image to rest against the bottom of the
div box. But in each case, the bottom of the image is displayed at
(apparently) exactly 20 pixels from the top of the div. What is going
on?

--------------------code------


There are many things to puzzle about with inline images, what quite is
puzzling you about

<http://netweaver.com.au/alt/inlineImages/twoDivs.html>

It will help you to see what is going on if you keep changing the text
size (up the point of the text wrapping)
make that

<http://netweaver.com.au/alt/inlineImages/twoDivs.html>

for an extra one with a div given a height. Remember that an inline
image is a bit like a bit of type, it will start whee the text line
boxes start in a div, left and top and the div will normally grow height
to accommodate. If you give the div a height, the height is not
necessirly used. The vertical-align instruction is not with respect to
the div but to the line box in which text sits. Images can be very tall
(like a big capital P).

--
dorayme
Aug 18 '08 #3
Alright, I solved it.

Apparently the CSS statement "vertical-align:bottom;" aligns the image
to the bottom of the element's line-height, not it's height. Although
I set the height of the first div to 50px and the height of the second
div to 100px, the line-height of each div was 20px, so when I set the
image to vertical-align:bottom, it aligned the bottom edge of the
image to 20px from the top of the div (i.e. at the line-height).

bgold12
Aug 18 '08 #4
On 18 Aug, 06:09, bgold12 <bgol...@gmail.comwrote:
In the code below, which is a complete HTML document which validates
as XHTML 1.0 Strict,
* * * * <div style="background-color:red; height:100px;"><img src="Images/
DivLine1.jpg" alt="DivLine1" width="100%" height="5px" style="vertical-
align:bottom" /></div>
It might be valid, but it doesn't conform to the HTML recommendation.
width and height attributes on an image are a legacy from old
presentational HTML and use their own way of indicating units, not the
same as CSS lengths. width="100%" is OK, but height="5px" should just
be height="5" Once you're using non-conformant code like this,
anything could happen. The first step in investigating such issues,
particularly when there's a variation across browsers, is to make sure
the code is _perfect_.
Aug 18 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Gianpiero Colagiacomo | last post by:
VBScript: Can anyone help me figure out why the image within this IF statement shows as a place holder rather than the image itself when the statement is returning true? If I remove the IF...
15
by: Philipp Lenssen | last post by:
My friend has the following problem (background: we want to transform XML to XHTML via XSLT): "We copy XHTML fragments into an output by using the following template: <xsl:template match="*"...
5
by: MyndPhlyp | last post by:
I've been busting my head trying to figure this out for quite some time. With IE6 and NS7, no problems. I can simply code the HTML <img height="100%"> and be done with it. But NS4 and NS6 (and...
15
by: Gérard Talbot | last post by:
Hello all, I'd like to know and understand the difference between, say, <img src="/ImageFilename.png" width="123" height="456" alt=""> and <img src="/ImageFilename.png" style="width:...
3
by: Henry Johnson | last post by:
Okay - I'm spinning my wheels on this one... can someone help me figure out how to programmatically populate a table cell as follows (from C# code-behind)? I've tried using a Literal control in the...
4
by: johanvdv | last post by:
Hello, I'm building a website which contains a floor plan of my house. I want to indicate if some lights in my house are on or off. I thought I found a good way to do it with...
1
by: Carl | last post by:
Hi all I have a javascript function that drags and drops an element (ie img) into a container (ie bordered div). The function works and returns the element and and container. My next step is to...
4
by: SammyBar | last post by:
Hi all, I wonder is it possible to upload the content of an <imgfield to a server. The content of the <imgwas downloaded from a web site different from the one it should be uploaded. The image...
4
by: Jon Slaughter | last post by:
I have a captcha system going and for some reason when I use <?php $s = ""; for($i = 0; $i < 10; $i++) { $s = $s.rand(0,9); } $_SESSION = $s; $fn = '/Login/Register/Captcha.php'; echo '<img...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.