search

Home  >  Q&A  >  body text

How to center a form/table with fieldsets in HTML-CSS and keep the size consistent?

In HTML using the combination of <form> and <table>. It looks like this:

<form ...>
 <table>
   <tr>
    <td></td>
    <td></td>
   </tr>
   ...
   <tr>
    <td></td>
    <td></td>
   </tr>
 </table>
</form>

To place this form/table in the middle of the page, you can use the following CSS:

table {
   margin: 0px auto;
}

source:

Until everything is ok.

When adding <fieldset> and legend to <form>, it is actually added to <table>middle. Therefore, the current structure is as follows:

<form ...>
<fieldset>
<legend>一些描述...</legend>
 <table>
   <tr>
    <td></td>
    <td></td>
   </tr>
   ...
   <tr>
    <td></td>
    <td></td>
   </tr>
 </table>
</fieldset>
</form>

There are two situations here:

  1. How to make <fieldset>'s border the same size as the form/table itself?

The application is as follows:

fieldset {
     display: inline-block;
}

source:

Even though it works as expected, <table> is still on the left.

question

P粉316110779P粉316110779580 days ago1531

reply all(1)I'll reply

  • P粉561323975

    P粉5613239752023-09-17 00:02:52

    Such a thing?

    form {
        display: table;
        margin: 0 auto;
    }
    table {
       margin: 0 auto;
    }
    fieldset {
       display: inline-block;
    }
    <form>
      <fieldset>
        <legend>一些描述...</legend>
        <table>
          <tr>
            <td></td>
            <td></td>
          </tr>
          <tr>
            <td></td>
            <td></td>
          </tr>
        </table>
      </fieldset>
    </form>

    reply
    0
  • Cancelreply