html - 对齐 Div 文本底部

标签 html css vertical-alignment text-alignment

出于某种原因,我无法让此 div 的文本垂直对齐到底部,除了涉及大量代码的解决方案之外,我几乎尝试了所有方法。

.products {
width: 191.25px;
height: 191.25px;
margin-left: 15px;
margin-bottom: 15px;
padding: 15px;
background: black;
color: white;
float: left;
text-align: right;
}

<h2>Header Two</h2>
<div class="products">Content for  class "products" Goes Here</div>
<div class="products">Content for  class "products" Goes Here</div>
<div class="products">Content for  class "products" Goes Here</div>
<div class="products">Content for  class "products" Goes Here</div>

如果有人可以帮助我修复我的代码,以便将 div 的文本垂直对齐到底部。

编辑: 我尝试了以下方法:

添加到 .product

display: table-cell;
vertical-align: bottom;

最佳答案

将内容包装在绝对定位的 span 标签中。然后将 div 设置为 relative 位置。然后,您可以使用 spanbottom 属性来调整其在 div 中的高度。

HTML

<h2>Header Two</h2>
<div class="products"><span>Content for  class "products" Goes Here</span></div>
<div class="products"><span>Content for  class "products" Goes Here</span></div>
<div class="products"><span>Content for  class "products" Goes Here</span></div>
<div class="products"><span>Content for  class "products" Goes Here</span></div>

CSS

.products {
width: 191.25px;
height: 191.25px;
margin-left: 15px;
margin-bottom: 15px;
padding: 15px;
background: black;
color: white;
float: left;
text-align: right;
position:relative; /** Added **/
}

/** New Style **/
.products span{
    position: absolute;
    bottom: 0px;
    left: 0px;
    padding: 15px;    
}

工作示例 http://jsfiddle.net/wD4yJ/

关于html - 对齐 Div 文本底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17846845/

相关文章:

javascript - 如何在弹出窗口中打开新标签页?

javascript - 带圆 Angular 的 Canvas clearRect

css - 在方向更改时禁用 css 动画

CSS:制作标签式菜单。需要的想法

css - 使用在 webkit 中工作的 css3 转换无限滚动但不在 gecko 中工作

垂直对齐忽略 CSS3 最小高度属性 : middle

php - Laravel:多个图像上的图像验证不起作用

html - 如何去除 Blogger 上图片的边框?

css - <p> 垂直对齐到 <div>

css - 带有CSS的div内的图像垂直对齐