如何在html的一行中对齐多个按钮?

时间:2019-02-05 07:49:25

标签: html css html5 button tags

我正在将两个按钮对齐到表格中表格正下方的行的中间。

但是按钮的对齐方式现在是垂直的。如何使它们水平并居中。

This is how it is being displayed now

For Joykal Infotech reference in IE after adding vendor prefixes

我想将它们正确对齐到行的中间,并且按钮应该在同一轴上。返回登录名不能为多行。

这就是我尝试过的。

div.blueButton { /* Blue Button sized for submit */
            position:relative;
            margin:0;
            background:transparent url('../images/btn_blue_back.gif') repeat-x;
            color:white;
            padding:0 4px 6px 4px;
            text-align:center;
            width:45px;
            margin-left:520px;
        }
        div.blueButton_left {
            background:transparent url('../images/btn_blue_l.gif') no-repeat left;
            width:7px; height:22px;
            position:absolute;
            top:-2px; left:-2px;    
        }
        div.blueButton_right {
            background:transparent url('../images/btn_blue_r.gif') no-repeat right;
            width:7px; height:22px;
            position:absolute;
            top:-2px; right:-3px;   
        }

a.button, .button {
            width:auto;
            padding:0; margin:0 0 0 0;
            background:#005499;
            font-size:11px; font-weight:bold; color:white; text-decoration:none;
            cursor:pointer;
        }
<div>
<div class="blueButton">
<div class="blueButton_left"></div>
<div class="blueButton_right"></div>
<a href="" onclick="javascript:forgotUsername();return false;" class="button" onblur="javascript:f_setfocus();">Return to LogIn</a>
</div>
<div class="blueButton">
<div class="blueButton_left"></div>
<div class="blueButton_right"></div>
<a href="" onclick="javascript:forgotUsername();return false;" class="button" onblur="javascript:f_setfocus();">Continue</a>
</div>
</div>

2 个答案:

答案 0 :(得分:0)

您可以使用bootstrap并使用带有form-inline类的div 并将两个按钮都放在div中。 将div放入您要显示的td中。

答案 1 :(得分:0)

希望,这可能会有所帮助 我在两个按钮上方都使用了包装器,并提供了display: flex;justify-content:center,还删除了赋予width的固定margindiv.bluebutton

然后结帐flexbox

更新-已添加供应商前缀

.wrap {
  -webkit-display: flex;
  -ms-display: flex;
  -o-display: flex;
  display: flex;
  -webkit-justify-content: center;
  -ms-justify-content: center;
  -o-justify-content: center;
  justify-content: center;
}
div.blueButton {
  /* Blue Button sized for submit */
  position: relative;
  margin: 0;
  background: transparent url('../images/btn_blue_back.gif') repeat-x;
  color: white;
  padding: 0 4px 6px 4px;
  text-align: center;
}

div.blueButton_left {
  background: transparent url('../images/btn_blue_l.gif') no-repeat left;
  width: 7px;
  height: 22px;
  position: absolute;
  top: -2px;
  left: -2px;
}

div.blueButton_right {
  background: transparent url('../images/btn_blue_r.gif') no-repeat right;
  width: 7px;
  height: 22px;
  position: absolute;
  top: -2px;
  right: -3px;
}

a.button,
.button {
  width: auto;
  padding: 0;
  margin: 0 0 0 0;
  background: #005499;
  font-size: 11px;
  font-weight: bold;
  color: white;
  text-decoration: none;
  cursor: pointer;
}
<div class="wrap">
  <div class="blueButton">
    <div class="blueButton_left"></div>
    <div class="blueButton_right"></div>
    <a href="" onclick="javascript:forgotUsername();return false;" class="button" onblur="javascript:f_setfocus();">Return to LogIn</a>
  </div>
  <div class="blueButton">
    <div class="blueButton_left"></div>
    <div class="blueButton_right"></div>
    <a href="" onclick="javascript:forgotUsername();return false;" class="button" onblur="javascript:f_setfocus();">Continue</a>
  </div>
</div>