如何解决行反向 flexboxes 在移动设备上没有很好地对齐
我更改了现在适用于所有浏览器的关于我们部分的格式。但是,我尝试将 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,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"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"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
是 depreciated。最好使用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,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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。