【问题标题】:Responsive row of images and text响应式图像和文本行
【发布时间】:2013-07-23 22:17:49
【问题描述】:

我将五张图片排成一行,每张图片下方都有文字,我正在努力使其具有响应性。问题是所有图像都没有正确按比例缩小。我希望它们都具有相同的宽度和高度。


到目前为止我的代码:

<table>
    <tr>
        <td>
            <img src="http://thumbs.dreamstime.com/thumb160_268/1210514734LWUcju.jpg" />
            <p>testing text</p>
        </td>
        <td>
            <img src="http://thumbs.dreamstime.com/thumb160_268/1210514734LWUcju.jpg" />
            <p>Longerishhh texting text</p>
        </td>
        <td>
            <img src="http://thumbs.dreamstime.com/thumb160_268/1210514734LWUcju.jpg" />
            <p>Text</p>
        </td>
        <td>
            <img src="http://thumbs.dreamstime.com/thumb160_268/1210514734LWUcju.jpg" />
            <p>Quite long text</p>
        </td>
        <td>
            <img src="http://thumbs.dreamstime.com/thumb160_268/1210514734LWUcju.jpg" />
            <p>More testing</p>
        </td>
    </tr>
</table>

CSS:

html{
    width: 100%;
}

table{
    width: 80%;
}

td{
    display: table-cell;
    width: 20%;
    text-align: center;
    overflow: hidden;
    vertical-align: baseline;
}

img{
    width: 100%;    
}

jsfiddle

【问题讨论】:

标签: html css image responsive-design


【解决方案1】:

将以下内容添加到表格 css:

table-layout: fixed;

在你的情况下:

table {
    width: 80%;
    table-layout: fixed;
}

在这里更新了 jsfiddle - http://jsfiddle.net/Y7CrV/7/

【讨论】:

    【解决方案2】:
    html{
        width: 100%;
    }
    
    table{
        width: 80%;
    }
    tr{width:100%;}
    td{
        display: table-cell;
        width: 20%;
        text-align: center;
        overflow: hidden;
        vertical-align: baseline;
    word-break: break-all;
    }
    
    img{
        width: 100%;    
    }
    

    【讨论】:

      【解决方案3】:

      为什么不使用浮动 div?

      div.row {
          width: 80%;
      }
      
      /* clearfix */
      div.row { zoom:1; }
      div.row:before, div.row:after { content:""; display:table; }
      div.row:after { clear:both; }
      
      div.row .column {
          width: 20%;
          float: left;
          text-align: center;
          overflow: hidden;
      }
      

      见:http://jsfiddle.net/Y7CrV/8/

      但是如果你想要更多的灵活性,你可能想看看http://foundation.zurb.com/grid.php

      【讨论】:

        猜你喜欢
        • 2016-01-12
        • 1970-01-01
        • 2017-05-27
        • 1970-01-01
        • 2018-02-07
        • 1970-01-01
        • 1970-01-01
        • 2021-01-01
        • 1970-01-01
        相关资源
        最近更新 更多