网页设计之5种简单的XHTML网页表单
所属分类:
网页制作 / HTML/Xhtml
阅读数:
751
收藏 0赞 0分享
网页设计之5中简单的XHTML网页表单。
技术1:标签三明治
将输入框,选择框和文本框全部包含进 label 元素,并全部设置为块级元素。将单选按钮和多选框显示方式设置为 inline 以便于它们在同一行出现。如果你比较喜欢 label 和单选按钮/多选框出现在不同行,可以选择不把它包含在 label 里面,或者使用硬换行处理。
每种情况都在下面展示了。
当这些看起来比较时髦的时候,W3C 事实上已经含蓄地展示了他们的 label 例子。
主要好处:简单
代码:
label, input, select, textarea {display: block;}
label {margin-bottom: 10px;}
input[type="radio"], input[type="checkbox"] {display: inline;}
<form> <fieldset>
<legend>Contact Form</legend>
<label for="name">
Name</label>
<input id="name" name="name" size="20" />
<label for="email">Email</label>
<input id="email" name="email" size="20" />
<label for=" Choices"> Choices (radio) — <em>wrapped label</em></label>
<input name=" Choice" type="radio" /> Choice 1
<input name=" Choice" type="radio" /> Choice 2
<input name=" Choice" type="radio" /> Choice 3
<label style="margin-bottom: 0pt;" for=" Choices2"> Choices (checkbox) — <em>non-wrapped label, margin reset</em></label>
<input name=" Choice2" type="checkbox" /> Choice 1
<input name=" Choice2" type="checkbox" /> Choice 2
<input name=" Choice2" type="checkbox" /> Choice 3
<div style="height: 10px;"><!-- just to split the demo up --></div>
<label for=" Choices3"> Choices (checkbox) — <em>wrapped, hard line-break</em></label>
<input name=" Choice3" type="checkbox" /> Choice 1
<input name=" Choice3" type="checkbox" /> Choice 2
<input name=" Choice3" type="checkbox" /> Choice 3
<label for="dropdown">
Question</label>
<select id="dropdown"> <optgroup label="Group of Options"></optgroup> <option>Option 1</option> <option>Option 2</option> <option>Option 3</option> </select>
<label for="message">
Message
<textarea cols="36" rows="12" name="message"></textarea>
</label>
<input type="submit" value="send it" />
</fieldset>
</form>
运行结果:
#expamle1 label,#expamle1 input,#expamle1 select,#expamle1 textarea {display: block;}
#expamle1 label {margin-bottom: 10px;}
#expamle1 input[type="radio"],#expamle1 input[type="checkbox"] {display: inline;}
技术2:懒人
许多开发者采用了这种不正统但是快速简单(用换行隔断标记)的方法。虽然能运行,但是对你的 css 能力有害,因为你不需要任何 css 去实现它。
主要好处:快速
代码:
<form> <fieldset>
<legend>Contact Form</legend>
<label for="name">Name</label>
<input id="name" name="name" size="20" /> <label for="email">Email</label>
<input id="email" name="email" size="20" /> <label for=" Choices"> Choices (radio)</label>
<input name=" Choice" type="radio" /> Choice 1
<input name=" Choice" type="radio" /> Choice 2
<input name=" Choice" type="radio" /> Choice 3
<label for=" Choices3"> Choices (checkbox)</label>
<input name=" Choice3" type="checkbox" /> Choice 1
<input name=" Choice3" type="checkbox" /> Choice 2
<input name=" Choice3" type="checkbox" /> Choice 3
<label for="dropdown">Question</label>
<select id="dropdown"> <optgroup label="Group of Options"></optgroup> <option>Option 1</option> <option>Option 2</option> <option>Option 3</option> </select>
<label for="message">Message</label>
<textarea cols="36" rows="12" name="message"></textarea>
<input type="submit" value="send it" />
</fieldset>
</form>
运行结果:
#p#
网页设计之5中简单的XHTML网页表单。
技术3:语义先生
web 标准的信条之一就是考虑数据类型和与之对应的代码。既然表单是一个连续的问题列表,那么有序列表用在这里就非常贴切。
主要好处: 结构化
代码:
ol {
list-style: none;
padding-left: 0;
}
<form> <fieldset>
<legend>Contact Form</legend>
<ol>
<li> <label for="name">Name</label>
<input id="name" name="name" size="20" /></li>
<li> <label for="email">Email</label>
<input id="email" name="email" size="20" /></li>
<li> <label for=" Choices"> Choices (radio)</label>
<input name=" Choice" type="radio" /> Choice 1
<input name=" Choice" type="radio" /> Choice 2
<input name=" Choice" type="radio" /> Choice 3</li>
<li> <label for=" Choices3"> Choices (checkbox)</label>
<input name=" Choice3" type="checkbox" /> Choice 1
<input name=" Choice3" type="checkbox" /> Choice 2
<input name=" Choice3" type="checkbox" /> Choice 3</li>
<li> <label for="dropdown">Question</label>
<select id="dropdown"> <optgroup label="Group of Options"></optgroup> <option>Option 1</option> <option>Option 2</option> <option>Option 3</option> </select></li>
<li> <label for="message">Message</label><textarea cols="36" rows="12" name="message"></textarea></li>
<li>
<input type="submit" value="send it" /></li>
</ol>
</fieldset>
</form>
运行结果:
#example3 ol {
list-style: none;
padding-left: 0;
}
技术4:分而治之
假如你采取将横向表单,需要何种形式?很多情况(客户)会要求横向表单。我们可以依赖的是老伙伴 div,只需要把表单分割成多栏。利用标签三明治方法我们可以很容易的实现。
主要好处:空间的利用
代码:
label, input, select, textarea {display: block;}
label {margin-bottom: 10px;}
input[type="radio"], input[type="checkbox"] {display: inline;}
.form-column {
width: 150px;
height: 250px;
padding-left: 20px;
border-left: 1px solid #ccc;
float: left;
}
<form> <fieldset>
<legend>Contact Form</legend>
<div class="form-column">
<label for="name">
Name</label>
<input id="name" name="name" size="20" />
<label for="email">
Email</label>
<input id="email" name="email" size="20" />
<label for=" Choices"> Choices (radio)</label>
<input name=" Choice" type="radio" /> Choice 1
<input name=" Choice" type="radio" /> Choice 2
<input name=" Choice" type="radio" /> Choice 3</div>
<!-- /form-column -->
<div class="form-column">
<label for=" Choices3"> Choices (radio)</label>
<input name=" Choice2" type="radio" /> Choice 1
<input name=" Choice2" type="radio" /> Choice 2
<input name=" Choice2" type="radio" /> Choice 3
<label for=" Choices3"> Choices (checkbox)</label>
<input name=" Choice2" type="checkbox" /> Choice 1
<input name=" Choice2" type="checkbox" /> Choice 2
<input name=" Choice2" type="checkbox" /> Choice 3
<label for="dropdown">
Question</label>
<select id="dropdown"> <optgroup label="Group of Options"></optgroup> <option>Option 1</option> <option>Option 2</option> <option>Option 3</option> </select>
<input type="submit" value="send it" /></div>
<!-- /form-column -->
</fieldset>
</form>
运行结果:
#Example4 label,#Example4 input, #Example4 select, #Example4 textarea {display: block;}
#Example4 label {margin-bottom: 10px;}
#Example4 input[type="radio"], #Example4 input[type="checkbox"] {display: inline;}
#Example4 .form-column {
width: 150px;
height: 250px;
padding-left: 20px;
border-left: 1px solid #ccc;
float: left;
}
技术5:老学究似的懒人
如果你不想纠缠与 CSS,非常匆忙,并且不打算做浏览器测试,你应该另外找个新工作。玩笑而已,这个是为你准备的。
主要好处:直观
代码:
<form> <fieldset>
<legend>Contact Form</legend>
<table border="0">
<tbody>
<tr><!-- column one -->
<td><label for="name">Name</label>
<input id="name" name="name" size="20" /> <label for="email">Email</label>
<input id="email" name="email" size="20" /> <label for=" Choices"> Choices (radio)</label>
<input name=" Choice" type="radio" /> Choice 1
<input name=" Choice" type="radio" /> Choice 2
<input name=" Choice" type="radio" /> Choice 3</td>
<!-- column two -->
<td><label for=" Choices3"> Choices (checkbox)</label>
<input name=" Choice3" type="checkbox" /> Choice 1
<input name=" Choice3" type="checkbox" /> Choice 2
<input name=" Choice3" type="checkbox" /> Choice 3
<label for="dropdown">Question</label>
<select id="dropdown"> <optgroup label="Group of Options"></optgroup> <option>Option 1</option> <option>Option 2</option> <option>Option 3</option> </select></td>
<!-- column three -->
<td><label for="message">Message</label>
<input type="submit" value="send it" /></td>
</tr>
</tbody></table>
</fieldset>
</form>
运行结果:
W3C教程(14):W3C RDF和OWL活动
RDF 和 OWL 是两项重要的语义网技术。
RDF 和 OWL 是两项重要的语义网技术。
语义网 (Semantic Web)
语义网是为资产管理、企业整合及网络数据的共享和重用提供的一个框架。
语义网为企业、应
收藏 0赞 0分享
W3C教程(16):其他的W3C活动
本节概况了其他一些重要和有趣的 W3C 活动。
本节概况了其他一些重要和有趣的 W3C 活动。
Web Accessibility Initiative (WAI)
WAI 定义了如何使残障人士更易使用 Web 内容的指
收藏 0赞 0分享
W3C教程(13):W3C WSDL 活动
Web Services 与应用程序到应用程序的通信有关。WSDL 是一门基于 XML 的 Web Services 描述语言。
Web Services 与应用程序到应用程序的通信有关。
WSDL 是一门基于 XML 的 Web Se
收藏 0赞 0分享
W3C教程(15):W3C SMIL 活动
SMIL 向 web 增加了对定时和媒介同步的支持。
SMIL 向 web 增加了对定时和媒介同步的支持。
SMIL
SMIL (Synchronized Multimedia Integration Language)
收藏 0赞 0分享
深层优化 提高网站的访问速度的一些技巧
深层优化 提高网站的访问速度的一些技巧
网站访问速度可以直接影响到网站的流量,而网站的访问量几乎与网站的利益直接挂钩,因此网站的速度问题成为企业及站长十分关注的问题。现在网站越来越多,不少朋友的网站打开速度很
收藏 0赞 0分享
网页制作中使用规范的HTML代码的几点
许多网站设计者最常犯的错误便是当其网页能够在IE下正常显示便认为其代码正确无误,甚至常看到有人在抱怨其网站排名不理想,到其网站简单看一下便可发现HTML代码中充斥各种各样的错误,在那样的代码基础上无论付出多少努力去优化网站结果都可能
收藏 0赞 0分享
关于超链接的一些问题
很高兴参加了这一期的薯片会,认识了几个朋友~~不料的却是今天我要来总结一下
很高兴参加了这一期的薯片会,认识了几个朋友~~不料的却是今天我要来总结一下
本次薯片会我们总共讨论了三个议题:
A、 如何让“用
收藏 0赞 0分享
入门:HTML的基本标签和属性简单介绍
HTML是由标志和属性构成的,它们一起被用来告诉浏览器应该如何显示一页文档。标志用来引用一段文字或是一幅图片等文档部件,属性是标志的选项,在标志中修饰,如颜色,对齐方式,高度和宽度等。很多标志都成对出现,例如有 就有 前一个表示开始
收藏 0赞 0分享
总结XHTML代码常见的应用问题
一段时间以来,发现有很多人XHTML都不会用,不光是普通的初学者,有的程序员都不是很清楚该怎么写这个XHTML,我这里呢算是把一些常见的应用问题做一个总结,也算能使得大家能在沟通,合作上能形成默契。
一段时间以来,发现有
收藏 0赞 0分享
查看更多