10.6. HTML fieldset 标签 -- 表单分组(转http://www.dreamdu.com/xhtml/tag_fieldset)

本文介绍了如何使用HTML中的fieldset和legend标签对表单元素进行有效分组,以提高表单的可读性和可用性。通过示例展示了不同类型的表单输入如何被组织到不同的组中,并为每个组提供了描述性的标题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

10.6.1. HTML legend 标签

如果一个页面的表单项太多,我们最好把它们分组显示,就像使用p标签分开段落一样,可以使用fieldsetlegend标签对表单内容分组.

fieldset 标签 -- 对表单进行分组
  • fieldset标签是成对出现的,以<fieldset>开始,以</fieldset>结束
  • 一个表单可以有多个<fieldset>,每对<fieldset>为一组,每组内容的描述可以使用legend标签说明
  • 引用网址:http://www.dreamdu.com/xhtml/tag_fieldset/
  • 属性:

示例

<form action="dreamdu.php" method="post" id="dreamduform">
        <fieldset>
                <legend>用户名与密码:</legend>
                <input id="hiddenField" name="hiddenField" type="hidden" value="hiddenvalue" />
                <label for="username">用户名:</label>
                <input type="text" id="username" name="username" value="dreamdu" />
                <label for="pass">密码:</label>
                <input type="password" id="pass" name="pass" />
        </fieldset>
        <fieldset>
                <legend>性别:</legend>
                <label for="boy"></label>
                <input type="radio" value="1" id="sex" name="sex" />
                <label for="girl"></label>
                <input type="radio" value="2" id="sex" name="sex" />
                <label for="sex">保密</label>
                <input type="radio" value="3" id="sex" name="sex" />
        </fieldset>
        <fieldset>
                <legend>我最喜爱的:</legend>
                <label for="computer">计算机</label>
                <input type="checkbox" value="1" id="fav" name="fav" />
                <label for="trval">旅游</label>
                <input type="checkbox" value="2" id="fav" name="fav" />
                <label for="buy">购物</label>
                <input type="checkbox" value="3" id="fav" name="fav" />
        </fieldset>
        <fieldset>
                <legend>对梦之都的意见:</legend>
                <label for="select">你对梦之都的感觉</label>
                <select size="1" id="select" name="select">
                        <option>很全面,很好</option>
                        <option>一般般吧,还要努力</option>
                        <option>有很多问题,不过还可以</option>
                </select>
        </fieldset>
        <fieldset>
                <legend>梦之都编程语言选择:</legend>
                <label for="multipleselect">你想在梦之都学习的编程语言</label>
                <select size="10" multiple="multiple" id="multipleselect" name="multipleselect">
                        <option>XHTML</option>
                        <option>CSS</option>
                        <option>JAVASCRIPT</option>
                        <option>XML</option>
                        <option>PHP</option>
                        <option>C#</option>
                        <option>JAVA</option>
                        <option>C++</option>
                        <option>PERL</option>
                </select>
        </fieldset>
        <fieldset>
                <legend>我要在梦之都学:</legend>
                <label for="WebDesign">选择一个你在梦之都最想学的</label>
                <select id="WebDesign" name="WebDesign">
                        <optgroup label="client">
                                <option value="HTML">HTML</option>
                                <option value="CSS">CSS</option>
                                <option value="javascript">javascript</option>
                        </optgroup>
                        <optgroup label="server">
                                <option value="PHP">PHP</option>
                                <option value="ASP">ASP</option>
                                <option value="JSP">JSP</option>
                        </optgroup>
                        <optgroup label="database">
                                <option value="Access">Access</option>
                                <option value="MySQL">MySQL</option>
                                <option value="SQLServer">SQLServer</option>
                        </optgroup>
                </select>
        </fieldset>
        <fieldset>
                <legend>个人化信息:</legend>
                <label for="myimage">个性照片上传</label>
                <input type="file" id="myimage" name="myimage" size="35" maxlength="255" />
                <label for="contactus">联系我们</label>
                <textarea cols="50" rows="10" id="contactus" name="contactus">
                        可爱的猴子
                </textarea>
        </fieldset>
        <fieldset>
                <legend>提交:</legend>
                <input type="submit" value="submit" id="submit" name="submit" />
                <input type="reset" value="reset" id="reset" name="reset" />
        </fieldset>
</form>

HTML fieldset 标签示例 -- 可以尝试编辑

说明

  • legend的内容一般显示在左上角
  • 通过CSS可以改变fieldset边框显示方式,也可以改变legend的显示方式.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>IIS 10.0 详细错误 - 404.0 - Not Found</title> <style type="text/css"> <!-- body { margin: 0; font-size: .7em; font-family: Verdana, Arial, Helvetica, sans-serif; } code { margin: 0; color: #006600; font-size: 1.1em; font-weight: bold; } .config_source code { font-size: .8em; color: #000000; } pre { margin: 0; font-size: 1.4em; word-wrap: break-word; } ul, ol { margin: 10px 0 10px 5px; } ul.first, ol.first { margin-top: 5px; } fieldset { padding: 0 15px 10px 15px; word-break: break-all; } .summary-container fieldset { padding-bottom: 5px; margin-top: 4px; } legend.no-expand-all { padding: 2px 15px 4px 10px; margin: 0 0 0 -12px; } legend { color: #333333; ; margin: 4px 0 8px -12px; _margin-top: 0px; font-weight: bold; font-size: 1em; } a:link, a:visited { color: #007EFF; font-weight: bold; } a:hover { text-decoration: none; } h1 { font-size: 2.4em; margin: 0; color: #FFF; } h2 { font-size: 1.7em; margin: 0; color: #CC0000; } h3 { font-size: 1.4em; margin: 10px 0 0 0; color: #CC0000; } h4 { font-size: 1.2em; margin: 10px 0 5px 0; } #header { width: 96%; margin: 0 0 0 0; padding: 6px 2% 6px 2%; font-family: "trebuchet MS", Verdana, sans-serif; color: #FFF; background-color: #5C87B2; } #content { margin: 0 0 0 2%; position: relative; } .summary-container, .content-container { background: #FFF; width: 96%; margin-top: 8px;
最新发布
04-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值