Jaron787
Jaron787

Reputation: 560

Button Positioning within div

What is the best way to get button 3 & 4 in a vertical column next to button 1 & 2. I thought about putting them within a table to separate them but wanted to see if there was a better idea in CSS ?

Below working example: https://jsfiddle.net/Jaron787/0te3cs66/1/

Code:

HTML

<div id="lse" class="display">
  <div id="centertbl">
    <table id="tblData" class="TSS">
      <tr>
        <td align="center" colspan="4"><b>Table 1</b></td>
      </tr>
    </table>

    <table id="tblData" class="TSS">
      <tr>
        <td align="center" colspan="4"><b>Table 2</b></td>
      </tr>
    </table>
  </div>

  <input type="submit" class="button button1" name="submitButton" value="Button 1">
  <input type="submit" class="button button1" name="submitButton" value="Button 2">
  <input type="submit" class="button button1" name="submitButton" value="Button 3">
  <input type="submit" class="button button1" name="submitButton" value="Button 4">

CSS

</div>

.TSS {
  border: 1px solid #000000;
  float: none;
  font-family: Verdana,Geneva,sans-serif;
  font-size: 10.6px;
  font-style: normal;
  padding: 10px;
  text-decoration: none;
  display: inline-block;
}

#centertbl {
  text-align: center;
}

.button {
  background-color: #4CAF50;
  /* Green */
  border: none;
  color: white;
  padding: 5px 15px;
  text-align: center;
  text-decoration: none;
  display: block;
  font-size: 16px;
  margin: 4px 2px;
  -webkit-transition-duration: 0.4s;
  /* Safari */
  transition-duration: 0.4s;
  cursor: pointer;
}

.button1 {
  background-color: white;
  color: black;
  border: 2px solid #4CAF50;
}

.button1:hover {
  background-color: #4CAF50;
  color: white;
}

Upvotes: 0

Views: 103

Answers (3)

Grant Jordan
Grant Jordan

Reputation: 458

You can always use flexbox as well. Here is an example. If you want to change the order of the buttons, just change the order in the html.

https://jsfiddle.net/GJordan/yoj1m8jf/

HTML

<div class="btn-container">
   <input type="submit" class="button" name="submitButton" value="Button 1">
  <input type="submit" class="button" name="submitButton" value="Button 3">
  <input type="submit" class="button" name="submitButton" value="Button 2">
  <input type="submit" class="button" name="submitButton" value="Button 4">
</div>

CSS

.btn-container {
  display: flex;
  flex-wrap: wrap;
  width: 250px;
}
.button {
  margin: 1%;
  width: 45%;
}

Upvotes: 2

Tousif Ahmad
Tousif Ahmad

Reputation: 106

Its very simple just put the buttons inside table tag

    <table>
    <tr>
     <td>  
<input type="submit" class="button button1" name="submitButton" value="Button 1">
      <input type="submit" class="button button1" name="submitButton" value="Button 2">
</td> 
 <td>
  <input type="submit" class="button button1" name="submitButton" value="Button 3">
      <input type="submit" class="button button1" name="submitButton" value="Button 4">
</td> 
    </tr>
    </table>

Upvotes: 0

Ahsan Aziz Abbasi
Ahsan Aziz Abbasi

Reputation: 168

making aligment thorugh CSS will align button by 1 3 and 2 4 in 2 rows simply floating and display inline attributes,

https://jsfiddle.net/0te3cs66/2/

above is the working example of required answer: with tables

below is the code

<div id="lse" class="display">
  <div id="centertbl">
    <table id="tblData" class="TSS">
      <tr>
        <td align="center" colspan="4"><b>Table 1</b></td>
      </tr>
    </table>

    <table id="tblData" class="TSS">
      <tr>
        <td align="center" colspan="4"><b>Table 2</b></td>
      </tr>
    </table>
  </div>
<table>
<tr>
 <td>  <input type="submit" class="button button1" name="submitButton" value="Button 1">
  <input type="submit" class="button button1" name="submitButton" value="Button 2"></td> 
 <td>  <input type="submit" class="button button1" name="submitButton" value="Button 3">
  <input type="submit" class="button button1" name="submitButton" value="Button 4"></td> 

</tr>
</table>



</div>

Upvotes: 0

Related Questions