Row-reverse flexboxes 在移动设备上不能很好地对齐
Row-reverse flexboxes not aligning well on mobile
我更改了现在适用于所有浏览器的“关于我们”部分的格式。但是,我尝试将 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 字体的 href 缺少引号。
- img 标签中的图像宽度和高度应使用像素而不是百分比指定(您可以使用样式应用百分比)。
h1
和 h4
标签不应是 ul
标签的子标签。
min-device-width
和 max-device-width
已经 depreciated。最好用max-width.
- 我在头部部分的开头添加了所需的元标记。
- 在你的
html
标签上有 lang
属性是很好的。
我将你的 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>
我更改了现在适用于所有浏览器的“关于我们”部分的格式。但是,我尝试将 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 字体的 href 缺少引号。
- img 标签中的图像宽度和高度应使用像素而不是百分比指定(您可以使用样式应用百分比)。
h1
和h4
标签不应是ul
标签的子标签。min-device-width
和max-device-width
已经 depreciated。最好用max-width.
- 我在头部部分的开头添加了所需的元标记。
- 在你的
html
标签上有lang
属性是很好的。
我将你的 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>