views:

965

answers:

5

I need to make following kind of menu, but I don't know how I can align buttons to left and right with CSS, so that it will work in IE too. Menu should also have fixed height, but that seems to cause some problems..

|Button1|Button2|-----------------------------------------------|Button3|

|table here ------------------------------------------------------------|

|Button1|Button2|-----------------------------------------------|Button3|
+1  A: 

It is so much easier to use a table to do this, why struggle with CSS?

<table>
 <tr>
     <td width="10%" align="left">Button1</td>
     <td width="10%" align="left">Button2</td>
     <td width="80%" align="right">Button3</td>
 </tr>
 <tr>
     <td colspan="3">
        ..inner table..
     </td>
 </tr>
 <tr>
     <td width="10%" align="left">Button1</td>
     <td width="10%" align="left">Button2</td>
     <td width="80%" align="right">Button3</td>
 </tr>

If you really want to do it with CSS, try something like

<div style="width:400px;">   
   <div style="display:inline; float:left;">Button1</div>   
   <div style="display:inline; float:left;">Button2</div>   
   <div  style="display:inline; float:right;">Button3</div>
</div>

 ... etc
Dead account
+ 1 Althought we are told not to use tables... this is a clear to used them in a sensible way.
yeyeyerman
A general problem I see with CSS is maintaining column widths. It's easy with a fixed design, but tables actually give you more flexibility IMHO.
Dead account
A: 

CSS:

.buttonBar
{
  float:left;
  width:100%;
}
.buttonBar .left
{
  float:left;
}
.buttonBar .right
{
  float:right;
}

HTML:

<div class="buttonBar">
  <div class="left">
    <input type="submit" value="Button 1" class="button">
    <input type="submit" value="Button 2" class="button">
  </div>
  <div class="right">
    <input type="submit" value="Button 2" class="button">
  </div>
</div>

<table>
.
.
</table>

<div class="buttonBar">
  <div class="left">
    <input type="submit" value="Button 1" class="button">
    <input type="submit" value="Button 2" class="button">
  </div>
  <div class="right">
    <input type="submit" value="Button 2" class="button">
  </div>
</div>
Charlie
A: 
<div class="wrapper">
  <div class="left">
    Button1
  </div>
  <div class="left">
    Button2
  </div>
  <div class="right">
    Button3
  </div>
</div>
<style type="text/css">
.left{
  float:left;
}
.right{
  float: right;
}
</style>
Marius
A: 

Why don't you use the float attribute?

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Menu</title>
    <style>
        .menu { background:blue;}
        .lbutton {
            background:green;
            float:left;
        }
        .rbutton {
            background:red;
            float:right;
        }
    </style>
  </head>
  <body>
    <h1>Object test</h1>
    <div class="menu">
        <div class="lbutton">button 1</div>
        <div class="lbutton">button 2</div>
        <div class="rbutton">button 3</div>    
    </div>    
  </body>
</html>
tinmaru
+1  A: 

You can do this with CSS and in IE if you force the elements to have the hidden hasLayout property:

<style>
/* allow buttons to display on the same line */
.menu-button { display:inline-block; }

/* make button float on the right */
.menu-button-right { position:relative; display:block; float:right; }
</style>

<div>   
   <div class="menu-button">Button1</div>   
   <div class="menu-button">Button2</div>   
   <div class="menu-button-right">Button3</div>
</div>
Keith
This is good, but I have trouble with IE7 with .menu-button-right, because if I have left element, then it will drop down from the menu... In Firefox and other browser this works allright, but IE7 seems to have this odd problem...
IE usually does - if you have a problem with this layout the absolute alternative sometimes works better in IE. Change the wrapper div to position:relative, then change .menu-button-right to { position:absolute; top:0; right:0; }. Another option is to have the float:right element first.
Keith