By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,625 Members | 2,250 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,625 IT Pros & Developers. It's quick & easy.

vertical-align:bottom not working

P: n/a
Hi

I have a strange problem with vertical-align. The case can be viewed at
http://www.brainput.info/geschichte.html.

HTML code:

<div id="bild"><img src="geschichte.gif" width="274" height="29" alt="Wir
schreiben die Geschichte Ihres Unternehmens."></div>

CSS code:

#bild {
width: 600px;
height: 76px;
margin: 0px 0px 0px 50px;
vertical-align:bottom;
}

img {
vertical-align:top;
}

#bild img {
vertical-align:bottom;
}

Now the image should be displayed at the bottom of the div, or am I wrong?
Both IE6 and Netscape 7 display it at the top.

Strange enough: Adding "text-align:right" to the "#bild img" definition is
not working either, but when I add "border:5px solid blue" the image will be
displayed with the blue border. So the selectors must be correct.

I am quite stuck; if somebody sees where the mistake is I will be very happy
about it.

Thanks
Markus
Jul 20 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
In article Markus Ernst wrote:
Hi

I have a strange problem with vertical-align. The case can be viewed at
http://www.brainput.info/geschichte.html.
It is because you have misunderstood how vertical-align works.
Now the image should be displayed at the bottom of the div, or am I wrong?
Both IE6 and Netscape 7 display it at the top.
You are wrong. Use line-height. See this thread (about centering):
http://gogle.de/gr******************...ews.cis.dfn.de
Strange enough: Adding "text-align:right" to the "#bild img" definition is
not working either, but when I add "border:5px solid blue" the image will be
displayed with the blue border. So the selectors must be correct.


Thats because vertical-align only aplies to inline-elements, and text-
align only to block elements.

--
Lauri Raittila <http://www.iki.fi/lr> <http://www.iki.fi/zwak/fonts>
Saapi lähettää meiliä, jos aihe ei liity ryhmään, tai on yksityinen
tjsp., mutta älä lähetä samaa viestiä meilitse ja ryhmään.

Jul 20 '05 #2

P: n/a
Lauri Raittila wrote:
Thats because vertical-align only aplies to inline-elements, and text-
align only to block elements.


'text-align' does not apply to block-level elements. It does apply to
inline elements as well ;-)
--
Anne van Kesteren
<http://www.annevankesteren.nl/>
Jul 20 '05 #3

P: n/a
In article Anne van Kesteren wrote:
Lauri Raittila wrote:
Thats because vertical-align only aplies to inline-elements, and text-
align only to block elements.


'text-align' does not apply to block-level elements. It does apply to
inline elements as well ;-)


I used term applies in the meaning CSS has for it. Spec clearly says that
that text-align only applies to block elements.

http://www.w3.org/TR/CSS2/text.html#alignment-prop
| Applies to: block-level elements

http://www.w3.org/TR/CSS21/text.html#alignment-prop
| Applies to: block-level elements and table cells
--
Lauri Raittila <http://www.iki.fi/lr> <http://www.iki.fi/zwak/fonts>
Saapi lähettää meiliä, jos aihe ei liity ryhmään, tai on yksityinen
tjsp., mutta älä lähetä samaa viestiä meilitse ja ryhmään.

Jul 20 '05 #4

P: n/a
Markus Ernst wrote:
Hi

I have a strange problem with vertical-align. The case can be viewed at
http://www.brainput.info/geschichte.html.

HTML code:

<div id="bild"><img src="geschichte.gif" width="274" height="29" alt="Wir
schreiben die Geschichte Ihres Unternehmens."></div>

CSS code:

#bild {
width: 600px;
height: 76px;
margin: 0px 0px 0px 50px;
vertical-align:bottom;
}

img {
vertical-align:top;
}

#bild img {
vertical-align:bottom;
}

Now the image should be displayed at the bottom of the div, or am I wrong?
Both IE6 and Netscape 7 display it at the top.
Lauri refers you to this link:
http://gogle.de/gr******************...ews.cis.dfn.de

A summary of the findings is:
1. The nice and quite proper use of vertical-align: middle applied to an
image within a parent div that has a height and line-height of equal size
(10em) unfortunately only works in Opera and Mozilla, IE6 just leaves the
image sitting stubbornly at the top of the div.
2. Lauri then gets quite inventive with the css but it would be so much more
simple if IE6 just behaved as Opera and Mozilla.

Strange enough: Adding "text-align:right" to the "#bild img" definition is
not working either, but when I add "border:5px solid blue" the image will
be displayed with the blue border. So the selectors must be correct.


I thought I would add to what Lauri has replied to you by putting it in
simple terms that I understand:

"This property describes how inline content of a block is aligned. " (as
per CCS 2 - CSS2.1 includes table cells as well)

So, this property will affect the alignment of inline content inside a block
level element (or inside a table cell), therefore you apply the property to
the block level element and not to the inline content - see below
<div style="text-align: right;">
<img src="myimage.gif" width=200 height=400 alt="">
</div>

this will align the image to the right side of the div. It would not be
correct to apply the property directly to the inline content, so the
following would not produce the desired affect:

<div>
<img style="text-align: right;" src="myimage.gif" width=200 height=400
alt="">
</div>

Of course, inline style is bad, only did this to make it easier to follow.
Your descendent selector (#bild img) was OK but that was not the cause of
your problem - your problem was as I have pointed out above i.e your
targetting the wrong element

HTH
David



Jul 20 '05 #5

P: n/a
"Lauri Raittila" <la***@raittila.cjb.net> schrieb im Newsbeitrag
news:MP************************@news.cis.dfn.de...
In article Markus Ernst wrote:
Hi

I have a strange problem with vertical-align. The case can be viewed at
http://www.brainput.info/geschichte.html.


It is because you have misunderstood how vertical-align works.
Now the image should be displayed at the bottom of the div, or am I wrong? Both IE6 and Netscape 7 display it at the top.


You are wrong. Use line-height. See this thread (about centering):
http://gogle.de/gr******************...ews.cis.dfn.de
Strange enough: Adding "text-align:right" to the "#bild img" definition is not working either, but when I add "border:5px solid blue" the image will be displayed with the blue border. So the selectors must be correct.


Thats because vertical-align only aplies to inline-elements, and text-
align only to block elements.

--
Lauri Raittila <http://www.iki.fi/lr> <http://www.iki.fi/zwak/fonts>
Saapi lähettää meiliä, jos aihe ei liity ryhmään, tai on yksityinen
tjsp., mutta älä lähetä samaa viestiä meilitse ja ryhmään.


Thank you for pointing me to this very interesting thread. As IE does not
support the line-height solution I did the real cross-browser thing - I
added the white space to the images so that they all have the same height
and the visible part is where I want it to be.

Actually I wonder why vertical-align:bottom was not specified as applicable
for block elements to align at the bottom of the parent element. So it would
be easy to define the image as display:block to put it at the bottom of the
parent element, as easy as the old <td valign="bottom"> way was. Well maybe
this is a stupid idea, but I think the biggest problem in the actual
specification and implementations of CSS is that it needs big discussions
for small problems, so I hope the focus in the further development is on the
ease of use.

Thanks a lot for your help!
Markus
Jul 20 '05 #6

P: n/a
"David Graham" <da************@ntlworld.com> schrieb im Newsbeitrag
news:kz******************@newsfep1-win.server.ntli.net...

Of course, inline style is bad, only did this to make it easier to follow.
Your descendent selector (#bild img) was OK but that was not the cause of
your problem - your problem was as I have pointed out above i.e your
targetting the wrong element

HTH
David


Thank you for this hint - it's really obsolete to do a test if I do it on
the wrong element :-)

Markus
Jul 20 '05 #7

P: n/a
In article Markus Ernst wrote:
"Lauri Raittila" <la***@raittila.cjb.net> schrieb im Newsbeitrag
news:MP************************@news.cis.dfn.de...
http://gogle.de/gr******************...ews.cis.dfn.de

Thank you for pointing me to this very interesting thread.
I made a webpage about that subject finally, and managed to invent 2 more
ways to vertically center in process...
http://www.student.oulu.fi/~laurirai/www/css/middle/

One of those worked in all browsers I tested, and that is the one that
breaks most likely, when em/px ratio is different...

But I think I have made some mistake, as it seems strange how badly
Mozilla renders three of the examples. So if someone would look it with
something else than 1.4 mozilla, I would like to hear.
As IE does not
support the line-height solution I did the real cross-browser thing - I
added the white space to the images so that they all have the same height
and the visible part is where I want it to be.
Well, Adding them just right amount of margin would have been good too.
Actually I wonder why vertical-align:bottom was not specified as applicable
for block elements to align at the bottom of the parent element. So it would
be easy to define the image as display:block to put it at the bottom of the
parent element, as easy as the old <td valign="bottom"> way was.
It is good question. OTOH, it would have been third definition for same
property.
Well maybe
this is a stupid idea, but I think the biggest problem in the actual
specification and implementations of CSS is that it needs big discussions
for small problems, so I hope the focus in the further development is on the
ease of use.


The problem with ease of use is that it is not necessarily very fast.
When designing principles of CSS vere done, my P200 would have been very
high tech machine. If CSS would have made differently, I bet I could not
surf with this machine as well as I can now.

And, it is hard to think something easier to use.

Anyway, more steps are taken toward ease of use in CSS3.


--
Lauri Raittila <http://www.iki.fi/lr> <http://www.iki.fi/zwak/fonts>
Saapi lähettää meiliä, jos aihe ei liity ryhmään, tai on yksityinen
tjsp., mutta älä lähetä samaa viestiä meilitse ja ryhmään.

Jul 20 '05 #8

P: n/a
"Lauri Raittila" <la***@raittila.cjb.net> schrieb im Newsbeitrag
news:MP************************@news.cis.dfn.de...
In article Markus Ernst wrote:
"Lauri Raittila" <la***@raittila.cjb.net> schrieb im Newsbeitrag
news:MP************************@news.cis.dfn.de...
http://gogle.de/gr******************...ews.cis.dfn.de
Thank you for pointing me to this very interesting thread.
I made a webpage about that subject finally, and managed to invent 2 more
ways to vertically center in process...
http://www.student.oulu.fi/~laurirai/www/css/middle/

One of those worked in all browsers I tested, and that is the one that
breaks most likely, when em/px ratio is different...

But I think I have made some mistake, as it seems strange how badly
Mozilla renders three of the examples. So if someone would look it with
something else than 1.4 mozilla, I would like to hear.


Netscape 7.0 (I am sorry I don't find out on which Mozilla version it is
based):
- Line-height: Image 2 px below middle
- Absolute positioning: Text 2 px below middle
- Table-cell: different height (seems to behave like border-box model)
- Padding and negative margin: as absolute positioning
- Relative positioning and negative margin: Broken (Text on top, image
overlaps top)
- Absolute positioning and negative margin: as absolute positioning

I also have installed Mozilla 1.0, seems to behave exactly the same.
As IE does not
support the line-height solution I did the real cross-browser thing - I
added the white space to the images so that they all have the same height and the visible part is where I want it to be.


Well, Adding them just right amount of margin would have been good too.


Yes but it is more complicated to handle as it is necessary to calculate the
extra space for every single image and apply it as inline style.
Anyway, more steps are taken toward ease of use in CSS3.


As a user of graphic layout softwares I am looking forward to using the
border box model :-). Nowadays it is impossible to mix percent values with
other values. A width or height of 100% and a padding of 2em causes a
scrollbar. This will be much better with a border-box model.

A really huge improvement would be calculating CSS:
#menu {
width:20em;
}
#contents {
margin: 2em;
border: solid 3px;
width: (100% - 20em - 4em - 6px);
}

Or even better with reference to other elements:
#menu {
width:20em;
min-width:200px /* width of logo graphic */
}
#contents {
margin: 2em;
border: solid 3px;
width: (100% - #menu.width - 4em - 6px);
}

Will need a lot of CPU power of course...

--
Markus
Jul 20 '05 #9

P: n/a
In article Markus Ernst wrote:
"Lauri Raittila" <la***@raittila.cjb.net> schrieb im Newsbeitrag
news:MP************************@news.cis.dfn.de...
vertically center
http://www.student.oulu.fi/~laurirai/www/css/middle/ But I think I have made some mistake, as it seems strange how badly
Mozilla renders three of the examples. So if someone would look it with
something else than 1.4 mozilla, I would like to hear.
I found out that Mozilla didn't like positioning and floating at same
time after I posted that, and that it incorrectly floated but not
positioned. (it should have positioned but not floated if it was
following spec.)
Netscape 7.0 (I am sorry I don't find out on which Mozilla version it is
based):
- Line-height: Image 2 px below middle
- Absolute positioning: Text 2 px below middle
- Table-cell: different height (seems to behave like border-box model)
- Padding and negative margin: as absolute positioning
- Relative positioning and negative margin: Broken (Text on top, image
overlaps top)
- Absolute positioning and negative margin: as absolute positioning

I also have installed Mozilla 1.0, seems to behave exactly the same.
Thanks. I never checked exact pixels, so I think they were rendered just
as Mozilla 1.4.
Anyway, more steps are taken toward ease of use in CSS3.


As a user of graphic layout softwares I am looking forward to using the
border box model :-). Nowadays it is impossible to mix percent values with
other values. A width or height of 100% and a padding of 2em causes a
scrollbar. This will be much better with a border-box model.


Of course, the CSS property that changes mode to border box, works
already on many browsers. I'm not sure about IE6 or khtml, but at least
Opera, Mozilla and MacIE.
A really huge improvement would be calculating CSS
Or even better with reference to other elements


Both are suggested many times, but I don't think they are coming. At
least the latter isn't.
--
Lauri Raittila <http://www.iki.fi/lr> <http://www.iki.fi/zwak/fonts>
Saapi lähettää meiliä, jos aihe ei liity ryhmään, tai on yksityinen
tjsp., mutta älä lähetä samaa viestiä meilitse ja ryhmään.

Jul 20 '05 #10

P: n/a
"Lauri Raittila" <la***@raittila.cjb.net> schrieb im Newsbeitrag
news:MP************************@news.cis.dfn.de...
A really huge improvement would be calculating CSS
Or even better with reference to other elements


Both are suggested many times, but I don't think they are coming. At
least the latter isn't.


Yes I was afraid I was not the first one to have these ideas ;-)

--
Markus
Jul 20 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.