html - 将图像垂直对齐到 div 标签的底部

标签 html css

<div class = "column2_SS">
 <img class = "weather_widget" src = "images/weather.png" alt = "Smiley face">
</div>

CSS 代码:

.column2_SS{
background-color: #f2f7fc;
float: right;
height: 171px;
width: 300px;
background-color: black;  /*#444444*/
margin-top: 20px;
margin-right: 100px;
border-radius: 7px;
vertical-align: bottom;}

.weather_widget{
vertical-align: bottom;}

垂直对齐:底部;不起作用。 我需要将天气小部件图像对齐到底部。任何解决方案? 找到附加的图像。 enter image description here

编辑: 我已将 column2_SS 的背景颜色设置为黑色。如果图像底部对齐,则背景颜色不应为黑色。请参阅附图。图像下方有黑色行,这意味着图像未底部对齐。 enter image description here

最佳答案

您可以使用 position: absolute 并使用 top/bottom/left/right 值来定位相对于其父元素的元素。 vertical-align 主要适用于内联元素或表格单元格 ( read more on MDN )。

.column2_SS {
  background-color: #f2f7fc;
  float: right;
  height: 271px;
  width: 300px;
  background-color: black;
  margin-top: 20px;
  margin-right: 100px;
  border-radius: 7px;
  position: relative;
}

.weather_widget {
  position: absolute;
  bottom:0;
}
<div class="column2_SS">
  <img class="weather_widget" src="http://i.stack.imgur.com/iU1rX.png" alt="Smiley face">
</div>

关于html - 将图像垂直对齐到 div 标签的底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35406801/

相关文章:

html - 对齐 div 内容

javascript - 如何使用 Javascript 在网络上随机更改计时器上的 HTML 元素,而不仅仅是在浏览器中?

javascript - 如何将非文字添加到像 jQuery 这样的变量中?

html - R&Knitr html输出: Create collapsing and expanding header

javascript - 如何在博客页面中获取搜索栏以搜索选择性文章?

CSS Font-Face 网址不起作用?

javascript - 寻找 HTML5 视频是否需要加载整个文件?

CSS 循环第 n 个子模式

php - 为什么我不能在 HTML 表格中指定单元格的宽度和高度?

html - 我们可以跨多个 <svg> 元素引用 <defs> 的内容吗?