肖像的景观使1行4张图像转到4行1张图像
我正在使用Flex,想在手机上的一行中放置4个图像。 在肖像中,它将图像加载在另一个下方。这些图像不大(我什至可以使它们很小!),即使在肖像中,它们也应该在屏幕上轻松适应。但是,当我去风景时,它们会根据需要加载一行。
这就是我目前所拥有的:
<div class="flex-container">
<div><img class="item" src="/images/personnel/person1.jpg" alt="pic1" style="width:auto;height:70px;"></div>
<div><img class="item" src="/images/personnel/person2.jpg" alt="pic2" style="width:auto;height:70px;"></div>
<div><img class="item" src="/images/personnel/person3.jpg" alt="pic3" style="width:auto;height:70px;"></div>
<div><img class="item" src="/images/personnel/person4.jpg" alt="pic4" style="width:auto;height:70px;"></div>
</div>
在我的CSS文件中:
.flex-container {
display: flex;
background-color: rgb(220, 235, 250);
flex-direction: row;
flex-wrap: wrap;
justify-content: space-between;
align-content: center;
padding: 5px;
}
要澄清,我希望它们在肖像和景观中一排。
我在CSS文件中也有此功能,但是我不确定这是否是行为的原因,因为我尝试进行flex方向行,但没有任何区别。
@media (max-width: 800px) {
.flex-container {
flex-direction: column;
}
}
I am using Flex, wanting to position 4 images across one row on my phone.
When in portrait, it loads the images one below the other. The images aren't big (I can even make them tiny!), and even in portrait they should easily fit across the screen. However when I go to landscape, then they load in one row as required.
This is what I have currently:
<div class="flex-container">
<div><img class="item" src="/images/personnel/person1.jpg" alt="pic1" style="width:auto;height:70px;"></div>
<div><img class="item" src="/images/personnel/person2.jpg" alt="pic2" style="width:auto;height:70px;"></div>
<div><img class="item" src="/images/personnel/person3.jpg" alt="pic3" style="width:auto;height:70px;"></div>
<div><img class="item" src="/images/personnel/person4.jpg" alt="pic4" style="width:auto;height:70px;"></div>
</div>
and in my CSS file:
.flex-container {
display: flex;
background-color: rgb(220, 235, 250);
flex-direction: row;
flex-wrap: wrap;
justify-content: space-between;
align-content: center;
padding: 5px;
}
To clarify, I want them in one row in portrait AND landscape.
I also have this in my CSS file, but I'm not sure if this is the reason for the behaviour because I have tried making flex-direction row, and it makes no difference.
@media (max-width: 800px) {
.flex-container {
flex-direction: column;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个如何为您服务
How does this work for you
感谢您的建议。因此,我所做的是除了@Media部分之外,我没有更改任何内容,我将其做到了@Media(Max-Width:320px),这似乎有效!我仍然在绊倒自己的出路,所以我敢肯定,我的做法是错误的,但是我的目标是进行一些Udemy课程,然后再回来改进。
Thanks for the recommendation. So what I did is not change anything except the @media section, I made it @media (max-width: 320px) and that seemed to work! I'm still stumbling my way around, so I'm sure there is loads wrong with how I did it, but my goal is to do a little Udemy course and then come back and improve it.