锦方的个人网页

css 表单

发布 · 约 181 字 · 预计 1 分钟

介绍表单输入框的边框、内边距、焦点状态和过渡效果。

归档记录:本文最后更新于 2017 年,文中涉及的软件版本、配置或命令可能已随环境演进发生变化。

系列连载:CSS 笔记系列(第 3 / 8 篇)
  1. 1. css 单词
  2. 2. css 导航栏
  3. 3. css 表单(当前)
  4. 4. css 下拉
  5. 5. css 提示
  6. 6. css 图片
  7. 7. css RWD
  8. 8. css 扩散列表

<html> <head> <style> input[type=text]{ width:50%; padding:12px 20px; margin:8px 0; box-sizing:border-box; border:3px solid #ccc; -webkit-transition:0.5s; outline:none; border-radius:5px; } input[type=text]:focus{ border:3px solid red; } input[type=password]{ width:50%; padding:12px 20px; margin:8px 0; box-sizing:border-box; border:3px solid #ccc; -webkit-transition:0.5s; outline:none; } input[type=password]:focus{ border:3px solid red; background-color:#000; } select{ width:50%; padding:16px 20px; margin:none; border-radius:4px; background-color:#f1f1f1; } input[type=reset],input[type=submit]{ background-color: #4caf50; border:none; color:white; padding:16px 50px; text-decoration:none; margin:6px 2px; cursor:pointer; margin-left:40px; } </style> </head> <body> <form> <label for="fname"> 姓名:</label> <input type="text" id="fname" name="fname" value="pppp"></input></br> <label for="fname">密码:</label> <input type="password" id="lname" name="lname"maxlength="1"></input></br> <label for="fname">地址:</label> <select id="country"name="country"> <option value="aa">11</option> <option value"bb">22</option> </select></br> <input type="reset" value="重填"> <input type="submit" value="提交"> </form> </body> </html>

代码: #

<html>
<head>
<style>
input[type=text]{
    width:50%;
    padding:12px 20px;
    margin:8px 0;
    box-sizing:border-box;
    border:3px solid #ccc;
    -webkit-transition:0.5s;
    outline:none;
    border-radius:5px;
}
input[type=text]:focus{
    border:3px solid red;
}
input[type=password]{
    width:50%;
    padding:12px 20px;
    margin:8px 0;
    box-sizing:border-box;
    border:3px solid #ccc;
    -webkit-transition:0.5s;
    outline:none;
}
input[type=password]:focus{
    border:3px solid red;
    background-color:#000;
}
select{
    width:50%;
    padding:16px 20px;
    margin:none;
    border-radius:4px;
    background-color:#f1f1f1;
}
input[type=reset],input[type=submit]{
    background-color: #4caf50;
    border:none;
    color:white;
    padding:16px 50px;
    text-decoration:none;
    margin:6px 2px;
    cursor:pointer;
    margin-left:40px;
}
</style>
</head>
<body>
<form>
<label for="fname"> 姓名:</label>
<input type="text" id="fname" name="fname" value="pppp"></input></br>
<label for="fname">密码:</label>
<input type="password" id="lname" name="lname"maxlength="1"></input></br>
<label for="fname">地址:</label>
<select id="country"name="country">
    <option value="aa">11</option>
    <option value"bb">22</option>
</select></br>
<input type="reset" value="重填">
<input type="submit" value="提交">
</form>
</body>
</html>

✉ 对本文有补充或勘误?欢迎就本文写信交流。