css3 flex弹性布局登录页面
大致思路:
1、利用弹性布局的
/* 将body标签转换为弹性容器 */
display: flex;
/* 主轴方向设置为垂直交叉轴 */
flex-direction: column;
/* 内容不换行 */
flex-wrap: nowrap;
/* 弹性元素水平方向居中显示 */
justify-content: center;
/* 设置弹性容器中弹性元素居中显示 */
align-items:center;
使得元素有规律排列,形成登录页面
2、添加一下hover属性
<div class="container">
<h3>管理员登录</h3>
<form>
<div><label for="">用户名:</label><input type="text" name="" id=""></div>
<div><label for="">密 码:</label><input type="password" name="" id=""></div>
<div><button>登录</button></div>
</form>
</div>
css
* {
margin: 0;
padding: 0;
}
body,
html {
width: 100%;
height: 100%;
}
body {
color: #444;
font-size: 14px;
font-family: '微软雅黑';
font-weight: lighter;
background-image: linear-gradient(to top, lightcyan, white, lightcyan);
/* 弹性布局 */
/* 将body标签转换为弹性容器 */
display: flex;
/* 主轴方向设置为垂直交叉轴 */
flex-direction: column;
/* 内容不换行 */
flex-wrap: nowrap;
/* 弹性元素水平方向居中显示 */
justify-content: center;
/* 设置弹性容器中弹性元素居中显示 */
align-items: center;
/* 将body标签垂直划分一百份 */
/* width: 100vh; */
}
h3 {
/* 不加粗 */
font-weight: normal;
text-align: center;
margin-bottom: 15px;
font-size: 20px;
}
.container {
width: 300px;
padding: 20px;
box-sizing: border-box;
position: relative;
box-shadow: 0 0 8px gray;
border-radius: 8%;
}
.container form {
display: flex;
flex-flow: column nowrap;
background-image: linear-gradient(to right bottom, lightblue, white);
border-radius: 8px;
padding: 15px;
transition: 0.5s ease-in-out;
}
.container form:hover {
box-shadow: 0 0 5px gray;
}
.container>form>div {
display: flex;
flex-flow: row nowrap;
margin: 10px 0;
}
.container input {
flex: 1;
margin-left: 10px;
border: 1px solid gray;
outline: none;
padding-left: 3px;
height: 23px;
line-height: 23px;
}
.container input:hover {
outline: 0.5px solid gray;
}
.container button {
flex: 1;
height: 30px;
line-height: 28px;
background-color: skyblue;
color: #fff;
text-align: center;
border: none;
outline: none;
cursor: pointer;
letter-spacing: 15px;
border-radius: 8%;
}
.container button:hover {
background-color: steelblue;
}
代码演示:
评论
匿名评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果