Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to center a select box in a cell table using HTML?

This may seem silly, but I’m a beginner here and I can’t wrap my head around this one:

Fiddle

<table class="table table-sm table-striped" id="dtable" style="font-size:0.9em">
  <thead style="white-space: nowrap">
    <tr>
      <th style="width: 17%" class="text-center">Link To File</th>
      <th style="width: 18%" class="text-center">Approval Status</th>
    </thead>
    <tbody>
      <tr>
        <td class="align-middle" style="word-wrap: break-word;min-width: 160px;max-width: 160px;text-align:center">2</td>
        <td class="align-middle" style="align-center">
          <select name="D1" style="border-radius: 0.2rem">
            <option value="empty"></option>
            <option value="approved">Approved</option>
            <option value="dicsuss">Discuss</option>
            <option value="cancelled">Cancelled</option>
           </select>
         </td>
      </tr>
   </tbody>
  </table>

It should look like this:
enter image description here
Appreciate any help.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Assuming you are using bootstrap

Change this:

          <td class="text-center">
          <select class="text-center" name="D1" style="border-radius: 0.2rem">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.12.9/dist/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

<table class="table table-sm table-striped" id="dtable" style="font-size:0.9em">
  <thead style="white-space: nowrap">
    <tr>
      <th style="width: 17%" class="text-center">Link To File</th>
      <th style="width: 18%" class="text-center">Approval Status</th>
    </thead>
    <tbody>
      <tr>
        <td class="align-middle" style="word-wrap: break-word;min-width: 160px;max-width: 160px;text-align:center">2</td>
        <td class="text-center">
          <select class="text-center" name="D1" style="border-radius: 0.2rem">
            <option value="empty"></option>
            <option value="approved">Approved</option>
            <option value="dicsuss">Discuss</option>
            <option value="cancelled">Cancelled</option>
           </select>
         </td>
      </tr>
   </tbody>
  </table>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading