CSS - 多线包装

时间:2017-05-25 08:52:32

标签: html css flexbox alignment

如果您能提供帮助,我只想就以下问题提供一些指导。enter image description here

基本上,如果我在图像描述中有太多文字,它会将图像向上推。处理这样一个问题最有吸引力的方法是什么?

感谢。

我创建了一个基本的小提琴 - 重新调整窗口大小以使其内联

JSFiddle

div.gallery {
  border: 1px solid #ccc;
}

div.gallery:hover {
    border: 1px solid #777;
}

div.gallery img {
    width: 30%;
    height: auto;
}

div.desc {
    padding: 15px;
    text-align: center;
}

* {
    box-sizing: border-box;
}

.responsive {
    padding: 0 6px;
    display: inline-block;
    width: 15.99999%;
}

@media only screen and (max-width: 700px){
    .responsive {
        width: 49.99999%;
        margin: 6px 0;
    }
}

@media only screen and (max-width: 500px){
    .responsive {
        width: 100%;
    }
}

.clearfix:after {
    content: "";
    display: table;
    clear: both;
}

5 个答案:

答案 0 :(得分:1)

对于未来的人们,我认为灵活的解决方案对我来说真的很有帮助。

我创建了以下css代码:

.file-wrapper {
    flex-direction: row;
    flex-flow: row wrap;
    justify-content: center;
    display: flex;
}
.file-image {
    padding: 30px;
}

.file-box {
    text-align: center;
    padding: 1em;
    flex-basis: 10em;
    margin: 1em;
}

.fileTextWrapper {
    display: table;
    width: 100%;
    height: 3em;
}
.file-text {
    display: table-cell;
    vertical-align: middle;
    text-align: center;
    width: 100%;
}

HTML非常自我解释。包装器包含所有元素,然后我有法师及其描述的div。通过这样做不仅它们响应,而且它们在中心对齐,文本很好地包装。

答案 1 :(得分:0)

您可以在{css part

下使用flex进行相同的方法更新

Update code

div.gallery {
    border: 1px solid #ccc;
    display:flex;
    justify-content:center;
    flex-flow:column nowrap;
    align-items:center;
    padding:10px;
} 

    div.gallery img {
    /* width: 30%; */
    height: auto;
}

div.gallery {
    border: 1px solid #ccc;
    display:flex;
    justify-content:center;
    flex-flow:column nowrap;
    align-items:center;
    padding:10px;
}
div.gallery:hover {
    border: 1px solid #777;
}

div.gallery img {
   /* width: 30%; */
    height: auto;
}

div.desc {
    padding: 15px;
    text-align: center;
}

* {
    box-sizing: border-box;
}

.responsive {
    padding: 0 6px;
    display: inline-block;
    width: 15.99999%;
}

@media only screen and (max-width: 700px){
    .responsive {
        width: 49.99999%;
        margin: 6px 0;
    }
}

@media only screen and (max-width: 500px){
    .responsive {
        width: 100%;
    }
}

.clearfix:after {
    content: "";
    display: table;
    clear: both;
}
          
          
          <div class="responsive">
                <div class="gallery">
                        <img src="{{ asset('/img/zip.svg')}}"/>
                    <div class="desc">Description</div>
                </div>
        </div>
        
                 <div class="responsive">
                <div class="gallery">
                        <img src="{{ asset('/img/zip.svg')}}"/>
                    <div class="desc">Description Description</div>
                </div>
        </div>
        
                 <div class="responsive">
                <div class="gallery">
                        <img src="{{ asset('/img/zip.svg')}}"/>
                    <div class="desc">Description Description Description Description Description Description</div>
                </div>
        </div>
        
        

答案 2 :(得分:0)

我会做这样的事情:

div.gallery {
  border: 1px solid #ccc;
  min-height: 200px;
}

这会使所有盒子都相等。

答案 3 :(得分:0)

您可以将vertical-align: top;添加到.responsive div中,这样所有div都会从顶部对齐.. 检查下面的代码段

div.gallery {
    border: 1px solid #ccc;
}

div.gallery:hover {
    border: 1px solid #777;
}

div.gallery img {
    width: 30%;
    height: auto;
}

div.desc {
    padding: 15px;
    text-align: center;
}

* {
    box-sizing: border-box;
}

.responsive {
    padding: 0 6px;
    display: inline-block;
    width: 15.99999%;
    vertical-align: top;
}

@media only screen and (max-width: 700px){
    .responsive {
        width: 49.99999%;
        margin: 6px 0;
    }
}

@media only screen and (max-width: 500px){
    .responsive {
        width: 100%;
    }
}

.clearfix:after {
    content: "";
    display: table;
    clear: both;
}
          
          
<div class="responsive">
    <div class="gallery">
        <img src="{{ asset('/img/zip.svg')}}" />
        <div class="desc">Description</div>
    </div>
</div>

<div class="responsive">
    <div class="gallery">
        <img src="{{ asset('/img/zip.svg')}}" />
        <div class="desc">Description Description</div>
    </div>
</div>

<div class="responsive">
    <div class="gallery">
        <img src="{{ asset('/img/zip.svg')}}" />
        <div class="desc">Description Description Description Description Description Description</div>
    </div>
</div>
        
        

答案 4 :(得分:0)

取决于您对某个有吸引力的解决方案意味着什么的概念,因为它尚未提出。您可以使用文本溢出省略号。

div.desc {
    padding: 15px;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
}