移动端布局——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

相关文章
|
13天前
|
前端开发 算法 Java
(CSS)使用Flex布局,帮助你快速了解各种基本的Flex布局属性以及帮你让元素快速达到布局中的指定位置!
(CSS)使用Flex布局,帮助你快速了解各种基本的Flex布局属性以及帮你让元素快速达到布局中的指定位置!
54 1
|
13天前
|
前端开发 算法 Java
【CSS】前端三大件之一,如何学好?从基本用法开始吧!(六):全方面分析css的Flex布局,从纵、横两个坐标开始进行居中、两端等元素分布模式;刨析元素间隔、排序模式等
Flex 布局 布局的传统解决方案,基于盒状模型,依赖 display 属性 + position属性 + float属性。它对于那些特殊布局非常不方便,比如,垂直居中就不容易实现。 2009年,W3C 提出了一种新的方案----Flex 布局,可以简便、完整、响应式地实现各种页面布局。目前,它已经得到了所有浏览器的支持,这意味着,现在就能很安全地使用这项功能。 一、Flex 布局是什么? Flex 是 Flexible Box 的缩写,意为"弹性布局",用来为盒状模型提供最大的灵活性。
142 0
|
4月前
|
设计模式 容器
13.HarmonyOS流式卡片列表实现指南:Flex多行布局详解
在现代移动应用开发中,流式卡片列表是一种常见且实用的UI设计模式。它能够自适应屏幕宽度,在有限空间内高效展示多个内容项。本教程将详细讲解如何使用HarmonyOS的ArkUI框架中的Flex组件实现一个灵活的流式卡片列表,重点关注多行布局与对齐策略的应用。
116 2
|
4月前
|
开发者 UED 容器
07.精通HarmonyOS Flex对齐:从基础到高级布局技巧(上)
在HarmonyOS Next的ArkUI框架中,Flex容器提供了强大而灵活的对齐系统,使开发者能够精确控制子元素在容器中的排列方式。掌握这些对齐技术,是构建专业级用户界面的关键。
138 0
|
4月前
|
UED 容器
5.HarmonyOS Next开发宝典:掌握Flex布局的艺术
Flex布局(弹性布局)是HarmonyOS Next中最强大的布局方式之一,它提供了一种更加高效、灵活的方式来对容器中的子元素进行排列、对齐和分配空间。无论是简单的居中显示,还是复杂的自适应界面,Flex布局都能轻松应对。
156 0
|
4月前
|
UED 容器
10.HarmonyOS Next布局进阶:嵌套Flex容器与空间分配策略
在HarmonyOS Next的ArkUI框架中,Flex布局是构建用户界面的核心技术之一。通过嵌套使用Flex容器,我们可以创建复杂而灵活的界面结构,满足各种应用场景的需求。本教程将深入探讨如何在HarmonyOS Next中使用嵌套Flex容器实现复杂布局,以及如何合理分配和控制空间。
124 0
|
7月前
|
开发者 容器
鸿蒙开发:弹性布局Flex
在实际的开发中,需要掌握主轴与交叉轴的关系、换行规则及子元素属性,同时注意性能与兼容性问题,还有一点,Flex组件在渲染时存在二次布局过程,因此在对性能有严格要求的场景下建议使用Column、Row代替。
200 10
鸿蒙开发:弹性布局Flex
|
前端开发 容器
flex布局
【10月更文挑战第7天】
253 87
|
前端开发 UED 容器
使用 Flex 布局实现垂直居中效果
【10月更文挑战第7天】
1203 57
|
11月前
|
前端开发 UED 容器
在 CSS 中使用 Flex 布局实现页面自适应时需要注意什么?
【10月更文挑战第22天】在使用 Flex 布局实现页面自适应时,需要对其基本原理和特性有深入的理解,同时结合具体的布局需求和场景,进行细致的调整和优化。通过合理的设置和注意事项的把握,才能实现理想的自适应效果,提升用户体验。还可以根据实际情况进行更深入的探索和实践,以不断提升 Flex 布局的应用能力。

热门文章

最新文章