具有多列的表单,没有表格

时间:2022-06-07 18:29:16

How to position a complex form with multiple fields in line across the screen?

如何在屏幕上排列多个字段的复杂表单?

11 个解决方案

#1


3  

Why are people so hell-bent on avoiding tables?

人们为什么如此害怕避开牌桌?

Tables are not deprecated and should be used when displaying content which logically belongs in a table.

表不会被弃用,应在显示逻辑上属于表的内容时使用。

If your form is logically grouped such that a table would be intuitive, please use a table.

如果您的表单按逻辑分组以使表格直观,请使用表格。

Always be thinking: "What's the cleanest, simplest, most maintainable way to achieve this result."

始终在思考:“实现这一结果的最简洁,最简单,最可维护的方法是什么。”

If you want a fluid form with a variable number columns, then disregard this.

如果您想要一个具有可变数字列的流体形式,请忽略它。

#2


3  

I prefer the slightly-more-semantic way, using a definition list:

我更喜欢使用定义列表的稍微更语义的方式:

<dl class="form">
    <dt><label for="input1">One:</label></dt>
    <dd><input type="text" name="input1" id="input1"></dd>
    <dt><label for="input2">Two:</label></dt>
    <dd><input type="text" name="input2" id="input2"></dd>
</dl>

Then your CSS:

然后你的CSS:

dl.form {
    width:100%;
    float:left;
    clear:both;
}
dl.form dt {
    width:50%;
    float:left;
    clear:left;
    text-align:right;
}
dl.form dd {
    width:50%;
    float:left;
    clear:right;
    text-align:left;
}

This should produce a form centered in the page, with the labels in the left column and the inputs in the right

这应该会生成一个以页面为中心的表单,左侧列中的标签和右侧的输入

#3


2  

There are many different ways to do this. It's all a matter of preference. What I typically do is have a wrapper div that contains all of the rows, and then a div block per row that contains the label, input, and validator. You can use the line-height CSS property to help you with vertical alignment. Example:

有很多不同的方法可以做到这一点。这完全是一个偏好问题。我通常做的是包含所有行的包装器div,然后是每行包含标签,输入和验证器的div块。您可以使用line-height CSS属性来帮助您进行垂直对齐。例:

<div class="formWrapper">
<form>
   <div class="formItem">
      <label for="firstName">First Name:</label>
      <input name="firstName" id="firstName" class="required" type="text" />
      <span class="validator" style="display: none;">*</>
   </div>
   ... <!-- Rinse repeat -->
</form>
</div>

<style type="text/css">
   .formWrapper { width: 400px }
   .formWrapper .formItem { line-height: 35px; height: 35px; }
   .formWrapper label { width: 50px; }
   .formWrapper input { width: 100px; border: 1px solid #000; }
   .formWrapper .validator { padding-left: 10px; color: #FF0000; }
</style>

Hope that helps.

希望有所帮助。

#4


2  

After looking at many many different solutions, I found the examples on this page (particularly the one from 'Fatal'?) some of the most helpful. But the extensive

在查看了许多不同的解决方案之后,我在这个页面上找到了这些例子(特别是'致命'中的一个?),其中一些最有用。但是广泛的

and tags did bother me a bit. So here is a little bit of a modification that some may like. Also, you find some sort of 'wrapper' or 'fieldset' style very necessary to keep the float from affecting other HTML. Refer to examples above.

和标签确实打扰了我一点。所以这里有一些修改,有些人可能会喜欢。此外,您发现某种“包装”或“字段集”样式非常必要,以防止浮动影响其他HTML。请参阅上面的示例。

<style>
.formcol{
float: left;
padding: 2px;
} 
.formcol label {
font-weight: bold;
display:block;} 
</style>

<div class="formcol">
    <label for="org">organization</label>
    <input type="text" id="org" size="24" name="org" />
  </div>
 <div class="formcol">
    <label for="fax">fax</label>
    <input type="text" id="fax" name="fax" size="2" />
  </div>
  <div class="formcol">
    <label for="3">three</label>
    <input type="text" id="3" name="3" />
    <label for="4">four</label>
    <input type="text" id="4" name="4" />

    <label for="5">five</label>
    <input type="text" id="5" name="5" />
  </div>
 <div class="formcol">
    <label for="6">six</label>
    <input type="text" id="6" name="6" />
  </div>

#5


1  

Do a search for "layouts without tables". Many sites describe formatting with CSS. Here is a simple intro: http://www.htmlgoodies.com/beyond/css/article.php/3642151

搜索“没有表格的布局”。许多网站用CSS描述格式。这是一个简单的介绍:http://www.htmlgoodies.com/beyond/css/article.php/3642151

#6


1  

I suggest you blueprint CSS framework. Have a quick look at the demo page.

我建议你蓝图CSS框架。快速浏览一下演示页面。

#7


1  

This is what I usually use when I need to design pretty complex forms.

当我需要设计非常复杂的表单时,这就是我通常使用的。

HTML:

<fieldset>
<legend>Consent group</legend>
<form>
<fieldset class="nolegend">
<p><label><span>Title</span> <input type="text" name="title" size="40" value="" /></label></p>
<p><label><span>Short name</span> <input type="text" name="sname" size="20" value="" /></label></p>
<p><label><br /><input type="checkbox" name="approval"> This consent group requires approval</label></p>
</fieldset>
<fieldset class="nolegend">
<p><label><span>Data use limitations</span> <textarea name="dul" cols="64" rows="4"></textarea></label></p>
</fieldset>
<input type="submit" value="Submit" />
</form>
</fieldset>

CSS:

body, input, textarea, select {
font: 1em Arial, Helvetica, sans-serif;
}
input, textarea, select { font-size: .8em }
fieldset,
fieldset legend {
background-color: #EEE;
}
fieldset {
border: none;
margin: 0;
padding: 0 0 .5em .01em;
top: 1.25em;
position: relative;
margin-bottom: 2em;
}
fieldset fieldset {
margin: 0 0 1em 0;
}
fieldset legend {
padding: .25em .5em 0 .5em;
border-bottom: none;
font-weight: bold;
margin-top: -1.25em;
position: relative;
*left: -.5em;
color: #666;
}fieldset form,
fieldset .fieldset {
margin: 0;
padding: 1em .5em 0 .5em;
overflow: hidden;
}
fieldset.nolegend {
position: static;
margin-bottom: 1em;
background-color: transparent;
padding: 0;
overflow: hidden;
}
fieldset.nolegend p,
fieldset.nolegend div {
float: left;
margin: 0 1em 0 0;
}
fieldset.nolegend p:last-child,
fieldset.nolegend div:last-child {
margin-right: 0;
}
fieldset.nolegend label>span {
display: block;
}
fieldset.nolegend label span {
_display: block;
}

I omitted couple lines of CSS with Safari hacks. You can check out live version of this code.

我用Safari黑客省略了几行CSS。您可以查看此代码的实时版本。

#8


1  

Pace KyleFarris but I just had to give Ben S a vote for having the guts to mention tables. Just look at the variety of CSS solutions on this page and around the internet for a ridiculously simple problem. CSS may one day become a good solution, but for the time being replicating the simple row and column grid that the table tag provides is extremely complex. I have spent countless fruitless hours with this prejudice against tables for things like a form. Why do we do this to ourselves?

Pace KyleFarris,但我只得给Ben S投票,让他们有胆量提及表格。只需查看此页面和互联网上的各种CSS解决方案,即可找到一个非常简单的问题。 CSS有朝一日可能会成为一个很好的解决方案,但是目前复制表标签提供的简单行和列网格非常复杂。对于诸如表格之类的事情,我已经花费了无数无效的时间来对表进行这种偏见。为什么我们这样做?

#9


0  

That would be done using CSS by setting the "display" property to "inline" (since form elements are, by default, block level elements).

这可以通过将“display”属性设置为“inline”来使用CSS完成(因为默认情况下,表单元素是块级元素)。

#10


0  

input fields, by default, are inline. Therefore, you can simply use line them up without
Another option if you want them lined up correctly is as follows:

默认情况下,输入字段是内联的。因此,如果您希望它们正确排列,您可以简单地使用它们而不使用其他选项,如下所示:

<div id="col1" style="float: left;>
    <input type="text" name="field1" />
    <br />
    <input type="text" name="field3" />
</div>

<div id="col2" style="float: left;>
    <input type="text" name="field2" />
    <br />
    <input type="text" name="field4" />
</div>

#11


0  

I prefer to use fieldset to group all elements and p for each form field.

我更喜欢使用fieldset来为每个表单字段分组所有元素和p。

<html>
<head>
<style type="text/css">
    fieldset {
        width: 500px;
        background-color: lightblue;
    }

    fieldset legend {
        font-weight: bold;
    }

    fieldset p {
        clear:both;
        padding: 5px;
    }

    fieldset label {
        text-align: left;
        width: 100px;
        float: left;
        font-weight: bold;
    }

    fieldset .Validator {
        color: red !important;
        font-weight: bold;
    } 

</style>
<head>
<body>
    <form>
        <fieldset>
            <legend>Data</legend>
            <p>
                <label for="firstName">First Name:</label>
                <input name="firstName" id="firstName" class="required" type="text" />
                <span class="Validator" style="display: none;">*</span>
            </p>
            <p>
                <label for="lastName">Last Name:</label>
                <input name="lastName" id="lastName" class="required" type="text" />
                <span class="Validator">*</span>
            </p>
        </fieldset>
    </form>
</body>
</html>

#1


3  

Why are people so hell-bent on avoiding tables?

人们为什么如此害怕避开牌桌?

Tables are not deprecated and should be used when displaying content which logically belongs in a table.

表不会被弃用,应在显示逻辑上属于表的内容时使用。

If your form is logically grouped such that a table would be intuitive, please use a table.

如果您的表单按逻辑分组以使表格直观,请使用表格。

Always be thinking: "What's the cleanest, simplest, most maintainable way to achieve this result."

始终在思考:“实现这一结果的最简洁,最简单,最可维护的方法是什么。”

If you want a fluid form with a variable number columns, then disregard this.

如果您想要一个具有可变数字列的流体形式,请忽略它。

#2


3  

I prefer the slightly-more-semantic way, using a definition list:

我更喜欢使用定义列表的稍微更语义的方式:

<dl class="form">
    <dt><label for="input1">One:</label></dt>
    <dd><input type="text" name="input1" id="input1"></dd>
    <dt><label for="input2">Two:</label></dt>
    <dd><input type="text" name="input2" id="input2"></dd>
</dl>

Then your CSS:

然后你的CSS:

dl.form {
    width:100%;
    float:left;
    clear:both;
}
dl.form dt {
    width:50%;
    float:left;
    clear:left;
    text-align:right;
}
dl.form dd {
    width:50%;
    float:left;
    clear:right;
    text-align:left;
}

This should produce a form centered in the page, with the labels in the left column and the inputs in the right

这应该会生成一个以页面为中心的表单,左侧列中的标签和右侧的输入

#3


2  

There are many different ways to do this. It's all a matter of preference. What I typically do is have a wrapper div that contains all of the rows, and then a div block per row that contains the label, input, and validator. You can use the line-height CSS property to help you with vertical alignment. Example:

有很多不同的方法可以做到这一点。这完全是一个偏好问题。我通常做的是包含所有行的包装器div,然后是每行包含标签,输入和验证器的div块。您可以使用line-height CSS属性来帮助您进行垂直对齐。例:

<div class="formWrapper">
<form>
   <div class="formItem">
      <label for="firstName">First Name:</label>
      <input name="firstName" id="firstName" class="required" type="text" />
      <span class="validator" style="display: none;">*</>
   </div>
   ... <!-- Rinse repeat -->
</form>
</div>

<style type="text/css">
   .formWrapper { width: 400px }
   .formWrapper .formItem { line-height: 35px; height: 35px; }
   .formWrapper label { width: 50px; }
   .formWrapper input { width: 100px; border: 1px solid #000; }
   .formWrapper .validator { padding-left: 10px; color: #FF0000; }
</style>

Hope that helps.

希望有所帮助。

#4


2  

After looking at many many different solutions, I found the examples on this page (particularly the one from 'Fatal'?) some of the most helpful. But the extensive

在查看了许多不同的解决方案之后,我在这个页面上找到了这些例子(特别是'致命'中的一个?),其中一些最有用。但是广泛的

and tags did bother me a bit. So here is a little bit of a modification that some may like. Also, you find some sort of 'wrapper' or 'fieldset' style very necessary to keep the float from affecting other HTML. Refer to examples above.

和标签确实打扰了我一点。所以这里有一些修改,有些人可能会喜欢。此外,您发现某种“包装”或“字段集”样式非常必要,以防止浮动影响其他HTML。请参阅上面的示例。

<style>
.formcol{
float: left;
padding: 2px;
} 
.formcol label {
font-weight: bold;
display:block;} 
</style>

<div class="formcol">
    <label for="org">organization</label>
    <input type="text" id="org" size="24" name="org" />
  </div>
 <div class="formcol">
    <label for="fax">fax</label>
    <input type="text" id="fax" name="fax" size="2" />
  </div>
  <div class="formcol">
    <label for="3">three</label>
    <input type="text" id="3" name="3" />
    <label for="4">four</label>
    <input type="text" id="4" name="4" />

    <label for="5">five</label>
    <input type="text" id="5" name="5" />
  </div>
 <div class="formcol">
    <label for="6">six</label>
    <input type="text" id="6" name="6" />
  </div>

#5


1  

Do a search for "layouts without tables". Many sites describe formatting with CSS. Here is a simple intro: http://www.htmlgoodies.com/beyond/css/article.php/3642151

搜索“没有表格的布局”。许多网站用CSS描述格式。这是一个简单的介绍:http://www.htmlgoodies.com/beyond/css/article.php/3642151

#6


1  

I suggest you blueprint CSS framework. Have a quick look at the demo page.

我建议你蓝图CSS框架。快速浏览一下演示页面。

#7


1  

This is what I usually use when I need to design pretty complex forms.

当我需要设计非常复杂的表单时,这就是我通常使用的。

HTML:

<fieldset>
<legend>Consent group</legend>
<form>
<fieldset class="nolegend">
<p><label><span>Title</span> <input type="text" name="title" size="40" value="" /></label></p>
<p><label><span>Short name</span> <input type="text" name="sname" size="20" value="" /></label></p>
<p><label><br /><input type="checkbox" name="approval"> This consent group requires approval</label></p>
</fieldset>
<fieldset class="nolegend">
<p><label><span>Data use limitations</span> <textarea name="dul" cols="64" rows="4"></textarea></label></p>
</fieldset>
<input type="submit" value="Submit" />
</form>
</fieldset>

CSS:

body, input, textarea, select {
font: 1em Arial, Helvetica, sans-serif;
}
input, textarea, select { font-size: .8em }
fieldset,
fieldset legend {
background-color: #EEE;
}
fieldset {
border: none;
margin: 0;
padding: 0 0 .5em .01em;
top: 1.25em;
position: relative;
margin-bottom: 2em;
}
fieldset fieldset {
margin: 0 0 1em 0;
}
fieldset legend {
padding: .25em .5em 0 .5em;
border-bottom: none;
font-weight: bold;
margin-top: -1.25em;
position: relative;
*left: -.5em;
color: #666;
}fieldset form,
fieldset .fieldset {
margin: 0;
padding: 1em .5em 0 .5em;
overflow: hidden;
}
fieldset.nolegend {
position: static;
margin-bottom: 1em;
background-color: transparent;
padding: 0;
overflow: hidden;
}
fieldset.nolegend p,
fieldset.nolegend div {
float: left;
margin: 0 1em 0 0;
}
fieldset.nolegend p:last-child,
fieldset.nolegend div:last-child {
margin-right: 0;
}
fieldset.nolegend label>span {
display: block;
}
fieldset.nolegend label span {
_display: block;
}

I omitted couple lines of CSS with Safari hacks. You can check out live version of this code.

我用Safari黑客省略了几行CSS。您可以查看此代码的实时版本。

#8


1  

Pace KyleFarris but I just had to give Ben S a vote for having the guts to mention tables. Just look at the variety of CSS solutions on this page and around the internet for a ridiculously simple problem. CSS may one day become a good solution, but for the time being replicating the simple row and column grid that the table tag provides is extremely complex. I have spent countless fruitless hours with this prejudice against tables for things like a form. Why do we do this to ourselves?

Pace KyleFarris,但我只得给Ben S投票,让他们有胆量提及表格。只需查看此页面和互联网上的各种CSS解决方案,即可找到一个非常简单的问题。 CSS有朝一日可能会成为一个很好的解决方案,但是目前复制表标签提供的简单行和列网格非常复杂。对于诸如表格之类的事情,我已经花费了无数无效的时间来对表进行这种偏见。为什么我们这样做?

#9


0  

That would be done using CSS by setting the "display" property to "inline" (since form elements are, by default, block level elements).

这可以通过将“display”属性设置为“inline”来使用CSS完成(因为默认情况下,表单元素是块级元素)。

#10


0  

input fields, by default, are inline. Therefore, you can simply use line them up without
Another option if you want them lined up correctly is as follows:

默认情况下,输入字段是内联的。因此,如果您希望它们正确排列,您可以简单地使用它们而不使用其他选项,如下所示:

<div id="col1" style="float: left;>
    <input type="text" name="field1" />
    <br />
    <input type="text" name="field3" />
</div>

<div id="col2" style="float: left;>
    <input type="text" name="field2" />
    <br />
    <input type="text" name="field4" />
</div>

#11


0  

I prefer to use fieldset to group all elements and p for each form field.

我更喜欢使用fieldset来为每个表单字段分组所有元素和p。

<html>
<head>
<style type="text/css">
    fieldset {
        width: 500px;
        background-color: lightblue;
    }

    fieldset legend {
        font-weight: bold;
    }

    fieldset p {
        clear:both;
        padding: 5px;
    }

    fieldset label {
        text-align: left;
        width: 100px;
        float: left;
        font-weight: bold;
    }

    fieldset .Validator {
        color: red !important;
        font-weight: bold;
    } 

</style>
<head>
<body>
    <form>
        <fieldset>
            <legend>Data</legend>
            <p>
                <label for="firstName">First Name:</label>
                <input name="firstName" id="firstName" class="required" type="text" />
                <span class="Validator" style="display: none;">*</span>
            </p>
            <p>
                <label for="lastName">Last Name:</label>
                <input name="lastName" id="lastName" class="required" type="text" />
                <span class="Validator">*</span>
            </p>
        </fieldset>
    </form>
</body>
</html>