在容器底部堆叠HTML元素

Dan*_*nny 5 html css

我有一个div(具有固定宽度)有2个图像元素作为孩子.

每个图像的宽度与div相同,因此图像不在同一行上(参见屏幕截图).
这很棒,但我希望图像以相同的方式显示(一个在另一个上面),但在div的底部.

我能够在某些浏览器中使用以下方法实现此类行为:

-webkit-transform: rotate(180deg); -moz-transform: rotate(180deg);
Run Code Online (Sandbox Code Playgroud)

在div css上.

有没有更好的方法来实现这一目标?

这是我用于示例的代码:

<html>
<head>
<style type="text/css">
.container {background:url(http://img01.imagefra.me/img/img01/1/11/10/f_dwr8biwm_3ed594d.png) no-repeat;height:116px;
width:33px}
</style>
</head>
<body>
<div class="container">
    <img src="http://img01.imagefra.me/img/img01/1/11/10/f_ei8p1qf6om_0e5c35c.png" width="33px">
    <img src="http://img01.imagefra.me/img/img01/1/11/10/f_ei8p1qf6om_0e5c35c.png" width="33px">
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

Jos*_*ola 2

制作容器position:relative;并将图像设置为position:absolute; bottom:0;

但是,这不会堆叠图像。它们会相互重叠。如果需要堆叠它们,最简单的(动态)方法是将图像用另一个容器(如 )包装,然后在div上设置样式。例如...

标记:

<div class="container">
  <div class="innerContainer">
    <img src="http://img01.imagefra.me/img/img01/1/11/10/f_ei8p1qf6om_0e5c35c.png" width="33px" /> 
    <img src="http://img01.imagefra.me/img/img01/1/11/10/f_ei8p1qf6om_0e5c35c.png" width="33px" />
   </div>
</div>
Run Code Online (Sandbox Code Playgroud)

CSS:

.container {
  background:url(http://img01.imagefra.me/img/img01/1/11/10/f_dwr8biwm_3ed594d.png) no-repeat;
  height:116px;
  width:33px;
  position:relative;
}

.container .innerContainer {
  position:absolute;
  bottom:0;
 }
Run Code Online (Sandbox Code Playgroud)