Search code examples
csshtmlbuttontags

How to align multiple buttons inside a row in html?


I am working on aligning two buttons to the middle of the row which is just below a table in the form.

But the alignment of buttons is vertical now. How do I make them horizontal and to the middle.

This is how it is being displayed now

For Joykal Infotech reference in IE after adding vendor prefixes

I want to align them properly to the middle of the row and the buttons should be on same axis. Return to Login should not be in multiple lines.

Here's what I tried.

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>


Solution

  • Hope, this might help I have used a wrapper above both the buttons and provided display: flex; and justify-content:center and also removed the fixed width and margin given to div.bluebutton

    And do checkout flexbox

    Update - vendor prefixes added

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