实例代码:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<style>
.div-box{
background-color:#f1f1f1;
border-radius:5px;
padding:12px;
box-sizing:border-box;
float:left;
width:100%;
}
.row{
margin:5px;
float:left;
width:100%;
box-sizing:border-box;
}
.div-tab{
float:left;
padding:9px 0px;
box-sizing:border-box;
width:20%;
}
.div-01{
box-sizing:border-box;
float:right;
width:80%;
}
input,select,textarea{
width:100%;
box-sizing:border-box;
border-radius:4px;
padding:10.5px 5px;
font-size:10px;
}
textarea{
height:200px;
resize:vertical;
}
button{
background-color:#4CAF50;
color:white;
border:none;
cursor:pointer; /*定义指针样式*/
float:right;
border-radius:4px;
padding:10px 32px;
}
button:hover{
background-color:green;
}
/* 响应式布局 - 当屏幕的宽度小于 600 像素时,使两列相互堆叠而不是彼此并排。 */
@media screen and (max-width:600px){
.div-tab,.div-01,.div-row,button{
width:100%;
}
}
</style>
</head>
<body>
<h1>响应式表单</h1>
<p>请调整浏览器窗口大小以查看效果,当屏幕的宽度小于600像素时,使用两例相互堆叠而不是彼此并排。</p>
<div class="div-box">
<form accept="" target="get">
<div class="row">
<div class="div-tab">
<table>First Name</table>
</div>
<div class="div-01">
<input type="text" name="fst" placeholder="You name.."></input>
</div>
</div>
<div class="row">
<div class="div-tab">
<table>Last Name</table>
</div>
<div class="div-01">
<input type="text" name="lst" placeholder="You last name.."></input>
</div>
</div>
<div class="row">
<div class="div-tab">
<table for="country">Country</table>
</div>
<div class="div-01">
<select id="country" name="country">
<option value="au">Australia </option>
<option value="ca">Canada</option>
<option value="usa">USA</option>
</select>
</div>
</div>
<div class="row">
<div class="div-tab">
<table for="subject">Subject</table>
</div>
<div class="div-01">
<textarea id="subject" name="subject" placeholder="Write something.."></textarea>
</div>
</div>
<div class="row">
<button type="submit" value="submit">提交</button>
</div>
</form>
</div>
</body>
</html>
运行效果:
评论