Standard
Form whether in the production of the site, or in the reconstruction of the site, we will frequently "meet", when the "meet" the number of times, but feel that he is more confusing, a familiar "strange", more and more can not grasp him.
Below we will take you into the form of the world, together to understand, explore, master his "temperament."
For the simple form of the design (such as figure one, Yahoo registered part of the page), how do we do the overall layout? Generally we can use the following 3 ways to do the layout:
1, use table to layout
This is the most commonly used method, although now everywhere talk about standardization, and even more in the said Div+css, but Yiwen fly or recommend you use table to layout form. For the standard, the individual's alternative understanding "is more logical, more efficient and quicker".
Why do you recommend that you use it? Table is used to display two-dimensional data, with a table layout form can be said to be his "old line." Another important point is that the complexity of the form,table can be more efficient layout and maintenance changes, reflecting the efficiency and ease of use.
Before layout, review some of the tabs on the table:
Table: Displaying two-dimensional data
Summary: Defining the purpose of a table
Caption: Defines the title of the table, used at the beginning of the table, only once
TR: a row in a table
Th: Header cell, defining a row or column of header information
TD: Data Cells
Here's a concrete layout for the Tuyi design:
<styletype= "Text/css" ><!--* {margin:0; padding:0;} Table {border-collapse:collapse;} Input,select {font-family:arial, Helvetica, Sans-serif; font-size:12px;}. Required {font:0.8em Verdana!important; color: #f68622;}. Explain {color: #808080;}. b {font-weight:bold; font-size:12px;}. DemoCSS table{font:11px/12px Arial, Helvetica, Sans-serif;color: #333; width:420px; DemoCSS caption {Display:none}. DemoCSS th {font-weight:normal; text-align:right; vertical-align:top;padding:4px; padding-top:8px; width:110px}. DemoCSS td {Text-align:left; padding:4px; width:294px;}. DemoCSS input {width:180px}. DemoCSS select#content {width:185px}. DemoCSS input.submit {width:70px;} --></style><form id= "Demoform" class= "DemoCSS" action= "><table" summary= "Demo for layout using table" Id= "Demo" ><caption>registration example Form</caption><tr><th><span class= "required" >* </span> <labelfor= "fname" accesskey= "F" >first name:</label></th><Td><input type= "text" id= "fname" value= "/></td></tr><tr><th><span class=" Required ">*</span> <labelfor=" lname "accesskey=" L ">last name:</label></th><td> <input type= "text" id= "lname" value= ""/></td></tr><tr><th><span class= "required" >*</span> <labelfor= "Content" accesskey= "C" >Preferredcontent:</label></th><td> <select name= "Content" id= "content" ><option value= "Us" selected= "selected" >yahoo! u.s.</option> <option value= "E1" >yahoo! U.S. In spanish</option><option value= ' B5 ' >yahoo! U.S. In Chinese</ Option><option value= "cn" >yahoo! china</option><option value= "UK" >yahoo! United Option><option value= "ar" >yahoo! argentina</option><option value= "AA" >Yahoo! Asia</option ><option value= "au" >yahoo! australia</option> <optionvalue= "BR" >yahoo! BRAZIL</option><option value= "Ca" >yahoo! Canada in english</option><option value= "CF" >Yahoo! In French</option><option value= "fr" >yahoo! france</option><option value= "de" >Yahoo! Germany</option><option value= "HK" >yahoo!-kong</option><option value= "in" >Yahoo! India </option><option value= "It" >yahoo! italy</option><option value= "KR" >Yahoo! Korea</ Option><option value= "mx" >yahoo! mexico</option><option value= "SG" >yahoo! Option><option value= "es" >yahoo! spain</option><option value= "TW" >yahoo! Taiwan</option ></select></td></tr><tr><th><span class= "Required" >*</span> < labelfor= "Sex" accesskey= "G" >gender:</label></th><td><select name= "sex" id= "Sex" >< Option Value= "" >[select] </option><option value= "M" >male</option><option value= "F" >Female</option></select></td></tr><tr><th><span class= "Required" >* </span> <labelfor= accesskey= Y >yahoo! id:</label></th><td><input type= Text value= id= > <spanclass= B > @yahoo. COM</SPAN><BR/><span class= explain >id May consist of a-Z, 0-9, underscores,and a single dot (.) </span></td></tr><tr><th><span class= "Required" >*</span> <labelfor= "PW" accesskey= "P" >password:</label></th><td><input type= "Password" value= "" id= "PW"/> <BR/><span class= "explain" >six characters or more; Capitalizationmatters!</span></td></tr><tr><th><span class= "Required" >*< /SPAN> <labelfor= "pw2" accesskey= "R" >re-type password:</label></th><td><input " Password "value=" "id=" Pw2 "/></td></tr><tr><th></th><td><input type= "Submit" value= "submit" class= "submit"/><input type= "reset" value= "reset" class= "Submit"/> </td></tr></table></form>
2, use the label to layout
Features: For a simple form layout, this method is more prominent in semantic representation.
The usual solutions are:
Adds a DIV or p to the label and input or other perimeter, triggers the div or P to layout (you can use Holly hack to set height:1%), and clears the left float clear:left;. Set the label to Float:left; float on input or other right.
The method to align the label is to fix the width of the label, and then use Text-align to align left or right as needed.
If there is more than one line of input or other on the right side of the label, we can set padding-left:xpx on the DIV or P, and then set the MARGIN-LEFT:-XPX on the label.
Set the width of a small trick, using the unit EM according to the maximum number of words to set the width, do not have to hard test px.
Of course you can also use the <BR/> at the end of each line without div or P, and a BR setting clears the floating clear:left;
Note: The use of the secondary method in IE, there is a small bug, that is, Div or p in the first line of input or other 3px ie bug, we can use only IE talent Other * HTML to define attributes to eliminate 3px bugs.
Here's a concrete layout for the Tuyi design:
<style type= "Text/css" ><!--* {margin:0; padding:0;} Input,select {font-family:arial, Helvetica, Sans-serif; FONT-SIZE:12PX}. Required {font:0.8em Verdana!important; Color: #f68622; Explain {color: #808080;}. b {font-weight:bold; FONT-SIZE:12PX}. democss {font:11px/12px Arial, Helvetica, Sans-serif; Color: #333; DemoCSS p {width:298px; Clear:left; padding:4px; padding-left:122px; Text-align:left; height:1%}. DemoCSS label {float:left; Margin-left: -122px; width:110px; padding:4px 4px 0; Text-align:right}. DemoCSS input {width:180px}. DemoCSS select#content {width:185px}. DemoCSS input.submit {width:70px;} div#submit {width:298px; Text-align:left; padding:4px; padding-left:122px;} * HTML. DEMOCSS input,* HTML. DemoCSS select{margin-left: -3px; }* HTML div#submit input{margin-left:0px;} --></style><form id= "Demoform" class= "DemoCSS" action= "" ><p><label for= "fname" accesskey= "F "><span class=" RequirEd ">*</span> a name:</label><input type=" text "id=" fname "value=" "/></p><p>" <label for= "lname" accesskey= "L" ><span class= "required" >*</span> last name:</label>< Input type= "text" id= "lname" value= "/></p><p><label for=" content "accesskey=" C "><span class = "Required" >*</span> preferred content:</label><select name= "content" id= "content" ><option Value= "Us" selected= "selected" >yahoo! u.s.</option><option value= "E1" >yahoo! U.S. In spanish</ Option><option value= "B5" >yahoo! U.S. In chinese</option><option value= "cn" >Yahoo! Option><option value= "UK" >yahoo! United kingdom</option><option value= "ar" >yahoo! Argentina </option><option value= "AA" >yahoo! asia</option><option value= "au" >Yahoo! Australia</ option> <option value= "br" >yahoo! brazil</option><option value= "Ca" >yahoo! Canada in english</option><option value= "CF" >yahoo! Canada in French</option><option value= "FR" >yahoo! france</option><option value= "de" >yahoo! germany</option><option value= "HK" > Yahoo! Kong</option><option value= "in" >yahoo! india</option><option value= "it" >Yahoo! Italy</option><option value= "KR" >yahoo! korea</option><option value= "mx" >Yahoo! Mexico< /option><option value= "SG" >yahoo! singapore</option><option value= "es" >Yahoo! Spain</ Option><option value= "TW" >yahoo! taiwan</option></select></p><p><label for= " Sex "accesskey=" G "><span class=" required ">*</span> gender:</label><select name=" Sex "id=" Sex "><option value=" ">[select] </option><option value=" M ">male</option><option value = F >female</option></select></p><p><label for= accesskey=Y ><span class= required >*</span> Yahoo! Id:</label><input type= text value= id= > <span class= "B" > @yahoo. COM</SPAN><BR/><span class= "Explain" >id may consist of-A-Z, 0-9, Underscores, and a single dot (.) </span></p><p><label for= "PW" accesskey= "P" ><span class= "required" >*</span> Password:</label><input type= "Password" value= "id=" PW "/><br/><span class=" explain ">Six characters or more; Capitalization Matters!</span></p><p><label for= "pw2" accesskey= "R" ><span class= " Required ">*</span> re-type password:</label><input type=" password "value=" "id=" Pw2 "/></p" ><div id= "Submit" ><input type= "Submit" value= "submit" class= "Submit"/> <input type= "reset" value= " Reset "class=" Submit "/></div></form>
3, using DL, DT, DD to layout
This is a play, practice method, of course, diagram one of the design can also be used in other more ways to layout, with DL, DT, DD to layout only for a comment.
DL: Represents an HTML custom list
DT: Represents an HTML custom list group
Dd:html Custom List Description
Although the DL, DT, DD in the semantic and not very good performance Map, but the DL, DT, DD layout features can still be used to map a layout, and the effect is good, hehe ...
DT mainly puts the label portion, DD mainly puts input or other.
Note: As with the label layout, there is an IE 3px BUG.
Here's a concrete layout for the Tuyi design:
<styletype= "Text/css" ><!--* {margin:0; padding:0;} Input,select {font-family:arial, Helvetica, Sans-serif; font-size:12px;}. Required {font:0.8em Verdana!important; color: #f68622;}. Explain {color: #808080;}. b {font-weight:bold; font-size:12px;}. democss {font:11px/12px Arial, Helvetica, sans-serif; color: #333;} DemoCSS DL {width:420px}. DEMOCSS DT {width:110px; float:left; padding:4px; padding-top:8px;text-align:right;}. DemoCSS dd{margin:0 0 0 118px; padding:4px; Text-align:left}. DemoCSS input {width:180px}. DemoCSS select#content {width:185px}. DemoCSS input.submit {width:70px;} div#submit {width:298px; text-align:left; padding:4px;padding-left:122px;} * HTML. DEMOCSS input,* HTML. DemoCSS select{margin-left: -3px;} * HTML div#submit input{margin-left:0px;} --></style><form id= "Demoform" class= "DemoCSS" action= "><dl><dt><span class=" Required ">*</span> <labelfor=" fname "accesskey=" F ">first name:</label></dt> <dd><input type= "text" id= "fname" value= ""/></dd><dt><span class= "required" >*</ span> <labelfor= "lname" accesskey= "L" >last name:</label></dt><dd><input "text" Id= "lname" value= "/></dd><dt><span class=" required ">*</span> <labelfor=" content " accesskey= "C" >preferredcontent:</label></dt><dd><select name= "content" id= "Content" > <option value= "Us" selected= "selected" >yahoo! u.s.</option><option value= "E1" >yahoo! U.S. In Spanish</option><option value= "B5" >yahoo! U.S. In chinese</option><option value= "cn" >Yahoo! China</option><option value= "UK" >yahoo! United kingdom</option><option value= "AR" >Yahoo! Argentina</option><option value= "AA" >yahoo! asia</option><option value= "au" >Yahoo! australia</option> <optionvalue= "br" >yahoo! brazil</option><option value= "Ca"; Yahoo! Canada in english</option><option value= "CF" >yahoo! Canada in French</option><option Value= "FR" >yahoo! france</option><option value= "de" >yahoo! germany</option><option "value=" HK ">yahoo!" Kong</option><option value= "in" >yahoo! india</option><option value= "it" > Yahoo! italy</option><option value= "KR" >yahoo! korea</option><option value= "MX" >Yahoo! Mexico</option><option value= "SG" >yahoo! singapore</option><option value= "es" >Yahoo! Spain </option><option value= "TW" >yahoo! Taiwan</option></select></dd><dt><span Class= "Required" >*</span> <labelfor= "Sex" accesskey= "G" >gender:</label></dt><dd ><select name= "Sex" id= "sex" ><option value= "" >[select] </option><option value= "M" >Male </option><option value= "F" >female</option></select></dd><dt>≪span class= required >*</span> <labelfor= accesskey= Y >yahoo! id:</label></dt> <dd><input type= text value= id= > <spanclass= B > @yahoo. COM</SPAN><BR/>< Span class= "Explain" >id may consist A-Z, 0-9, underscores,and a single dot (.) </span></dd><dt><span class= "required" >*</span> <labelfor= "PW" accesskey= "P" > Password:</label></dt><dd><input type= "Password" value= "id=" PW "/><br/><span Class= "explain" >six characters or more; Capitalizationmatters!</span></dd><dt><span class= "Required" >*</span> <labelfor = "Pw2" accesskey= "R" >re-type password:</label></dt><dd><input type= "password" value= "id=" Pw2 "/></dd></dl><div id=" submit "><input type=" Submit "value=" submit "class=" Submit "/> <inputtype= "reset" value= "reset" class= "Submit"/></div></form>
There seems to be a small bug in the layout of the DL,DT,DD, and interested friends can experiment. To add his width attribute to DD, we can calculate the width of DD 294px according to relevant data, add this width property in theory is no problem, under the FF experiment is no problem, but under the IE6, it is miserable