473,803 Members | 3,833 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

<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="backgrou nd-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="backgrou nd-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 1989
In article
<93************ *************** *******@m73g200 0hsh.googlegrou ps.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.a u/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.aio e.org>,
dorayme <do************ @optusnet.com.a uwrote:
In article
<93************ *************** *******@m73g200 0hsh.googlegrou ps.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.a u/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.a u/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="backgrou nd-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
2357
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 the image shows... <% If (events.Fields.Item("picURL").Value) <> "" Then
15
3098
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="*" mode="xhtml"> <xsl:element name="{local-name()}"> <xsl:copy-of select="@*"/> <xsl:apply-templates mode="xhtml"/> </xsl:element>
5
2856
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 probably a couple of other IE and NS versions I can't get to right now) don't want to play nice unless I hard code the image height. (Yes, I'm one of those who insists on still coding for NS4.)
15
122169
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: 123px; height: 456px;" alt="">
3
5455
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 TableCell, a HyperLink control, and an Image, but I'm not getting the results I want. Here's the source of what I'm after (retrieved by viewing the source of a page I'm trying to emulate): <td><a...
4
1324
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 filter.lights.addPoint (IE only) but this has a limit of 10, which is not enough. Has anyone has an idea how to archive this ? How can I add images to an existing image on a certain position ?
1
4628
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 center the element in the container if the user is sloppy with positioning it. I can only test this on IE6 and IE5.5 and it fails. It positions the element too much right and low. Here is the function: function SnapToContainer(Container,El) {
4
9092
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 file should not be saved locally before uploading. It should not be visible any <input type=file on the form. How can it be done? I'm working on a project where client javascript requests an image server to generate dynamic images. The client...
4
2016
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 src="'.$fn.'" alt="Captcha" />'; ?>
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10289
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10068
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9119
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7600
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6840
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4274
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3795
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.