html - 图片居中,高度或宽度=原图的100%,图片溢出Responsive Divs

标签 html css image overflow centering

我需要用不同的 Div 制作一个页面来制作行和列。第一行有三个 div(宽度 = 33% 和高度 = 25%)。我想居中(垂直和水平)图像而不重新缩放它们(我正在使用 overflow:hidden 来裁剪图像的其余部分)。 我如何将它们居中? 这就是我正在写的:

CSS

div.hiddenrow1 {
width: 33%;
height: 25%;
overflow:hidden;
display:inline-block;
text-align: center;
}

HTML

<!--Row 1-->
<!--Air 1-->
<div class="hiddenrow1"><img src="Gifs/gifs pom twix/air_skate.gif" class="img" /></div>

<!--Air 2-->
<div class="hiddenrow1"><img src="Gifs/gifs pom twix/air_sea.gif" class="img" /></div>

<!--Air 3-->
<div class="hiddenrow1"><img src="Gifs/gifs pom twix/air_diving.gif" class="img" /></div>

此外, 对于第二行,是否可以将 div 定位为列?这是我正在设计的最终结构的图像。 structure

PS:我不知道如何使用表格,我不确定它们是否适合这个,但我对所有方面都持开放态度,如果有人能帮助我,我将不胜感激。

最佳答案

以下是使用表格后如何实现目标。

<table border="1" style="height:25%; width:100%;">
    <tr>
        <td style="width:33.33333333%">1</td>
        <td style="width:33.33333333%">2</td>
        <td style="width:33.33333333%">3</td>
    </tr>
</table>
<table border="1" style="height:50%; width:100%;">
    <tr>
        <td style="width:15%" rowspan="3"></td>
        <td style="width:15%"></td>
        <td rowspan="3"></td>
        <td style="width:15%"></td>
        <td style="width:15%" rowspan="3"></td>
    </tr>
    <tr>
        <td></td>
        <td></td>
    </tr>
    <tr>
        <td></td>
        <td></td>
    </tr>
</table>
<table border="1" style="height:25%; width:100%;">
    <tr>
        <td style="width:20%"></td>
        <td style="width:20%"></td>
        <td style="width:20%"></td>
        <td style="width:20%"></td>
        <td style="width:20%"></td>
    </tr>
</table>

使用 css 将图像添加到样式表中的每个 td,像这样将它们居中:

td
{
    background-position: center;
    background-image: url(http://wac.450f.edgecastcdn.net/80450F/arcadesushi.com/files/2014/04/Goat-Simulator-Coffee-Stain-Studios.jpg);
}

关于html - 图片居中,高度或宽度=原图的100%,图片溢出Responsive Divs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23066928/

相关文章:

javascript - 用 javascript 替换损坏的 Twitter 图片?

javascript - 如何使用 JQuery 刷新 DIV 的内容?

html - 两个可调整大小的 div ,改变一个会改变另一个

jquery - 通过sidemenu切换div

c# - 在 c# 中加载 1000 张图像而不会出现内存不足异常

jQuery 在 img 之后追加或appendTo

css - 居中一个固定的div,div与图像大小相同

html - CSS:父元素的 margin-top 不影响子元素的 margin-top

css - 页面在 iPad View 中看起来不同 - CSS 问题

javascript - 我需要使用 Twitter Bootstrap 图标在数据表中使用切换选项