css - 在每行 4 个图像的 block 布局中排序 <img> 标签

标签 css html

我有 20 <img> -标签:

<img src="/image/1.jpg"/>
<img src="/image/2.jpg"/>
<img src="/image/3.jpg"/>
<img src="/image/....jpg"/>
<img src="/image/N.jpg"/>

如何在每行 4 张图片的 block 布局中对这些图片进行排序? 仅有效 div , 没有 table !

示例:http://new.music.yahoo.com/videos/charts/

最佳答案

如果图像大小相同,您只需为容器创建一个 DIV 并将所有图像向左浮动并设置适当的 DIV 宽度。假设您创建的每张图片宽度为 100 像素,如下所示:

<div class="container">
    <div class="image-block">
        <img src="img1.jpg">
        <span>Here goes some text</span>
    </div>
    ....
</div>

CSS

div.container {
    width: 400px;
}

div.container .image-block {
    float: left;
    width: 100px;
    /* you may use overflow: hiiden; 
    if the text or image is wider 
    than the box width */
}

div.container .image-block span {
    /* styling the text */
}

关于css - 在每行 4 个图像的 block 布局中排序 <img> 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4152663/

相关文章:

html - Safari Mobile Multi-Line <Select> aka GWT Multi-Line ListBox

html - Google 字体加载说明

css - RDP(远程桌面连接)破坏网站格式

html - 为什么我的 css 代码没有将页面上的元素居中?

html - Chrome/Firefox 边距和填充问题 : how to line these things up?

html - 选项卡模型第 4 个 child 未显示

html - 无法垂直对齐表格单元格中的链接

php - html 表单和 php post 不起作用,信息正在被重写

javascript - 将 CSS、jQuery 和 HTML 全部集成到一个 .html 中

html - 居中表有问题