【问题标题】:HTML images not aligned when they are not the same image当它们不是相同的图像时,HTML 图像未对齐
【发布时间】:2014-05-14 15:47:14
【问题描述】:

我正在制作图像视图,但在对齐图像时遇到了一些问题。当我连续有两个相同的图像时,它将对齐,但是当图像不同时,第二个图像将低于第一个图像。这是截图screenshot。这是我的 html 和 css
html

<div id="wrapper">
        <div id="images">
            <div class="image" onClick="showimage('users/images/username/battlefield4_maars.png','battlefield4_maars.png','3.91MB','png');">
                <img src="users/images/username/battlefield4_maars.png">
                <div class="normaltext">battlefield4_maars.png</div>
            </div>
            <div class="image" onClick="showimage('users/images/username/dark_souls_2.jpg','dark_souls_2.jpg','363KB','jpg');">
                <img src="users/images/username/dark_souls_2.jpg">
                <div class="normaltext">dark_souls_2.jpg</div>
            </div>
            <div class="image" onClick="showimage('users/images/username/thief.jpg','thief.jpg','393KB','jpg');">
                <img src="users/images/username/thief.jpg">
                <div class="normaltext">thief.jpg</div>
            </div>
        </div>
    </div>

css

#images {
    margin-top: 20px;
    display: inline-block;
}
.image {
    height: 200px;
    width: 140px;
    border: 1px solid #cccccc;
    border-radius: 3px;
    background: #fff;
    display: inline-block;
    word-wrap:break-word;
    padding: 10px;
    cursor: pointer;
}
.image img {
    width: 140px;
    height: 140px;
}

有人知道这里有什么问题吗?

【问题讨论】:

  • 当你添加第三张图片,图片下方的文字只有 1 行而不是 2 行时,它会改变吗?
  • 实际上是自动换行造成这样的,因为有两行。我添加了一个 php 函数来缩短文本并添加“...”,现在它可以工作了,感谢您的帮助

标签: html css image


【解决方案1】:

添加这个:

#images {display:block;}
.image {
    vertical-align: top;
}

【讨论】:

  • 不会改变任何东西
  • 将#images设置为display:block;而不是 display:inline-block;并添加垂直对齐:顶部;到 .image
猜你喜欢
  • 2016-11-25
  • 2015-09-14
  • 2015-05-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多