我们来介绍css入门,我们从基础标签介绍起,现阶段我们看到的网站大部分是div和css可以实现,今天介绍css定义表单样式,设计下拉菜单样式,设计注册表
我们看看效果图
demo1
<!doctype html> <html> <head> <meta charset="utf-8"> <title></title> <STYLE type="text/css"></STYLE> </head> <body> <form id="form1" name="form1" method="post" action=""> <p> 文本框: <input type="text" name="textfield" id="textfield" /> </p> <p>文本区域: <textarea name="textarea" id="textarea" cols="45" rows="5"></textarea> </p> <p>复选框: a <input type="checkbox" name="checkbox" id="checkbox" /> b <input type="checkbox" name="checkbox2" id="checkbox2" /> c <input type="checkbox" name="checkbox3" id="checkbox3" /> </p> <p>单选按钮: a <input type="radio" name="radio" id="radio" value="radio" /> b <input type="radio" name="radio2" id="radio2" value="radio2" /> c <input type="radio" name="radio3" id="radio3" value="radio3" /> </p> <p>下载菜单: <select name="select" id="select"> <option value="1">a</option> <option value="2">b</option> <option value="3">c</option> </select> </p> <p> <input type="submit" name="button" id="button" value="提交" /> <input type="reset" name="button2" id="button2" value="重置" /> </p> </form> </body> </html>
demo2
<!doctype html> <html> <head> <meta charset="utf-8"> <title></title> <STYLE type="text/css"></STYLE> </head> <body> <form id="form1" name="form1" method="post" action=""> <fieldset> <legend>表单结构</legend> <p> <label for="textfield">文本框:</label> <input type="text" name="textfield" id="textfield" /> </p> <p> <label for="textarea">文本区域:</label> <textarea name="textarea" id="textarea" cols="45" rows="5"></textarea> </p> <p>复选框: <label for="checkbox">a</label> <input type="checkbox" name="checkbox" id="checkbox" /> <label for="checkbox2">b</label> <input type="checkbox" name="checkbox2" id="checkbox2" /> <label for="checkbox3">c</label> <input type="checkbox" name="checkbox3" id="checkbox3" /> </p> <p>单选按钮: <label for="radio">a</label> <input type="radio" name="radio" id="radio" value="radio" /> <label for="radio2">b</label> <input type="radio" name="radio2" id="radio2" value="radio2" /> <label for="radio3">c</label> <input type="radio" name="radio3" id="radio3" value="radio3" /> </p> <p> <label for="select">下载菜单:</label> <select name="select" id="select"> <option value="1">a</option> <option value="2">b</option> <option value="3">c</option> </select> </p> <p> <input type="submit" name="button" id="button" value="提交" /> <input type="reset" name="button2" id="button2" value="重置" /> </p> </fieldset> </form> </body> </html>
demo3
<!doctype html> <html> <head> <meta charset="utf-8"> <title></title> <STYLE type="text/css"> .title { width: 100px; /* 宽度 */ float: left; /* 向左浮动 */ text-align: right; /* 文本右对齐 */ font-weight: bold; /* 加粗提示文本 */ } .center { text-align: center; } #form1 { text-align: center; /* 定义表单内对象居中显示 */ } #form1 fieldset { width: 500px; /* 定义表单区域宽度 */ margin: 0 auto; /* 文本对象居中显示 */ text-align: left; /* 文本左对齐 */ } #form1 #textfield {/* 文本框样式 */ width: 16em; /* 文本框的宽度 */ border: solid 1px #aaa; /* 文本框的边框样式 */ font-size: 14px; /* 字体大小 */ color: #666; /* 字体颜色 */ position: relative; /* 相对定位 */ top: -3px; /* 向上移动位置 */ } #form1 #textarea {/* 文本区域样式 */ width: 30em; /* 文本区域宽度 */ height: 8em; /* 高度 */ border: solid 1px #aaa; /* 边框样式 */ font-size: 12px; /* 字体大小 */ color: #666; /* 字体颜色 */ } .checkbox {/* 复选框样式类 */ border: solid 1px #fff; /* 边框样式 */ position: relative; /* 相对定位 */ top: 3px; /* 向下移动位置 */ left: -2px; /* 向左移动位置 */ } #radio {/* 单选按钮样式 */ border: solid 1px #fff; /* 边框样式 */ position: relative; /* 相对定位 */ top: 3px; /* 向下移动位置 */ left: -1px; /* 向左移动位置 */ } </STYLE> </head> <body> <form id="form1" name="form1" method="post" action=""> <fieldset> <legend>表单结构</legend> <p> <label for="textfield" class="title">文本框:</label> <input type="text" name="textfield" id="textfield" /> </p> <p> <label for="textarea" class="title">文本区域:</label> <textarea name="textarea" id="textarea" cols="45" rows="5"></textarea> </p> <p><span class="title">复选框:</span> <label for="checkbox">a</label> <input type="checkbox" name="checkbox" id="checkbox" /> <label for="checkbox2">b</label> <input type="checkbox" name="checkbox2" id="checkbox2" /> <label for="checkbox3">c</label> <input type="checkbox" name="checkbox3" id="checkbox3" /> </p> <p><span class="title">单选按钮:</span> <label for="radio">a</label> <input type="radio" name="radio" id="radio" value="radio" /> <label for="radio2">b</label> <input type="radio" name="radio2" id="radio2" value="radio2" /> <label for="radio3">c</label> <input type="radio" name="radio3" id="radio3" value="radio3" /> </p> <p> <label for="select" class="title">下载菜单:</label> <select name="select" id="select"> <option value="1">a</option> <option value="2">b</option> <option value="3">c</option> </select> </p> <p class="center"> <input type="submit" name="button" id="button" value="提交" /> <input type="reset" name="button2" id="button2" value="重置" /> </p> </fieldset> </form> </body> </html>
2.设计下拉菜单样式
<!doctype html> <html> <head> <meta charset="utf-8"> <title></title> <style> body { background-color: #f5f0c2; } select { width: 160px; } form { color: #0c12f5; font-size: 16px; } .r { background-color: #FF0000; color: #000; } .o { background-color: #FF9900; color: #000; } .y { background-color: #FFFF00; color: #000; } .g { background-color: #009900; color: #000; } .q { background-color: #21b9b4; color: #000; } .b { background-color: #0000FF; color: #000; } .z { background-color: #7c176a; color: #000; } </style> </head> <body> <form> <label for="color"> 请选择你喜欢的一种颜色:</label> <select name="" id="clolr"> <option class="r">红</option> <option class="o">橙</option> <option class="y">黄</option> <option class="g">绿</option> <option class="q">青</option> <option class="b">蓝</option> <option class="z">紫</option> </select> </form> </body> </html>
3.css设计注册表
<!doctype html> <html> <head> <meta charset="utf-8"> <title></title> <style> body, div, h1, form, fieldset, input, textarea { margin: 0; padding: 0; border: 0; outline: none; } html { height: 100%; } body { background: #728eaa; font-family: 宋体; margin-bottom: 20px; padding-bottom: 40px; } #container { width: 430px; margin: 30px auto; padding: 60px 30px; background: #c9d0de; border: 1px solid #e1e1e1; } h1 { font-size: 35px; color: #445668; text-align: center; margin: 0 0 35px 0; text-shadow: 0px 2px 0px #f2f2f2; } label { float: left; clear: left; margin: 11px 20px 0 0; width: 95px; text-align: right; font-size: 18px; font-family: 宋体; color: #445668; text-shadow: 0px 1px 0px #f2f2f2; } input { width: 210px; height: 35px; padding: 5px 20px 0px 20px; margin: 0 0 20px 0; background: #5E768D; border-radius: 5px; font-family: 宋体, sans-serif; font-size: 16px; color: #a1b2c3; text-shadow: 0px -1px 0px #38506b; } textarea { width: 210px; height: 170px; padding: 12px 20px 0px 20px; margin: 0 0 20px 0; background: #5E768D; font-family: 宋体, sans-serif; font-size: 16px; color: #f2f2f2; text-shadow: 0px -1px 0px #334f71; } textarea { color: #a1b2c3; text-shadow: 0px -1px 0px #38506b; } input:focus, textarea:focus { background: #728eaa; } p { margin-left: 140px; } input[type=submit] { width: 105px; height: 42px; border: 1px solid #556f8c; cursor: pointer; color: #FFFFFF; } </style> </head> <body> <div id="container"> <h1>用户注册</h1> <form > <fieldset> <label for="name">用户名:</label> <input type="text" id="name" placeholder="填写姓名"> <label for="email">Email:</label> <input type="email" id="email" placeholder="填写电子邮箱地址"> <label for="password">密码:</label> <input type="password" id="password" placeholder="填写密码"> <label for="password">重复密码:</label> <input type="password" id="password" placeholder="重写密码"> <p> <input type="submit" value="重新填写"> <input type="submit" value="注 册"> </p> </fieldset> </form> </div> </body> </html>