2008-10-07 78 views

回答

0

我會使用div標籤查找頁面上的佈局數據。

對於表格數據,表格仍然非常有用,但是對於佈置頁面而言,表格仍然非常有用。

在這裏查看stackoverflow.com,可能有一些很好的例子。

+2

hmm .... SO上的頁面源代碼看起來有很多表格。 :) – 2008-10-07 19:02:47

+0

`

`標籤在本頁面上使用了24次。 – 2014-01-29 22:00:58

0

考慮將字段名稱放在字段上方,而不是旁邊。我覺得這是最好的。

12

尼克·裏格比寫了題爲除了Prettier Accessible Forms

列表中的優秀文章使用字段集,傳說,標籤。高度語義。

3

您可以嘗試將表單儘量剝離,並根據需要使用<label>和各種表單輸入元素,並在CSS中使用clear:left;屬性。

這將確保每條線重新開始,而無需將表格的每一行都包含在額外的<div><p>中,甚至無法將其列出。

.formlabel{ 
    clear:left; 
    display:block; 
    float:left; 
    margin:0 0 1em 0; 
    padding:0 0.5em 0 0; 
    text-align:right; 
    width:8em; 
} 

.forminput{ 
    float:left; 
    margin:0 0.5em 0.5em 0; 
} 

.formwarning{ 
    clear:left; 
    float:left; 
    margin:0 0.5em 1em 0; 
} 

下面是示出各種輸入類型的示例,並且根據需要,可以隱藏或樣式的額外驗證消息的示例HTML形式:

<fieldset><legend>Details</legend> 
    <label for="name" class="formlabel">Name</label> 
     <input id="name" name="name" type="text" class="forminput" /> 
     <div class="formwarning">Validation error message</div> 

    <label for="dob_year" class="formlabel">DOB</label> 
     <div class="forminput"> 
     <input id="dob_year" name="dob_year" type="text" size="4" />/
     <input id="dob_month" name="dob_month" type="text" size="2" />/
     <input id="dob_day" name="dob_day" type="text" size="2" /> 
     </div> 

    <label class="formlabel">Sex</label> 
     <label for="female" class="forminput">Female</label> 
     <input id="female" name="sex" type="radio" class="forminput" /> 
     <label for="male" class="forminput">Male</label> 
     <input id="male" name="sex" type="radio" class="forminput" /> 

    <label for="state" class="formlabel">State</label> 
     <select id="state" name="state" class="forminput"> 
     <option>ACT</option> 
     <option>New South Wales</option> 
     <option>Northern Territory</option> 
     <option>Queensland</option> 
     <option>South Australia</option> 
     <option>Tasmania</option> 
     <option>Victoria</option> 
     <option>Western Australia</option> 
     </select> 

    <label for="deadseal" class="formlabel">Death certificate</label> 
     <input id="deadseal" name="deadseal" type="file" class="forminput" /> 
</fieldset> 

在上面的例子中,DOB確實有一個額外的<div>混亂的事情。如果您在需要時將日期斜槓作爲:after僞元素的一部分進行設置,則可以將其刪除。

原來還好在Opera 11.60,Firefox的11,谷歌Chrome 18和Internet Explorer 8

0

HTML

<form> 
<div id="personal_name"> 
<label>Name</label> 
<input name="name" /> 
</div> 
</form> 

CSS

form 
{display: table} 
#personal_name 
{display: table-row} 
#personal_name input, #personal_name label 
{display: table-cell} 

我認爲這是足夠。

相關問題