我有一个 div(具有固定宽度),它有 2 个图像元素作为子元素。
每张图片与 div 的宽度相同,因此图片不在同一行 (see screenshot)。
这很好,但我希望图像以相同的方式显示(一个在另一个之上)但在 div 的底部。
我能够在某些浏览器中实现这样的行为:
-webkit-transform: rotate(180deg); -moz-transform: rotate(180deg);
在 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>
最佳答案
制作容器 position:relative;
并将图像设置为 position:absolute;底部: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>
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;
}
关于html - 在容器底部堆叠 HTML 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1710645/