經常看到一些表單會有一種相同的特殊效果,就是表單說明文字會浮在邊線上,可以用css控制實現,但是其實html有一個fieldset標簽來實現這效果
HTML <fieldset> 標簽
定義和用法
fieldset 元素可將表單內的相關元素分組。
<fieldset> 標簽將表單內容的一部分打包,生成一組相關表單的字段。
當一組表單元素放到 <fieldset> 標簽內時,瀏覽器會以特殊方式來顯示它們,它們可能有特殊的邊界、3D 效果,或者甚至可創(chuàng)建一個子表單來處理這些元素。
<fieldset> 標簽沒有必需的或唯一的屬性。
<legend> 標簽為 fieldset 元素定義標題。
實例
組合表單中的相關元素:
<form>
<fieldset>
<legend>health information</legend>
height: <input type="text" />
weight: <input type="text" />
</fieldset>
</form>
實現效果如下
還可以用css控制邊線的樣式和legend的樣式。
<form>
<fieldset>
<legend>health information</legend>
height: <input type="text" />
weight: <input type="text" />
</fieldset>
</form>