简体   繁体   English

包装时,具有display flex属性的css div如何对齐到右侧?

[英]How can my css div with the display flex property be alignd to the right when it's wrapping?

I am trying to make a sort of gallery where all my user uploaded pictures get alignd in a div which holds one more divs which holds the picture. 我正在尝试创建一种图库,在该图库中,我所有用户上传的图片都在一个div中对齐,该div中又保存了一个div,该div中保存了图片。 It will be more clear in the code ;) But the last item (the child div) aligns in the middle but I want the last one to align to the left but I have tried now in hours to get this flex stuff to work and watched several tutorials on how the flex property behaves but no success :/ 代码中会更清楚;)但是最后一项(子div)在中间对齐,但是我希望最后一项在左侧对齐,但是我现在已经尝试了好几个小时才能使这种伸缩功能正常工作并观察关于flex属性的行为的一些教程,但没有成功:/

Here the JSFiddle: 这里是JSFiddle:

https://jsfiddle.net/kra1b6LL/3/ https://jsfiddle.net/kra1b6LL/3/

#sWrapper{
    position:absolute;
    top:10vh;
    height:75vh; /* Android Size */
    height:65vh; /* iPhone  Size */
    width:100%;
    right:0px;
    left:0px;
}
#sWrapperContent{
    background-color:blue;
    position:absolute;
    height:100%;
    width:100%;
    overflow: auto;
    display:flex;
    flex-wrap:wrap;
    justify-content: space-around;
}
#sStyleBox{
    border:1px solid white;
    box-sizing: border-box;
    height:23vh;
    width:18vh;
    display:inline-block;
}

Just remove the justify-content style. 只需删除证明内容样式即可。 Elements that won't fit on the first row, will break to the second, starting on the left side. 不适用于第一行的元素将从左侧开始中断到第二行。 To make the code more fancy i've added some margin to the child boxes. 为了使代码更加精美,我为子框添加了一些边距。

https://jsfiddle.net/hyv4h4fy/ https://jsfiddle.net/hyv4h4fy/

 #sWrapper{ position:absolute; top:10vh; height:75vh; /* Android Size */ height:65vh; /* iPhone Size */ width:100%; right:0px; left:0px; } #sWrapperContent{ background-color:blue; position:absolute; height:100%; width:100%; overflow: auto; display:flex; flex-wrap:wrap; } #sStyleBox{ margin:5px; border:1px solid white; box-sizing: border-box; height:23vh; width:18vh; display:inline-block; } 
 <div id="sWrapper"> <div id="sWrapperBeforeContent"> <div id="sWrapperContent"> <div id="sStyleBox"> <div id="sStyleImg"></div> </div> <div id="sStyleBox"> <div id="sStyleImg"></div> </div> <div id="sStyleBox"> <div id="sStyleImg"></div> </div> <div id="sStyleBox"> <div id="sStyleImg"></div> </div> <div id="sStyleBox"> <div id="sStyleImg"></div> </div> <div id="sStyleBox"> <div id="sStyleImg"></div> </div> <div id="sStyleBox"> <div id="sStyleImg"></div> </div> <div id="sStyleBox"> <div id="sStyleImg"></div> </div> <div id="sStyleBox"> <div id="sStyleImg"></div> </div> <div id="sStyleBox"> <div id="sStyleImg"></div> </div> </div> </div> </div> 

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

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