简体   繁体   English

如何按比例缩放此Flexbox瓷砖网格

[英]How to scale proportionally this flexbox tiles grid

I'm preparing the hero element for my website using some tiles with flexbox. 我正在使用带有flexbox的图块为网站准备hero元素。 The hero element has some variants, to the configuration is flexible: nesting the tiles I can obtain the variant I need. hero元素具有一些变体,配置灵活:将图块嵌套可以获取所需的变体。 This is one variant and I cannot understand why when I resize the browser the image on the right, the vertical tile, lose the proportion. 这是一种变体,我无法理解为什么调整浏览器大小时,右侧的图像(垂直图块)会失去比例。 How can I scale the entire grid proportionally? 如何按比例缩放整个网格? And btw why I can remove the blue gap between the elements? 顺便说一句,为什么我可以消除元素之间的蓝色间隙? It's something related to the height of the righe tile. 这与刚性瓷砖的高度有关。

Here is the HTML 这是HTML

<div class="cover">
  <div class="tile is-ancestor">
    <div class="tile is-vertical is-2">
      <div class="tile is-child">
        <img src="https://s1.postimg.org/ga0s55bxr/cover1.jpg" />
      </div>
      <div class="tile is-child">
        <img src="https://s8.postimg.org/xnsnrs4x1/cover2.jpg" />
      </div>
    </div>
    <div class="tile">
      <img src="https://s1.postimg.org/n35qf5s4v/cover3.jpg" />
    </div>
  </div>
</div>

And here the compiled css 这是编译的CSS

.cover {
  max-width: 1080px;
  background-color: blue;
  margin: 0;
}
@media screen and (min-width: 1351px) {
  .cover {
    max-width: 1350px;
    margin: 0 -135px;
  }
}
.cover .tile {
  align-items: stretch;
  display: block;
  flex-basis: 0;
  flex-grow: 1;
  flex-shrink: 1;
  min-height: min-content;
}
.cover .tile.is-child {
  margin: 0 !important;
}
.cover .tile.is-vertical {
  flex-direction: column;
}
@media screen and (min-width: 769px) {
  .cover .tile:not(.is-child) {
    display: flex;
  }
  .cover .tile.is-1 {
    flex: none;
    width: 33.33333%;
  }
  .cover .tile.is-2 {
    flex: none;
    width: 66.66667%;
  }
  .cover .tile.is-3 {
    flex: none;
    width: 100%;
  }
}

I create also a codepen 我也创建了一个Codepen

THis is how i would make it all happen.. 这就是我如何做到这一切的方法..

You simply have to define the widths of the IMG and make sure to change the flex direction. 您只需要定义IMG的宽度并确保更改弯曲方向即可。

Everything can be flexboxed.. 一切都可以灵活装箱..

In your case it is the img so you need to flex one above from the img 在您的情况下,它是img,因此您需要从img上方弯曲一个

    .container {
    display:flex;

    }

    .container_left {display: flex;
                        flex: 1;
                        flex-direction:column}

    .left {
        flex:2;
        display: flex;
        align-items: stretch;
            }

.left img {max-width: 100%}
.right img {max-width: 100%}

    .right {
        flex:1;
    }

@media (max-width:768px) {
    .container{
        flex-direction: column


    }
}

The html i used.. You can apply it to your code.. 我使用的html。您可以将其应用于代码。

    <div class="container">

    <div class="container_left">
            <div class="left"><img src="https://s1.postimg.org/ga0s55bxr/cover1.jpg" /></div>
            <div class="left"> <img src="https://s8.postimg.org/xnsnrs4x1/cover2.jpg" /></div>
        </div>

        <div class="right"> <img src="https://s1.postimg.org/n35qf5s4v/cover3.jpg" /></div>



    </div>

Here it is on codepen for you 这是在codepen上为您服务

https://codepen.io/maffas/pen/zzxMxO https://codepen.io/maffas/pen/zzxMxO

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM