简体   繁体   English

CSS-多行包装

[英]CSS - Multi Line Wrapping

If you can help i just want to have some guidance with regards to the following problem. 如果您可以提供帮助,我只是想就以下问题提供一些指导。 在此处输入图片说明

Basically if I have too much text in the description of the image, it pushes the image up. 基本上,如果我在图像说明中有太多文字,则会将图像推高。 What would be the most attractive way of dealing with such an issue? 处理此类问题的最有吸引力的方法是什么?

Thanks. 谢谢。

I created a basic fiddle - re-size the window to get them inline 我创建了一个基本的小提琴-调整窗口大小以使其内联

JSFiddle 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;
}

For future peoples, I decided that a flex solution would really help me here. 对于未来的人们,我认为弹性解决方案确实可以为我带来帮助。

I created the following css code: 我创建了以下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%;
}

The HTML is very self explanatory. HTML非常自我解释。 The wrapper contains all the elements, and then I have divs for the mages and their descriptions. 包装器包含所有元素,然后为法师及其描述提供了divs。 By doing this not only are they responsive but they are aligned in the centre and the text is wrapped nicely. 通过这样做,它们不仅响应迅速,而且它们居中对齐,并且文本包装得很好。

You can use flex for same approach Update below css part 您可以将flex用于相同的方法在css部分下更新

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> 

I would do something like this: 我会做这样的事情:

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

This would make all boxes equal. 这将使所有盒子相等。

You can add vertical-align: top; 您可以添加vertical-align: top; to your .responsive div, so all div will align from top.. check below snippet 到您的.responsive ,因此所有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> 

Depending on your notion on a what an attractive solution means and since it hasn't been proposed already. 根据您的想法,有吸引力的解决方案意味着什么,并且由于尚未提出该解决方案。 You could use text-overflow ellipsis. 您可以使用文本溢出省略号。

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

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

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