html 怎么设置漂亮的表单样式

html-css011

html 怎么设置漂亮的表单样式,第1张

html 设置漂亮的表单样式,以下是代码:

1、编写一个from表单

<form id="payment">

<fieldset>

<legend>用户详细资料</legend>

<ol>

<li>

<label for="name">用户名称:</label>

<input id="name" name="name" type="text" placeholder="请输入用户名" required autofocus>

</li>

<li>

<label for="email">邮件地址:</label>

<input id="email" name="email" type="email" placeholder="[email protected]" required>

</li>

<li>

<label for="phone">联系电话:</label>

<input id="phone" name="phone" type="tel" placeholder="010-12345678" required>

</li>

</ol>

</fieldset>

<fieldset>

<legend>家庭住址(收货地址):</legend>

<ol>

<li>

<label for="address">详细地址:</label>

<textarea id="address" name="address" rows="1" required></textarea>

</li>

<li>

<label for="postcode">邮政编码:</label>

<input id="postcode" name="postcode" type="text" required>

</li>

<li>

<label for="country">国家:</label>

<input id="country" name="country" type="text" required>

</li>

</ol>

</fieldset>

<fieldset>

<legend>付费方式</legend>

<ol>

<li>

<fieldset>

<legend>信用卡类型</legend>

<ol>

<li>

<input id="visa" name="cardtype" type="radio">

<label for="visa">中国工商银行</label>

</li>

<li>

<input id="amex" name="cardtype" type="radio">

<label for="amex">中国人民银行</label>

</li>

<li>

<input id="mastercard" name="cardtype" type="radio">

<label for="mastercard">中国建设银行</label>

</li>

</ol>

</fieldset>

</li>

<li>

<label for="cardnumber">银行卡号:</label>

<input id="cardnumber" name="cardnumber" type="number" required>

</li>

<li>

<label for="secure">验 证 码:</label>

<input id="secure" name="secure" type="number" required>

</li>

<li>

<label for="namecard">持 卡 人:</label>

<input id="namecard" name="namecard" type="text" placeholder="确定是否该卡用户!" required>

</li>

</ol>

</fieldset>

<fieldset>

<button type="submit">现在购买</button>

</fieldset>

</form>

2、编写css样式

<style type="text/css">

/*分别定义HTML中和标记之的距离样式*/

html, body, h1, form, fieldset, legend, ol, li {

margin: 0

padding: 0

}

/*定义<body>标记样式*/

body {

background: #ffffff

color: #111111

font-family: Georgia, "Times New Roman", Times, serif

padding-left: 20px

}

/*定义付费内容的样式*/

form#payment {

background: #9cbc2c

-webkit-border-radius: 5px

border-radius: 5px

padding: 20px

width: 400px

margin:auto

}

form#payment fieldset {

border: none

margin-bottom: 10px

}

form#payment fieldset:last-of-type { margin-bottom: 0}

form#payment legend {

color: #384313

font-size: 16px

font-weight: bold

padding-bottom: 10px

text-shadow: 0 1px 1px #c0d576

}

form#payment >fieldset >legend:before {

content: "Step " counter(fieldsets) ": "

counter-increment: fieldsets

}

form#payment fieldset fieldset legend {

color: #111111

font-size: 13px

font-weight: normal

padding-bottom: 0

}

form#payment ol li {

background: #b9cf6a

background: rgba(255, 255, 255, .3)

border-color: #e3ebc3

border-color: rgba(255, 255, 255, .6)

border-style: solid

border-width: 2px

-webkit-border-radius: 5px

line-height: 30px

list-style: none

padding: 5px 10px

margin-bottom: 2px

}

form#payment ol ol li {

background: none

border: none

float: left

}

form#payment label {

float: left

font-size: 13px

width: 110px

}

form#payment fieldset fieldset label {

background: none no-repeat left 50%

line-height: 20px

padding: 0 0 0 30px

width: auto

}

form#payment fieldset fieldset label:hover { cursor: pointer}

form#payment input:not([type=radio]), form#payment textarea {

background: #ffffff

border: #FC3 solid 1px

-webkit-border-radius: 3px

font: italic 13px Georgia, "Times New Roman", Times, serif

outline: none

padding: 5px

width: 200px

}

form#payment input:not([type=submit]):focus, form#payment textarea:focus {

background: #eaeaea

border: #F00 solid 1px

}

form#payment input[type=radio] {

float: left

margin-right: 5px

}

</style>

3、漂亮的表单生成。

一、只对表格table标签设置边框   -  TOP

只对table标签设置border(边框)样式,将让此表格最外层table一个边框,而表格内部不产生边框样式。

案例详细如下:

1、对应css代码

<style>.table-a table{border:1px solid #F00} /* css注释:只对table标签设置红色边框样式 */ style>

2、对应html代码片段

<divclass="table-a"><tablewidth="400"border="0"cellspacing="0"cellpadding="0"><tr><tdwidth="105">站名td><tdwidth="181">网址td><tdwidth="112">说明td>tr><tr><td>DIVCSS5td><td>www.divcss5.comtd><td>CSS学习td>tr><tr><td>CSS5td><td>www.css5.com.cntd><td>CSS切图td>tr>table>div>

二、对td设置边框   -   TOP

对table表格td设置边框样式,表格对象内td将实现边框样式,但中间部分td会导致出现双边框。

详细案例教程如下:

1、对应css代码

<style>.table-b table td{border:1px solid #F00} /* css注释:只对table td标签设置红色边框样式 */ style>

2、对应html源代码片段

<divclass="table-b"><tablewidth="400"border="0"cellspacing="0"cellpadding="0"><tr><tdwidth="105">站名td><tdwidth="181">网址td><tdwidth="112">说明td>tr><tr><td>DIVCSS5td><td>www.divcss5.comtd><td>CSS学习td>tr><tr><td>CSS5td><td>www.css5.com.cntd><td>CSS切图td>tr>table>

三、对table和td技巧性设置表格边框   -   TOP

如上第二点,只对表格对象td设置单一边框样式,中间部分td与td标签之间就会出现双边框现象。

解决方法:对td只设置两个边的边框,对table也设置两个边的边框样式。

解释:对td设置左与上边框,这样td与td相邻就会只出现单一边框样式,这样就会出现表格右侧和下部没有边框,这个时候我们设置table右和下 边框解决显示右侧和下侧td剩下未显示边框。

1、对应css代码:

<style>.table-c table{border-right:1px solid #F00border-bottom:1px solid #F00} .table-c table td{border-left:1px solid #F00border-top:1px solid #F00} /* css 注释: 只对table td设置左与上边框; 对table设置右与下边框; 为了便于截图,我们将css 注释说明换行排版 */ style>

2、对应html源代码片段:

<divclass="table-c"><tablewidth="400"border="0"cellspacing="0"cellpadding="0"><tr><tdwidth="105">站名td><tdwidth="181">网址td><tdwidth="112">说明td>tr><tr><td>DIVCSS5td><td>www.divcss5.comtd><td>CSS学习td>tr><tr><td>CSS5td><td>www.css5.com.cntd><td>CSS切图td>tr>table>

四、对table和td设置背景,实现完美表格边框   -   TOP

1、基础设置

1)、先设置table css背景为红色

2)、设置table单元之间间距为1

使用DW软件辅助设置table表格单元间距为1,具体DW软件可视化操作步骤简要说明,首先(视图模式)选中表格后,对应DW软件编辑窗口底部会“属性”面板会出现对应table表格属性设置地方,我们将“间隔”填写为“1”。这个时候我们会看到table表格标签里cellspacing值为“1”(cellspacing="1")。

借助DW软件设置表格单元之间间距

直接对

标签内cellspacing="1"即可,得到:

<tablewidth="400"border="0"cellspacing="1"cellpadding="0">

3)、设置table td背景为白色

2、css代码:

<style>.table-d table{ background:#F00} .table-d table td{ background:#FFF} /* css注释:设置table背景为红色,td背景为白色 */ style>

3、对应html源代码:

<divclass="table-d"><tablewidth="400"border="0"cellspacing="1"cellpadding="0"><tr><tdwidth="105">站名td><tdwidth="181">网址td><tdwidth="112">说明td>tr><tr><td>DIVCSS5td><td>www.divcss5.comtd><td>CSS学习td>tr><tr><td>CSS5td><td>www.css5.com.cntd><td>CSS切图td>tr>table>div>

五、css table表格边框实现总结   -  TOP

以上四种方式实现table表格边框样式方法,推荐使用第三和第四种方法来解决表格边框样式。希望DIVCSS5整理总结html table边框布局方法对大家有帮助并能掌握,平时需要时灵活运用。

在网页的<head></head>标签中间加上

<style>

table {

border-left: 1px solid #C1DAD7/*边框颜色*/

border-top: 1px solid #C1DAD7/*边框颜色*/

}

td {

border-right: 1px solid #C1DAD7/*边框颜色*/

border-bottom: 1px solid #C1DAD7/*边框颜色*/

}

</style>