英文:
HTML-CSS: How to put a form/table with fieldset to the center but keeping the fieldset as the same size as the form/table?
问题
在HTML中,与<form>
一起使用的是<table>
。它如下所示:
<form ...>
<table>
<tr>
<td></td>
<td></td>
</tr>
...
<tr>
<td></td>
<td></td>
</tr>
</table>
</form>
要将此“表单/表格”置于页面中间,可以使用以下CSS:
table {
margin: 0px auto;
}
直到一切都正常。
情况是,当向<form>
添加<fieldset>
和<legend>
时,实际上是添加到了<table>
。因此,现在的结构如下:
<form ...>
<fieldset>
<legend>一些描述 ...</legend>
<table>
<tr>
<td></td>
<td></td>
</tr>
...
<tr>
<td></td>
<td></td>
</tr>
</table>
</fieldset>
</form>
这里出现了两种情况:
- 如何使
<fieldset>
的边框大小与表单/表格本身相同?
在这里应用了以下CSS:
fieldset {
display: inline-block;
}
来源:有没有办法让fieldset的宽度仅与其中的控件一样宽?
即使它按预期工作,<table>
仍然位于左侧。
问题
- 如何将带有
<fieldset>
的表单/表格置于中间,但保持<fieldset>
与表单/表格的大小相同?
英文:
In HTML for a <form>
used together with a <table>
. It such as:
<form ...>
<table>
<tr>
<td></td>
<td></td>
</tr>
...
<tr>
<td></td>
<td></td>
</tr>
</table>
</form>
To put this form/table in the middle of the page is used CSS
as follows:
table {
margin: 0px auto;
}
Credits from:
Until all is ok.
The situation is when is added <fieldset>
and legend
to the <form>
, well really to the <table>
. Therefore the structure is now as follows
<form ...>
<fieldset>
<legend>Some Description ...</legend>
<table>
<tr>
<td></td>
<td></td>
</tr>
...
<tr>
<td></td>
<td></td>
</tr>
</table>
</fieldset>
</form>
Here arises two situations:
- How to put the
<fieldset>
's border as the same size as the form/table itself?
Here as applied
fieldset {
display: inline-block;
}
Credits from:
Even when it works as expected, the <table>
returns to the left.
Question
- How to put a form/table with fieldset to the center but keeping the fieldset as the same size as the form/table?
答案1
得分: 1
像这样吗?
<!-- 开始代码段:js 隐藏: false 控制台: true Babel: false -->
<!-- 语言:lang-css -->
form {
display: table;
margin: 0 auto;
}
table {
margin: 0 auto;
}
fieldset {
display: inline-block;
}
<!-- 语言:lang-html -->
<form>
<fieldset>
<legend>一些描述...</legend>
<table>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
</fieldset>
</form>
<!-- 结束代码段 -->
请注意,我已经保留了原始代码的格式和标记。
英文:
Something like this?
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
form {
display: table;
margin: 0 auto;
}
table {
margin: 0 auto;
}
fieldset {
display: inline-block;
}
<!-- language: lang-html -->
<form>
<fieldset>
<legend>Some Description ...</legend>
<table>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
</fieldset>
</form>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论