0

Vertical align top (valign="top") help needed

asked 2009-03-03 16:22:15 +0800

sreed gravatar image sreed
195 1 3 5

updated 2009-03-03 21:00:35 +0800

I am trying to include a side bar with a little menu. I want the side bar (vbox) to take up the whole left side (height="100%") but I want the menu items (toolbarbuttons) to be vertically aligned at the top of the bar. I have attached some test code here with three versions of the sidebar that shows how setting valign="top" height="100%" behaves.

What happens depends on the browser. In Firefox, the height="100%" vboxes fill up the vertical space. In IE all the vboxes ignore the height attribute. For the case where height is not specified, the items are packed together in either IE or Firefox but then the sidebar is not the full height.

What am I doing wrong?

Is valign="top" not supposed to align everything at the top or is it a bug?

Why doesn't height="100%" work in IE?

I found a work-around (the fourth version in my example) to get the behavior I want in Firefox with nested vboxes, the outer vbox with height="100%" and the inner vbox with height not specified, but I consider this an inelegant option.

<?page title="Test Vertical Align Top" contentType="text/html;charset=UTF-8"?>
<zk>
  <window title="Test Vertical Align Top" border="normal">
    <hbox height="400px">
      <hbox height="100%" spacing="10px" style="background:#E0E0E0;">
        <vbox height="100%" valign="top" style="background:#E0F0E0;">
          <label value="height='100%' valign='top'"/>
          <toolbarbutton label="1 home" href="index.html" />
          <toolbarbutton label="1 contact us" href="contact.html" />
        </vbox>
        <vbox height="100%" style="background:#E0F0E0;">
          <label value="height='100%'"/>
          <toolbarbutton label="2 home" href="index.html" />
          <toolbarbutton label="2 contact us" href="contact.html" />
        </vbox>
        <vbox style="background:#E0F0E0;">
          <label value="no height, no valign"/>
          <toolbarbutton label="3 home" href="index.html" />
          <toolbarbutton label="3 contact us" href="contact.html" />
        </vbox>
        <vbox height="100%" style="background:#E0F0E0;">
          <vbox>
            <label value="nested vboxes, no height, no valign"/>
            <toolbarbutton label="4 home" href="index.html" />
            <toolbarbutton label="4 contact us" href="contact.html" />
            <label value="this is what I thought"/>
            <label value="height='100%' valign='top'/>
            <label value="would look like"/>
          </vbox>
        </vbox>
      </hbox>
    </hbox>
  </window>
</zk>

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2009-03-04 02:10:00 +0800

hideokidd gravatar image hideokidd
750 1 2

updated 2009-03-04 02:12:03 +0800

Hi,

For the vbox

<vbox height="100%" valign="top" style="background:#E0F0E0;">

Alignment got wrong because vbox will distribute the same height to its children components if its height is defined. So, for the last vbox, although you thought it's not a good solution, for specification of vbox that is an appropriate way to your purpose.

For the browser issue of the vbox

<vbox height="100%" style="background:#E0F0E0;">

I think that's because IE has its way to deal with vbox and hbox, no matter what attribute you set. In my test the height of hbox is much shorter than one in Firefox.

Thanks.

link publish delete flag offensive edit

answered 2009-03-04 03:57:36 +0800

sreed gravatar image sreed
195 1 3 5

hideokidd: "Alignment got wrong because vbox will distribute the same height to its children components if its height is defined. So, for the last vbox, although you thought it's not a good solution, for specification of vbox that is an appropriate way to your purpose."

Thank you for explaining it. It helps a lot just to understand why it is happening even if I don't like it. :-)

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-03-03 16:22:15 +0800

Seen: 2,799 times

Last updated: Mar 04 '09

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More