Align list of images using CSS

大兔子大兔子 提交于 2020-03-05 07:29:06

问题


I would like to align a list of images to 'bottom', how can I achieve this using CSS?

Background: I want a set of photos to be aligned to the bottom, the images are in different sizes.

<div>
  <ul>
    <li> <!-- image 1-->
    <li> <!-- image 2-->
    <li> <!-- image 3-->
  </ul>
</div>

Thanks.


回答1:


The problem with all this absolute positioning is that the li elements will have no height, since the image element is absolute and doesn't push any layout anymore. typically that's a bad solution.

Depending on what you need, this could work:

li {
  display: inline;
  vertical-align: bottom;
}

Live example here: http://mooshell.net/zBCGW/




回答2:


ul{ li-style-type: none;}

li{position:relative; float: left; width:100px; height: 100px; }

li img { display: block; position: absolute; bottom: 0; }

Then

<ul> <li><img /></li>...</ul>



回答3:


The following CSS should do the trick:

ul{ li-style-type: none;}

li img {position:absolute;bottom:0;}

li {float:left;vertical-align:bottom;}



回答4:


Just try try this:

li img{
    position:absolute;
    bottom:0;
}
li{
    position:relative;
}

EDIT: I just read that they are intended to be aligned to the bottom of the li element. I updated the code so the img will be aligned to the bottom of the li element.



来源:https://stackoverflow.com/questions/1525754/align-list-of-images-using-css

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!