肖像的景观使1行4张图像转到4行1张图像

发布于 2025-02-05 08:55:02 字数 1216 浏览 1 评论 0原文

我正在使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月竹挽风 2025-02-12 08:55:02

这个如何为您服务

.flex-container {
overflow-x: scroll;
overflow-y: hidden;    
display: -webkit-box;   /* OLD - iOS 6-, Safari 3.1-6, BB7 */
display: -ms-flexbox;  /* TWEENER - IE 10 */
display: -webkit-flexbox; /* NEW - Safari 6.1+. iOS 7.1+, BB10 */
display: flex;
} 

.item {
display: flex;
flex-direction: column;
padding: 0px;
margin: 5px;
}
   <div class="flex-container">
    <div><img class="item" src="https://via.placeholder.com/110x70" alt="pic1" style="width:auto;height:70px;"></div>
    <div><img class="item" src="https://via.placeholder.com/70x70" alt="pic2" style="width:auto;height:70px;"></div>
    <div><img class="item" src="https://via.placeholder.com/150x70" alt="pic3" style="width:auto;height:70px;"></div>
    <div><img class="item" src="https://via.placeholder.com/110x70" alt="pic4" style="width:auto;height:70px;"></div>
    <div><img class="item" src="https://via.placeholder.com/110x70" alt="pic5" style="width:auto;height:70px;"></div>
    <div><img class="item" src="https://via.placeholder.com/70x70" alt="pic6" style="width:auto;height:70px;"></div>
    <div><img class="item" src="https://via.placeholder.com/150x70" alt="pic7" style="width:auto;height:70px;"></div>
    <div><img class="item" src="https://via.placeholder.com/110x70" alt="pic8" style="width:auto;height:70px;"></div>
    </div>

How does this work for you

.flex-container {
overflow-x: scroll;
overflow-y: hidden;    
display: -webkit-box;   /* OLD - iOS 6-, Safari 3.1-6, BB7 */
display: -ms-flexbox;  /* TWEENER - IE 10 */
display: -webkit-flexbox; /* NEW - Safari 6.1+. iOS 7.1+, BB10 */
display: flex;
} 

.item {
display: flex;
flex-direction: column;
padding: 0px;
margin: 5px;
}
   <div class="flex-container">
    <div><img class="item" src="https://via.placeholder.com/110x70" alt="pic1" style="width:auto;height:70px;"></div>
    <div><img class="item" src="https://via.placeholder.com/70x70" alt="pic2" style="width:auto;height:70px;"></div>
    <div><img class="item" src="https://via.placeholder.com/150x70" alt="pic3" style="width:auto;height:70px;"></div>
    <div><img class="item" src="https://via.placeholder.com/110x70" alt="pic4" style="width:auto;height:70px;"></div>
    <div><img class="item" src="https://via.placeholder.com/110x70" alt="pic5" style="width:auto;height:70px;"></div>
    <div><img class="item" src="https://via.placeholder.com/70x70" alt="pic6" style="width:auto;height:70px;"></div>
    <div><img class="item" src="https://via.placeholder.com/150x70" alt="pic7" style="width:auto;height:70px;"></div>
    <div><img class="item" src="https://via.placeholder.com/110x70" alt="pic8" style="width:auto;height:70px;"></div>
    </div>

徒留西风 2025-02-12 08:55:02

感谢您的建议。因此,我所做的是除了@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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文