html - 行反向 flexbox 在移动设备上不能很好地对齐
问题描述
我更改了现在适用于所有浏览器的“关于我们”部分的格式。但是,我尝试将 flexboxes 安装到移动设备上,但只有偶数行没有正确对齐。奇数行与图像对齐,然后是文本。偶数行仍然与文本并排。我尝试将 flex-direction 更改为 column,但它不起作用。我错过了什么?
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href=https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css>
<link href=https://fonts.googleapis.com/css?family=Montserrat:400,500,700,900|Ubuntu:400,500,700 rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
@media only screen and (min-device-width: 320px) and (max-device-width: 480px){ /*Desktop*/
.container {
padding: 2px;
height: auto;
width: auto;
flex-direction: column;
}
.container:nth-of-type(even) {
flex-direction: column;
padding: 2px;
height: auto;
width: auto;
}
img {
width: 80%;
}
}
@media only screen and (min-device-width: 320px) and (max-device-width: 480px){ /*Desktop*/
h1 {
text-align: center;
width: 100%;
height: 100%;
display: inline-block;
}
h4 {
text-align: left;
width: 100%;
height: 100%;
display: inline-block;
}
}
.container {
display: flex;
align-items: center;
justify-content: center;
padding: 25px;
}
.container:nth-of-type(even) {
flex-direction: row-reverse;
align-items: center;
justify-content: center;
}
img {
max-width: 100%;
}
h1 {
font-family: 'Montserrat', sans-serif;
font-weight: 300;
font-size: 26px;
color: #5e5c5c;
text-align: center;
}
h4 {
font-family: 'Montserrat', sans-serif;
font-weight: 300;
font-size: 18px;
color: #5e5c5c;
line-height: 1.25;
}
li {
margin: 10px;
}
</style>
</head>
<body>
<!-----#Michael----->
<div class="container">
<img src=https://i.postimg.cc/9QsRxd2q/Michael.png alt="Michael"/ width="25%" height="25%">
<ul>
<h1><b>Michael Schlaefer, CEO</b></h1>
<h4><li>Owner of Global Development Contractors, LLC; Plymouth Industries, LLC; Liberty Stone & Aggregates - Clinton Quarry, LLC; Vision Development Group, LLC; and Green Earth Container Service, LLC.</li>
<li>Over 40 years of experience in site work; demolition; remediation; trucking material management, facility operations, complex brownfield and landfill redevelopment projects.</li>
<li>Board member – Tewksbury Environmental Commission</li></h4>
</ul>
</div>
<!-----#Jen----->
<div class='container'>
<img src=https://i.postimg.cc/nhX9YdyJ/Jen.png alt="Jen"/ width="25%" height="25%">
<ul>
<h1><b>Jennifer D. Kraft, COO</b></h1>
<h4><li>In-house counsel for Global Development Contractors, LLC with extensive experience with material management, operations, site development and compliance with environment regulations.</li>
<li>Chair – Tewksbury Board of Health</li>
<li>Member – Professional Women in Construction (PWC)</li></h4>
</ul>
</div>
解决方案
与其从桌面浏览器开始并尝试修改内容以在移动设备上运行,不如从相反的方式开始更容易。
通过W3 Validator运行代码作为检查代码的一种方式也很有帮助。您的页面没有的一些标准内容是:
- 您对 Font Awesome 和 Google Fonts 的 href 缺少引号。
- img 标签中的图像宽度和高度应使用像素指定,而不是百分比(您可以使用样式应用百分比)。
h1
并且h4
标签不应该是ul
标签的孩子。min-device-width
并且max-device-width
已经贬值。最好使用max-width.
- 我将所需的元标记添加到 head 部分的开头。
- 最好在标签上有
lang
属性。html
我将您的 h1 标签和您的列表移动到单独divs
的位置,以便它们保持在一起,并且我将切换点从一排变为垂直,为 768 像素(平板电脑大小)。您可以将值更改为适合您的任何值。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link href="https://fonts.googleapis.com/css?family=Montserrat:400,500,700,900%7CUbuntu:400,500,700" rel="stylesheet">
<style>
body {
margin: 0;
padding: 0;
}
.wrapper {
max-width: 960px;
margin: 2rem auto;
}
.container {
display: flex;
align-items: center;
justify-content: center;
padding: 25px;
}
.container:nth-of-type(even) {
flex-direction: row-reverse;
align-items: center;
justify-content: center;
}
.img-about {
max-width: 33%;
}
h1 {
font-family: 'Montserrat', sans-serif;
font-weight: 300;
font-size: 26px;
color: #5e5c5c;
text-align: center;
}
.experience {
font-family: 'Montserrat', sans-serif;
font-weight: 300;
font-size: 18px;
color: #5e5c5c;
line-height: 1.25;
}
li {
margin: 10px;
}
@media only screen and (max-width:768px) {
/*Desktop*/
.container {
padding: 2px;
height: auto;
width: auto;
flex-direction: column;
}
.container:nth-of-type(even) {
flex-direction: column;
padding: 2px;
height: auto;
width: auto;
}
.img-about {
width: 33%;
}
/*Desktop*/
h1 {
text-align: center;
width: 100%;
height: 100%;
display: inline-block;
}
h4 {
text-align: left;
width: 100%;
height: 100%;
display: inline-block;
}
}
</style>
</head>
<body>
<div class="wrapper">
<!-- #Michael -->
<div class="container">
<img class="img-about" src=https://i.postimg.cc/9QsRxd2q/Michael.png alt="Michael">
<div>
<h1><strong>Michael Schlaefer, CEO</strong></h1>
<ul class="experience">
<li>Owner of Global Development Contractors, LLC; Plymouth Industries, LLC; Liberty Stone & Aggregates - Clinton Quarry, LLC; Vision Development Group, LLC; and Green Earth Container Service, LLC.</li>
<li>Over 40 years of experience in site work; demolition; remediation; trucking material management, facility operations, complex brownfield and landfill redevelopment projects.</li>
<li>Board member – Tewksbury Environmental Commission</li>
</ul>
</div>
</div>
<!--#Jen -->
<div class='container'>
<img class="img-about" src=https://i.postimg.cc/nhX9YdyJ/Jen.png alt="Jen">
<div>
<h1><strong>Jennifer D. Kraft, COO</strong></h1>
<ul class="experience">
<li>In-house counsel for Global Development Contractors, LLC with extensive experience with material management, operations, site development and compliance with environment regulations.</li>
<li>Chair – Tewksbury Board of Health</li>
<li>Member – Professional Women in Construction (PWC)</li>
</ul>
</div>
</div>
</div>
</body>
</html>
推荐阅读
- sql - MAX(),但前提是所有值都不为空
- c++ - 通过串口获取号码
- python - 如何获取从起点到指定节点的路径?
- jquery - 根据范围滑块值检查单选按钮
- javascript - useEffect():行为
- reactjs - 如何在下图中给出的 React JS 中使用 Material UI 添加中心分隔线?
- python - Anaconda 导航器不刷新已使用终端更新的软件包
- python - 传递维基百科 API 的“继续”内容给我一个 badcontinue 错误
- django - 一次创建多个实例 Django Rest 框架
- javascript - React-Native 中的匿名函数