网页设计之5种简单的XHTML网页表单

互联网   发布时间:2000-01-01 00:00:00   作者:佚名   我要评论
网页设计之5中简单的XHTML网页表单。 技术1:标签三明治 将输入框,选择框和文本框全部包含进 label 元素,并全部设置为块级元素。将单选按钮和多选框显示方式设置为 inline 以便于它们在同一行出现。如果你比较喜欢 label

网页设计之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>
运行结果:

相关文章

  • HTML 表格详解(简单易懂较详细)

    HTML表格用于在网页上展示数据,通过标签及其相关标签来创建,表格由行和列组成,每一行包含一个或多个单元格,单元格可以包含文本、图像、链接等元素,本文将详细介绍HTML表格
    2025-03-12
  • 禁止HTML页面滚动的操作方法

    本文介绍了三种禁止HTML页面滚动的方法:通过CSS的overflow属性、使用JavaScript的滚动事件监听器以及使用CSS的position:fixed属性,每种方法都有其适用场景和优缺点,感兴
    2025-02-24
  • 使用HTML和CSS实现文字镂空效果的代码示例

    在 Web 开发中,文本的视觉效果是提升用户体验的重要因素之一,通过 CSS 技巧,我们可以创造出许多独特的效果,例如文字镂空效果,本文将带你一步一步实现一个简单的文字镂空
    2024-11-17
  • Html去除a标签的默认样式的操作代码

    在Html中,a标签默认的超链接样式是蓝色字体配下划线,这可能不满足所有设计需求,如需去除这些默认样式,可以通过CSS来实现,本文给大家介绍Html去除a标签的默认样式的操作代码
    2024-09-25
  • HTML文本域如何设置为禁止用户手动拖动

    在HTML中,可以通过设置CSS的resize属性为none,来禁止用户手动拖动文本域(textarea)的大小,这种方法简单有效,适用于大多数现代浏览器,但需要在老旧浏览器中进行测试以确保
    2024-09-25
  • 如何通过HTML/CSS 实现各类进度条的功能

    本文详细介绍了如何利用HTML和CSS实现多种风格的进度条,包括基础的水平进度条、环形进度条以及球形进度条等,还探讨了如何通过动画增强视觉效果,内容涵盖了使用HTML原生标签
    2024-09-19
  • HTML中Canvas关键知识点总结

    Canvas 提供了一套强大的 2D 绘图 API,适用于各种图形绘制、图像处理和动画制作,可以帮助你创建复杂且高效的网页图形应用,这篇文章主要介绍了HTML中Canvas关键知识点总结
    2024-06-03
  • html table+css实现可编辑表格的示例代码

    本文主要介绍了html table+css实现可编辑表格的示例代码,主要使用HTML5的contenteditable属性,文中通过示例代码介绍的非常详细,需要的朋友们下面随着小编来一起学习学习
    2024-03-06
  • HTML中使用Flex布局实现双行夹批效果

    本文主要介绍了HTML中使用Flex布局实现双行夹批效果,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习
    2024-02-22
  • HTML+CSS实现炫酷登录切换的项目实践

    在网站开发中,登录页面是必不可少的一部分,本文就来介绍一下HTML+CSS实现登录切换,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需
    2024-02-02

最新评论