css - 如何将此图像粘贴到 div 的底部

标签 css

我希望这个图像(较小的 - 灰色的)在调整窗口大小时留在其 div(草 map 像)的底部。我已经尝试在属性上使用自动值,但我猜想它与定位有关,无法弄清楚它到底是什么……有什么想法吗?非常感谢!

代码笔:http://codepen.io/anon/pen/zoEYgP

.images {
  background: url("http://kingofwallpapers.com/meadow/meadow-008.jpg");
  background-size: cover;
  height: 780px;
  /*position: relative;*/

}
.smaller {
  text-align: center;
}
.smaller img {
  position: relative;
  bottom: -280px;
}
@media screen and(max-width: 768px) {
  .images {
    height: auto;
    /*position: relative;*/
  }
  .smaller img {
    width: 80%;
    /*height: auto;*/
    /*margin-bottom: 0px;*/
  }
}
<section class="images">
  <div class="smaller">
    <img src="https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97500&w=400&h=500" alt="">
  </div>
</section>

最佳答案

参见 codepen ,我做了 smaller .image position: absolute 并调整了一些 css

.images {
  background: url("http://kingofwallpapers.com/meadow/meadow-008.jpg");
  background-size: cover;
  height: 768px;
  /*height: 100vh;*/
  min-height: 500px;
  max-width: 100%;
  position: relative;
}


.smaller img {
    position: absolute;
    bottom: 0;
    left: 0;
    max-width: 50%;
    margin: 0 auto;
    right: 0;
}

@media screen and(max-width: 768px) {
  .images {
    height: 100vh;
    //position: relative;
  }
  .smaller img {
    //width: 80%;
    //height: auto;
    //margin-bottom: 0px;
  }
}
<section class="images">
  <div class="smaller">
    <img src="https://placeholdit.imgix.net/~text?txtsize=38&txt=400%C3%97500&w=400&h=500" alt="">
  </div>
</section>

<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Blanditiis nulla laboriosam laborum sapiente sit voluptate voluptatum, velit eius quam minus natus incidunt omnis quidem cupiditate, maxime, ex reprehenderit minima enim!</p>

关于css - 如何将此图像粘贴到 div 的底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40844872/

相关文章:

html - 使 Bootstrap 列显示在一行中

javascript - Chrome "Can not drag"图标干扰了鼠标悬停事件,我该如何防止这种情况发生?

css - 如何在 flex 容器中间隔 flex 元素?

css - 如何在表格行上添加边框半径

css - 如何在 Bootstrap 的下拉列表前面添加图片?

javascript - CSS flex display 与 Chrome 中的相同 flex 元素不同

html - 通过将鼠标悬停在单独的元素上来触发 CSS 动画

javascript - 由于父元素的顶部和位置,子元素点击不起作用

html - CSS div/元素位置问题

javascript - 如果已经预先设置了一个属性,如何防止再次设置该属性?