移动端布局——flex布局下的居中对齐方式

简介: Flex是Flexible Box的缩写,意为”弹性布局”,用来为盒状模型提供最大的灵活性。任何一个容器都可以指定为Flex布局。

  题目要求

html代码

<!DOCTYPE html><html><head><title>第三题</title><metacharset="utf-8"><!-- <meta name="___(1)___" content="width=device-width, initial-scale=1,user-scalable=no"/> --><metaname="viewport"content="width=device-width, initial-scale=1,user-scalable=no"/><linkrel="stylesheet"type="text/css"href="css/style.css"></head><body><divclass="wrap"><header><divclass="logol"><imgsrc="img/logol.jpg"></div></header><section><divclass="tabTitle"><divclass="title">注册</div><divclass="title cur">登录</div></div><divclass="form"><!-- <form action="" ___(2)___="post"> --><formaction=""method="post"><ul><!-- <li><input type="text" name="username" __(3)___="请输入用户名"></li><li><input type="text" name="username" __(3)___="请输入密码"></li> --><li><inputtype="text"name="username"placeholder="请输入用户名"></li><li><inputtype="text"name="username"placeholder="请输入密码"></li></ul><div><ahref="">忘记密码</a></div><buttontype="submit">登录</button></form></div></section><sectionclass="otherLogin"><h2><a>第三方登录</a></h2><ul><li><imgsrc="img/icon-img1.jpg"></li><li><imgsrc="img/icon-img2.jpg"></li><li><imgsrc="img/icon-img3.jpg"></li></ul></section><footer><p>登录表示你同意该软件<ahref="">用户服务协议</a><ahref="">隐私政策</a></p></footer></div></body></html>


css代码

body,h1,h2,h3,h4,h5,h6,ul,p{
margin: 0;
padding:0;
}
body,html{
/* ____(4)____;设置高度为屏幕的高度 */height: 100%;/*设置高度为屏幕的高度*/}
img{
display: block;
}
ul{
list-style: none;
}
input{
border:none;
}
.wrap{
position: relative;
width: 100%;
max-width: 760px;
margin:0auto;
height: 100%;
}
header,section,footer{
width: 100%;
}
header{
display: flex;
/* _______(5)_____;水平居中对齐 *//* _______(6)_____;垂直居中对齐 */justify-content:center;/*水平居中对齐*/align-items: center;/*垂直居中对齐*/height: 31.8%;
background:url("../img/logol-bottomBj.jpg") no-repeatbottom/100%#7A9AD7;
}
header.logol{
display: flex;
/* _______(5)_____;水平居中对齐 *//* _______(6)_____;垂直居中对齐 */justify-content:center;/*水平居中对齐*/align-items: center;/*垂直居中对齐*/width: 82px;
height: 82px;
/* ____(7)_____: 50%;设置圆角 */border-radius: 50%;/*设置圆角*/border:2pxsolid#B5C5E7;
background-color: #fff;
}
.tabTitle{
margin-top:1em;
display: flex;
text-align: center;
line-height: 40px;
}
.tabTitle.title{
width: 50%;
border-bottom: 1pxsolid#E9E9E9;
}
.tabTitle.title.cur{
border-bottom: 1pxsolid#7C8194;
}
.form{
display: flex;
justify-content:center;/*水平居中对齐*/}
.formform{
width: 80%;
margin-top:1em;
text-align: center;
}
.formulli{
width: 100%;
height: 50px;
line-height: 50px;
display: flex;
align-items: center;;/*垂直居中对齐*/border-bottom:1pxsolid#ABAFB2;
}
.formformdiv{
border-bottom:none;
line-height: 40px;
text-align: right;
}
.formformdiva{
text-decoration: none;
color:#666;
font-size: 12px;
}
.formformbutton{
width: 60%;
height: 50px;
line-height: 50px;
background-color: #7A9AD7;
border-radius: 25px;
border:none;
color: #fff;
}
.otherLoginul{
display: flex;
justify-content:center;/*水平居中对齐*/}
.otherLoginh2{
text-align: center;
font-weight: normal;
font-size: 18px;
line-height: 40px;
margin:1em0;
color: #555;
}
.otherLoginh2:before{
position: relative;
top:23px;
left:50%;
transform: translateX(-50%);
z-index: -1;
content:"";
display: block;
width: 80%;
height:1px;
background-color: #E9E9E9;
}
.otherLoginh2a{
padding:010px;
background-color: #fff;
}
.otherLoginulli{
margin:010px;
}
footerp{
position: absolute;
width: 100%;
height: 30px;
line-height: 30px;
font-size: 12px;
bottom:10px;
text-align: center;
}
footerpa{
text-decoration: none;
color:#506081;
}

image.gif

题目分析

✅meta标签

<meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=no"/>
image.gif

image.gif

✅viewport的conten值

image.gif

✅input标签的placeholder 属性

image.gif

✅flex布局下设置居中对齐模式

水平居中

 justify-content:设置主轴上的子元素排列方式

image.gif

 垂直居中

 align-items:设置交叉轴上的子元素排列方式

image.gif

实现效果

image.gif

目录
相关文章
|
6天前
|
开发者 容器
flex 布局属性在实际项目中的应用场景有哪些?
flex 布局属性在实际项目中的应用场景有哪些?
flex布局属性简介
flex布局属性简介
|
23天前
|
弹性计算 前端开发 容器
【前端web入门第六天】02 flex布局
Flex布局是一种现代CSS布局模式,通过给父元素设置`display: flex`,其子元素可自动挤压或拉伸。它包含弹性容器和弹性盒子,主轴默认为水平方向,侧轴为垂直方向。主轴对齐方式由`justify-content`属性控制,侧轴对齐方式包括`align-items`(针对所有子元素)和`align-self`(针对单个子元素)。修改主轴方向使用`flex-direction`属性,`flex`属性用于控制子元素在主轴上的伸缩比例。此外,`flex-wrap`属性允许子元素换行,而`align-content`属性则定义多行对齐方式。
|
2月前
|
前端开发
FLex布局详解
Flex布局通过`flex-direction`定义主轴方向,包括横向`row`、反向横向`row-reverse`、纵向`column`及反向纵向`column-reverse`。`justify-content`控制主轴上子元素的排列,如起始端`flex-start`、末端`flex-end`、居中`center`、等间距`space-around`或两端对齐`space-between`。在Y轴上设置这些同样有效。`flex-wrap: wrap`使子元素在需要时换行。`align-items: center`实现侧轴(交叉轴)上的居中对齐
52 1
FLex布局详解
|
2月前
|
JavaScript
Vue3弹性布局(Flex)
这是一个基于 Vue 的弹性布局组件库,提供了丰富的参数配置,如宽度、方向、换行等,支持自定义对齐方式和间隙设置。在线预览展示了不同布局效果,包括单选、按钮和滑动输入条等组件的使用示例。
Vue3弹性布局(Flex)
|
2月前
|
前端开发 容器
掌握弹性盒子布局(Flex):打造灵活的网页布局
掌握弹性盒子布局(Flex):打造灵活的网页布局
|
2月前
|
容器
|
2月前
|
前端开发 JavaScript API
如何在 Angular 中使用 Flex 布局
如何在 Angular 中使用 Flex 布局
31 0
|
3月前
|
编解码 前端开发 容器
CSS Flex布局实战案例:构建响应式卡片组件
【7月更文挑战第17天】通过上述步骤,我们成功地使用CSS Flex布局构建了一个响应式的卡片组件。Flexbox不仅简化了布局代码,还让我们能够轻松实现复杂的布局效果,如响应式设计。在实战中,掌握Flexbox将大大提高前端开发的效率和网页布局的质量。希望这个案例能够帮助你更好地理解和应用Flexbox布局。