css - Bootstrap - 对齐列文本元素

标签 css twitter-bootstrap

我正在努力对齐右侧 Bootstrap 列中的右侧 2 个“h”元素(即 h1 和 h3)。

<div class="col-xs-6">photo</div>
<div class="col-xs-6 text-right">
<h1>Header</h1>
<h3 style="width:100px;">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation</h3>
</div>

问题是固定宽度的 h3 没有右对齐,而 h1 片段是。参见 screen

这里是 fiddle

调试后我发现问题是由于 h1 宽度属性引起的。但我需要它来保持文本折叠。可以通过手动设置左边距来解决,但我相信有更优雅的解决方案。

为什么 width 属性会阻止文本对齐,解决方案是什么?

最佳答案

尝试使用以下 block 。

CSS:

h1, h3{
    display: inline-block;
    padding-right: 20px;
}

关于css - Bootstrap - 对齐列文本元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31893225/

相关文章:

Jquery - (如果 css = A)做 B

html - 中心 x float 量 : left divs horizontally

html - 具有自动宽度的 css 动画按钮

javascript - 如果在 Material io 中选中了复选框,则更改复选框属性

javascript - 大型 Html 代码 - 页面响应时间非常慢

javascript - 如果达到限制,可移动的动态 Bootstrap Tab 菜单 slider

html - Bootstrap 切换菜单在移动 View 中不起作用

html - 为什么 IE 特定样式表被忽略

css - 使图像适合 bootstrap 3 网格的高度

html - 将字形图标垂直居中放置在 div 中的 img 上