将产品图像放在盒子底部

时间:2015-03-03 15:57:39

标签: html css image vertical-alignment

CODE

我希望图像在框底部对齐。将有来自后端的产品图像,并且没有固定大小。

HTML

<ul>
  <li><img src="http://img3.wikia.nocookie.net/__cb20120422063108/nickelodeon/images/2/27/Spongebob1.gif" alt="" /></li>
  <li>
    <img src="http://img2.wikia.nocookie.net/__cb20120717231330/hulksmash/images/7/78/Image_placeholder.jpg" alt="" />
  </li>
</ul>

CSS

ul {
  list-style: none;
}
li {
  float: left;
  width: 276px;
  text-align: center;
  border:1px solid #ccc;
  height: 276px;
  margin: 5px
}
img {
  vertical-align: bottom
}

3 个答案:

答案 0 :(得分:1)

这个css做了伎俩

ul {
  list-style: none;
}
li {
  width: 276px;
  text-align: center;
  border:1px solid #ccc;
  height: 276px;
  margin: 5px
  vertical-align: bottom;
  display: table-cell;
  vertical-align: bottom;
}
img {
  vertical-align: bottom
}

答案 1 :(得分:1)

这是一种做法。

li {
position:relative;
}

img {
 position: absolute;
 top: 100%;
 left: 50%;
 transform: translate(-50%, -100%); 
}

答案 2 :(得分:0)

您可以向li添加line-height属性,该属性与li的高度相同,应该可以实现。