Greg-A
Greg-A

Reputation: 852

Align the tr of a table horizontally

I have a table :

https://codepen.io/greg59650/pen/GROajNp

    <table role="table"><tbody>
      <tr>
       <td colspan="1">
      <form>
      <select name="pets" id="pet-select">
       <option value="">choose</option>
       <option value="dog">Dog</option>
       <option value="cat">Cat</option>
      </select>    
      </form>
       </td>    
        <td colspan="1">
       <form>
         <select name="pets" id="pet-select">
          <option value="">choose</option>
          <option value="dog">Dog</option>
          <option value="cat">Cat</option>
         </select>
          <span><button>Logout</button></span>
         </form>
          </td>    
        <td colspan="1">
        <form>
          <select name="pets" id="pet-select">
            <option value="">choose</option>
            <option value="dog">Dog</option>
            <option value="cat">Cat</option>
           </select>    
        </form>
        </td>
        <td colspan="1">
       <form>
       <select name="pets" id="pet-select">
        <option value="">choose</option>
        <option value="dog">Dog</option>
        <option value="cat">Cat</option>
       </select>    
      </form>
       </td>
       <td colspan="1">
      <form>
      <select name="pets" id="pet-select">
       <option value="">choose</option>
       <option value="dog">Dog</option>
        <option value="cat">Cat</option>
       </select>    
       </form>
       </td>
       <td colspan="1">
       <form>
       <select name="pets" id="pet-select">
       <option value="">choose</option>
       <option value="dog">Dog</option>
       <option value="cat">Cat</option>
     </select>    
      </form>
     </td>
    <td colspan="1">
     <form>
      <select name="pets" id="pet-select">
    <option value="">choose</option>
    <option value="dog">Dog</option>
    <option value="cat">Cat</option>
  </select>    
  </form>
    </td>
       </tr></tbody></table>

if I add an element in the content of my td I would like all my selects to be aligned on the same level and the button below.

like this :

enter image description here

but currently I get this display :

enter image description here

would there be a simple solution to be able to align the selects on the same level ?

Upvotes: 1

Views: 103

Answers (3)

Aditya Pandey
Aditya Pandey

Reputation: 1

You can do this by following ways,

  1. by doing td {vertical-align: top;}
  2. by adding logout button in another row
  3. by using id or class of the button you can set its margin and other attributes.

Upvotes: 0

Archit Gargi
Archit Gargi

Reputation: 685

Simplest Solution. You can just create another row for it.

table {
  border: 1px solid black;
}
<table role="table">
  <tbody>
    <tr>
      <td colspan="1">
        <form>
          <select name="pets" id="pet-select">
            <option value="">choose</option>
            <option value="dog">Dog</option>
            <option value="cat">Cat</option>
          </select>
        </form>
      </td>
      <td colspan="1">
        <form>
          <select name="pets" id="pet-select">
            <option value="">choose</option>
            <option value="dog">Dog</option>
            <option value="cat">Cat</option>
          </select>
        </form>
      </td>
      <td colspan="1">
        <form>
          <select name="pets" id="pet-select">
            <option value="">choose</option>
            <option value="dog">Dog</option>
            <option value="cat">Cat</option>
          </select>
        </form>
      </td>
      <td colspan="1">
        <form>
          <select name="pets" id="pet-select">
            <option value="">choose</option>
            <option value="dog">Dog</option>
            <option value="cat">Cat</option>
          </select>
        </form>
      </td>
      <td colspan="1">
        <form>
          <select name="pets" id="pet-select">
            <option value="">choose</option>
            <option value="dog">Dog</option>
            <option value="cat">Cat</option>
          </select>
        </form>
      </td>
      <td colspan="1">
        <form>
          <select name="pets" id="pet-select">
            <option value="">choose</option>
            <option value="dog">Dog</option>
            <option value="cat">Cat</option>
          </select>
        </form>
      </td>
      <td colspan="1">
        <form>
          <select name="pets" id="pet-select">
            <option value="">choose</option>
            <option value="dog">Dog</option>
            <option value="cat">Cat</option>
          </select>
        </form>
      </td>
      <td colspan="1">
        <form>
          <select name="pets" id="pet-select">
            <option value="">choose</option>
            <option value="dog">Dog</option>
            <option value="cat">Cat</option>
          </select>
        </form>
      </td>
      <td colspan="1">
        <form>
          <select name="pets" id="pet-select">
            <option value="">choose</option>
            <option value="dog">Dog</option>
            <option value="cat">Cat</option>
          </select>
        </form>
      </td>
      <td colspan="1">
        <form>
          <select name="pets" id="pet-select">
            <option value="">choose</option>
            <option value="dog">Dog</option>
            <option value="cat">Cat</option>
          </select>
        </form>
      </td>
      <td colspan="1">
        <form>
          <select name="pets" id="pet-select">
            <option value="">choose</option>
            <option value="dog">Dog</option>
            <option value="cat">Cat</option>
          </select>
        </form>
      </td>
      <td colspan="1">
        <form>
          <select name="pets" id="pet-select">
            <option value="">choose</option>
            <option value="dog">Dog</option>
            <option value="cat">Cat</option>
          </select>
        </form>
      </td>
      <td colspan="1">
        <form>
          <select name="pets" id="pet-select">
            <option value="">choose</option>
            <option value="dog">Dog</option>
            <option value="cat">Cat</option>
          </select>
        </form>
      </td>
      <td colspan="1">
        <form>
          <select name="pets" id="pet-select">
            <option value="">choose</option>
            <option value="dog">Dog</option>
            <option value="cat">Cat</option>
          </select>
        </form>
      </td>
      <td colspan="1">
        <form>
          <select name="pets" id="pet-select">
            <option value="">choose</option>
            <option value="dog">Dog</option>
            <option value="cat">Cat</option>
          </select>
        </form>
      </td>
      <td colspan="1">
        <form>
          <select name="pets" id="pet-select">
            <option value="">choose</option>
            <option value="dog">Dog</option>
            <option value="cat">Cat</option>
          </select>
        </form>
      </td>
      <td colspan="1">
        <form>
          <select name="pets" id="pet-select">
            <option value="">choose</option>
            <option value="dog">Dog</option>
            <option value="cat">Cat</option>
          </select>
        </form>
      </td>
      <td colspan="1">
        <form>
          <select name="pets" id="pet-select">
            <option value="">choose</option>
            <option value="dog">Dog</option>
            <option value="cat">Cat</option>
          </select>
        </form>
      </td>
      <td colspan="1">
        <form>
          <select name="pets" id="pet-select">
            <option value="">choose</option>
            <option value="dog">Dog</option>
            <option value="cat">Cat</option>
          </select>
        </form>
      </td>
      <td colspan="1">
        <form>
          <select name="pets" id="pet-select">
            <option value="">choose</option>
            <option value="dog">Dog</option>
            <option value="cat">Cat</option>
          </select>
        </form>
      </td>
      <td colspan="1">
        <form>
          <select name="pets" id="pet-select">
            <option value="">choose</option>
            <option value="dog">Dog</option>
            <option value="cat">Cat</option>
          </select>
        </form>
      </td>
      <td colspan="1">
        <form>
          <select name="pets" id="pet-select">
            <option value="">choose</option>
            <option value="dog">Dog</option>
            <option value="cat">Cat</option>
          </select>
        </form>
      </td>
      <td colspan="1">
        <form>
          <select name="pets" id="pet-select">
            <option value="">choose</option>
            <option value="dog">Dog</option>
            <option value="cat">Cat</option>
          </select>
        </form>
      </td>
      <td colspan="1">
        <form>
          <select name="pets" id="pet-select">
            <option value="">choose</option>
            <option value="dog">Dog</option>
            <option value="cat">Cat</option>
          </select>
        </form>
      </td>
      <td colspan="1">
        <form>
          <select name="pets" id="pet-select">
            <option value="">choose</option>
            <option value="dog">Dog</option>
            <option value="cat">Cat</option>
          </select>
        </form>
      </td>
      <td colspan="1">
        <form>
          <select name="pets" id="pet-select">
            <option value="">choose</option>
            <option value="dog">Dog</option>
            <option value="cat">Cat</option>
          </select>
        </form>
      </td>
      <td colspan="1">
        <form>
          <select name="pets" id="pet-select">
            <option value="">choose</option>
            <option value="dog">Dog</option>
            <option value="cat">Cat</option>
          </select>
        </form>
      </td>
      <td colspan="1">
        <form>
          <select name="pets" id="pet-select">
            <option value="">choose</option>
            <option value="dog">Dog</option>
            <option value="cat">Cat</option>
          </select>
        </form>
      </td>
    </tr>
    <tr>
      <td></td>
      <td><span><button>Logout</button></span></td>
    </tr>
  </tbody>
</table>

Upvotes: 1

Sifat Haque
Sifat Haque

Reputation: 6057

You can add vertical-align: top to your td.

td {
    vertical-align: top;
}

table {border:1px solid black; }
td {
  vertical-align: top;
}
<table role="table"><tbody>
  <tr>
    <td colspan="1">
  <form>
  <select name="pets" id="pet-select">
    <option value="">choose</option>
    <option value="dog">Dog</option>
    <option value="cat">Cat</option>
  </select>    
  </form>
</td>    <td colspan="1">
  <form>
  <select name="pets" id="pet-select">
    <option value="">choose</option>
    <option value="dog">Dog</option>
    <option value="cat">Cat</option>
  </select>
    <span><button>Logout</button></span>
  </form>
</td>    <td colspan="1">
  <form>
  <select name="pets" id="pet-select">
    <option value="">choose</option>
    <option value="dog">Dog</option>
    <option value="cat">Cat</option>
  </select>    
  </form>
</td>
  <td colspan="1">
  <form>
  <select name="pets" id="pet-select">
    <option value="">choose</option>
    <option value="dog">Dog</option>
    <option value="cat">Cat</option>
  </select>    
  </form>
</td>
    <td colspan="1">
  <form>
  <select name="pets" id="pet-select">
    <option value="">choose</option>
    <option value="dog">Dog</option>
    <option value="cat">Cat</option>
  </select>    
  </form>
</td>
    <td colspan="1">
  <form>
  <select name="pets" id="pet-select">
    <option value="">choose</option>
    <option value="dog">Dog</option>
    <option value="cat">Cat</option>
  </select>    
  </form>
</td>
    <td colspan="1">
  <form>
  <select name="pets" id="pet-select">
    <option value="">choose</option>
    <option value="dog">Dog</option>
    <option value="cat">Cat</option>
  </select>    
  </form>
</td>
    <td colspan="1">
  <form>
  <select name="pets" id="pet-select">
    <option value="">choose</option>
    <option value="dog">Dog</option>
    <option value="cat">Cat</option>
  </select>    
  </form>
</td>
    <td colspan="1">
  <form>
  <select name="pets" id="pet-select">
    <option value="">choose</option>
    <option value="dog">Dog</option>
    <option value="cat">Cat</option>
  </select>    
  </form>
</td>
    <td colspan="1">
  <form>
  <select name="pets" id="pet-select">
    <option value="">choose</option>
    <option value="dog">Dog</option>
    <option value="cat">Cat</option>
  </select>    
  </form>
</td>
    <td colspan="1">
  <form>
  <select name="pets" id="pet-select">
    <option value="">choose</option>
    <option value="dog">Dog</option>
    <option value="cat">Cat</option>
  </select>    
  </form>
</td>
    <td colspan="1">
  <form>
  <select name="pets" id="pet-select">
    <option value="">choose</option>
    <option value="dog">Dog</option>
    <option value="cat">Cat</option>
  </select>    
  </form>
</td>
    <td colspan="1">
  <form>
  <select name="pets" id="pet-select">
    <option value="">choose</option>
    <option value="dog">Dog</option>
    <option value="cat">Cat</option>
  </select>    
  </form>
</td>
    <td colspan="1">
  <form>
  <select name="pets" id="pet-select">
    <option value="">choose</option>
    <option value="dog">Dog</option>
    <option value="cat">Cat</option>
  </select>    
  </form>
</td>
    <td colspan="1">
  <form>
  <select name="pets" id="pet-select">
    <option value="">choose</option>
    <option value="dog">Dog</option>
    <option value="cat">Cat</option>
  </select>    
  </form>
</td>
    <td colspan="1">
  <form>
  <select name="pets" id="pet-select">
    <option value="">choose</option>
    <option value="dog">Dog</option>
    <option value="cat">Cat</option>
  </select>    
  </form>
</td>
    <td colspan="1">
  <form>
  <select name="pets" id="pet-select">
    <option value="">choose</option>
    <option value="dog">Dog</option>
    <option value="cat">Cat</option>
  </select>    
  </form>
</td>
    <td colspan="1">
  <form>
  <select name="pets" id="pet-select">
    <option value="">choose</option>
    <option value="dog">Dog</option>
    <option value="cat">Cat</option>
  </select>    
  </form>
</td>
    <td colspan="1">
  <form>
  <select name="pets" id="pet-select">
    <option value="">choose</option>
    <option value="dog">Dog</option>
    <option value="cat">Cat</option>
  </select>    
  </form>
</td>
    <td colspan="1">
  <form>
  <select name="pets" id="pet-select">
    <option value="">choose</option>
    <option value="dog">Dog</option>
    <option value="cat">Cat</option>
  </select>    
  </form>
</td>
    <td colspan="1">
  <form>
  <select name="pets" id="pet-select">
    <option value="">choose</option>
    <option value="dog">Dog</option>
    <option value="cat">Cat</option>
  </select>    
  </form>
</td>
    <td colspan="1">
  <form>
  <select name="pets" id="pet-select">
    <option value="">choose</option>
    <option value="dog">Dog</option>
    <option value="cat">Cat</option>
  </select>    
  </form>
</td>
    <td colspan="1">
  <form>
  <select name="pets" id="pet-select">
    <option value="">choose</option>
    <option value="dog">Dog</option>
    <option value="cat">Cat</option>
  </select>    
  </form>
</td>
    <td colspan="1">
  <form>
  <select name="pets" id="pet-select">
    <option value="">choose</option>
    <option value="dog">Dog</option>
    <option value="cat">Cat</option>
  </select>    
  </form>
</td>
    <td colspan="1">
  <form>
  <select name="pets" id="pet-select">
    <option value="">choose</option>
    <option value="dog">Dog</option>
    <option value="cat">Cat</option>
  </select>    
  </form>
</td>
    <td colspan="1">
  <form>
  <select name="pets" id="pet-select">
    <option value="">choose</option>
    <option value="dog">Dog</option>
    <option value="cat">Cat</option>
  </select>    
  </form>
</td>
    <td colspan="1">
  <form>
  <select name="pets" id="pet-select">
    <option value="">choose</option>
    <option value="dog">Dog</option>
    <option value="cat">Cat</option>
  </select>    
  </form>
</td>
    <td colspan="1">
  <form>
  <select name="pets" id="pet-select">
    <option value="">choose</option>
    <option value="dog">Dog</option>
    <option value="cat">Cat</option>
  </select>    
  </form>
</td>
</tr></tbody></table>

Upvotes: 2

Related Questions