百科狗-知识改变命运!
--

- 表单控制分组 - html5 表单

乐乐1年前 (2023-11-21)阅读数 19#技术干货
文章标签元素

fieldset 元素通常用来对表单中的控制元素进行分组(也包括 label 元素)

浏览器支持

所有主流浏览器都支持标签。

示例

一个拥有,的表单

  title
     click me 
titleclick me

标签定义及使用说明

  • 标签可以将表单内的相关元素分组。标签将表单内容的一部分打包,生成一组相关表单的字段。
  • 当一组表单元素放到标签内时,浏览器会以特殊方式来显示它们,它们可能有特殊的边界、3D 效果,或者甚至可创建一个子表单来处理这些元素。
  • 标签会在相关表单元素周围绘制边框。
  • 标签为元素定义标题。
  • 标签没有必需的或唯一的属性。
Content categories流式内容元素,sectioning root,listed,form-associatedelement,段落内容元素.
Permitted contentAn optionalelement, followed by flow content.
Tag omission不允许,开始标签和结束标签都不能省略。
允许的父元素可接受的任何元素flow content.
DOM接口HTMLFieldSetElement

注意:与几乎任何其他元素不同,WHATWG HTML Rendering规范建议min-width:min-content作为默认样式的一部分,并且许多浏览器都实现了这种样式(或者与其类似的东西).

属性

属性描述
disabled HTML5新增disabled规定该组中的相关表单元素应该被禁用。
form HTML5新增form_id规定 fieldset 所属的一个或多个表单。
name HTML5新增text规定 fieldset 的名称。

HTML 4.01 与 HTML 5 之间的差异

HTML5 中新增了一些的新属性:disabled、form、name,HTML 4.01 中不支持这些属性。

全局属性

标签支持HTML的全局属性。

事件属性

标签支持HTML的事件属性。

实例

对表单中的相关元素进行分组:

personalia:
name:
email:
date of birth:

利用包含radioboxesandtextboxes的 fieldset 模拟一个可编辑的元素。下面的例子只使用了 HTML 和 CSS.

请注意,屏幕朗读和辅助设备不能正确的解析下面的表单,如果不使用正确的元素这个例子是不适合在生产环境中使用.

editable [pseudo]select


/* generic form fields */

fieldset.elist, input[type="text"], textarea, select, option, fieldset.elist ul, fieldset.elist > legend, fieldset.elist input[type="text"], fieldset.elist > legend:after {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

input[type="text"] {
  padding: 0 20px;
}

textarea {
  width: 500px;
  height: 200px;
  padding: 20px;
}

textarea, input[type="text"], fieldset.elist ul, select, fieldset.elist > legend {
  border: 2px #cccccc solid;
  border-radius: 10px;
}

input[type="text"], fieldset.elist, select, fieldset.elist > legend {
  height: 32px;
  font-family: tahoma;
  font-size: 14px;
}

input[type="text"]:hover, textarea:hover, select:hover, fieldset.elist:hover > legend {
  background-color: #ddddff;
}

select {
  padding: 4px 20px;
}

option {
  height: 30px;
  padding: 5px 4px;
}

option:not(:checked), textarea:focus {
  background-color: #ffcccc;
}

fieldset.elist > legend:after, fieldset.elist label {
  height: 28px;
}

input[type="text"], fieldset.elist {
  width: 316px;
}

input[type="text"]:focus {
  background: #ffcccc url("data:image/gif;base64,r0lgodlheaaqanu5apnoxuvr6+uxpdvb2+rq6ri4uo7qxunp6dpt06shv+/rx8vly+nezlo0sbe3t9ksas+qaacev8rkyp2dnf39/qaaak6ursifzhfxcc/qzu3mxyymjexcjnv1dc6mao7u7o+pj2txnoaghtfdpkcdvu3lxm+tcakev9bw1qofvwnjy8kristexnra2nbbobgxsby8vo/mu7kyso9zauzs7msgaiikhf///8zmzp///waaaaaaaaaaaaaaaaaaaaaaach5baeaadkalaaaaaaqabaaaaaxwjxwscwoyzwkmpkkzmoaqdqajdpqaqw2m53nrjlboaarfczomce0c99o8dgnmvm8tm3bbydr9x11dwkzdg5yc2oqjircenx/mxoeetm2q3pxatmlf4mylo17oasdlispmyaioiy0bzmcitmtkbasjgssftmqgxitmjyuotqbbaqhxge0wzcfmtdrmi/qra022nnang1cqqa7") no-repeat 2px center !important;
}

input[type="text"]:focus, textarea:focus, select:focus, fieldset.elist > legend {
  border: 2px #ccaaaa solid;
}

fieldset {
  border: 2px #af3333 solid;
  border-radius: 10px;
}

/* editable [pseudo]select (i.e. fieldsets with [class=elist]) */

fieldset.elist {
  display: inline-block;
  position: relative;
  vertical-align: middle;
  overflow: visible;
  padding: 0;
  margin: 0;
  border: none;
}

fieldset.elist ul {
  position: absolute;
  width: 100%;
  max-height: 320px;
  padding: 0;
  margin: 0;
  overflow: hidden;
  background-color: transparent;
}

fieldset.elist:hover ul {
  background-color: #ffffff;
  border: 2px #af3333 solid;
  left: 2px;
  overflow: auto;
}

fieldset.elist ul > li {
  list-style-type: none;
  background-color: transparent;
}

fieldset.elist label {
  display: none;
  width: 100%;
}

fieldset.elist input[type="text"] {
  width: 100%;
  height: 30px;
  line-height: 30px;
  border: none;
  background-color: transparent;
  border-radius: 0;
}

fieldset.elist > legend {
  display: block;
  margin: 0;
  padding: 0 0 0 5px;
  position: absolute;
  width: 100%;
  cursor: default;
  background-color: #ccffcc;
  line-height: 30px;
  font-style: italic;
}

fieldset.elist:hover > legend {
  position: relative;
  overflow: hidden;
}

fieldset.elist > legend:after {
  width: 20px;
  content: "2335";
  float: right;
  text-align: center;
  border-left: 2px #cccccc solid;
  font-style: normal;
  cursor: default;
}

fieldset.elist:hover > legend:after {
  background-color: #99ff99;
}

fieldset.elist ul input[type="radio"] {
  display: none;
}

fieldset.elist input[type="radio"]:checked ~ label {
  display: block;
  width: 292px;
  background-color: #ffffff;
}

fieldset.elist:hover input[type="radio"]:checked ~ label {
  width: 100%;
}

fieldset.elist:hover label {
  display: block;
  height: 100%;
}

fieldset.elist label:hover {
  background-color: #3333ff !important;
}

fieldset.elist:hover input[type="radio"]:checked ~ label {
  background-color: #aaaaaa;
}









    order a t-shirt 

write your name (simple textbox):

 - 表单控制分组 - html5 表单

choose your size (simple select): small medium large extra large

what address do you want to use? (editable pseudoselect) address…

write a comment:

鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com

免责声明:我们致力于保护作者版权,注重分享,当前被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理!邮箱:344225443@qq.com)

图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!

内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)