CSS菜单,其中按钮等可以左右对齐

时间:2009-08-05 09:42:59

标签: css internet-explorer

我需要制作以下类型的菜单,但我不知道如何使用CSS左右对齐按钮,这样它也可以在IE中使用。菜单也应该有固定的高度,但这似乎会导致一些问题..

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

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

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

5 个答案:

答案 0 :(得分:4)

如果强制元素具有隐藏的hasLayout属性,则可以使用CSS和IE执行此操作:

<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>

答案 1 :(得分:1)

使用表格这么容易,为什么要与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>

如果你真的想用CSS做,可以试试

<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

答案 2 :(得分:0)

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>

答案 3 :(得分:0)

<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>

答案 4 :(得分:0)

为什么不使用float属性?

<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>