html - 3x3 网格在特定宽度下表现奇怪

标签 html css css-float

我有一个响应式 3x3 视频缩略图网格,它使用漂亮的照片到灯箱 vimeo 剪辑。它在某些分辨率下效果很好,但是当您调整浏览器窗口的宽度时,它会迅速从 3x3 变为这种废话。
What?

这是有问题的 CSS。

     .thumb
{
float: right;
width: 25%;
height: auto;
margin: 2%;
}
    .maincontent
{
margin:0 auto;
width:90%;
float:right;
}

如果重要的话还有一段 HTML。

        <div class="maincontent">
    <a href="http://vimeo.com/428525" rel="prettyPhoto" title="">
       <img class="thumb" src="http://ftfrmedia.com/images/thumbnails/Overview-thumb.jpg" alt="Company Overview" width="60" />
       </a>

我真的很难过...

最佳答案

我认为这是 .thumbimg 中的 float 问题。

display: inline-block 替换 float 应该可以解决问题:

.thumb {
    height: auto;
    margin: 2em;
    width: 25%;
}

img {
    display: inline-block;
    *display: inline;        /* IE7 hack as it does not */
    *zoom: 1;                /* support display: inline-block */  
    height: 3em;
    margin-left: 0.5em;
    margin-right: 0.5em;
    margin-top: -1.6em;
    width: 3em;
}

更新

正如下面 @DaveHaigh 所指出的,没有必要在 img 元素上使用 display: inline-block,因为它已经接受了高度和宽度属性。

因此,只需删除 float 即可解决此问题。如果您想保持图像从右到左的流动,那么您可以将 direction: rtl 添加到它们的父级:

.maincontent {
    direction: rtl;
}

这样做的缺点是它还会使任何文本从右向左流动,但这在您的网站中似乎不是问题,因为您没有在 .maincontent 中使用任何文本元素。

关于html - 3x3 网格在特定宽度下表现奇怪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10816596/

相关文章:

javascript - Raphael.js : Why is the SVG positioned -0. 5px 向左?

javascript - 使用 Javascript 单击 div 时向标题添加样式

html - 如果我们向上移动,按钮不可点击

jquery - 图像向右浮动时 Superfish 菜单出现溢出问题

css - 如何在 r markdown ioslides 演示文稿中的代码块中启用语法突出显示?

HTML5 问题,背景图像及其上方随附的 float 图像。也不能调整不透明度。

javascript - jQuery 错误 - $(el).css ('float' ) 绝对或固定时 - 不同的浏览器返回不同的结果

javascript - 在用户单击链接之前,如何防止加载我的图像 slider ?

javascript - 将 HTML 字段集用于 PHP 表单数组

html - 如何垂直滚动多个 URL 集?