html - 在容器底部堆叠 HTML 元素

标签 html css

我有一个 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/

相关文章:

javascript - 使用 Javascript 对象动态构建 HTML 表

jquery - 如果执行 document.html.style.display= '' ,为什么我的网站主页仍为空白?

php - 文本移出标题标签

javascript - Gallery Filters,如何在这个例子中使用?

javascript - 在 slider 中延迟加载图像(纯 JS)

html - 选中 radio 时显示元素

html - CSS垂直 float 技术

CSS Transforms - 为什么简单的旋转会使图像模糊?

css - 不透明度/引导模式的奇怪故障

javascript - 如何在没有提交按钮的情况下向 JavaScript 提交表单?