html - Bootstrap 3 中的水平对齐中心与偏移量

标签 html css twitter-bootstrap

我有一个基于 bootstrap 3 的布局,有两列,如何确保第二列中的文本与页面的中心(水平)对齐?

HTML:

<div class="row spaced">
    <div class="col-sm-2 text-center">
      <img src="Images/picture.png" alt="Image" height="100%" width="100%">
    </div>
    <div class="col-sm-10 text-center horizontal-center">
      <h1 class="text-box text-center horizontal-center">Are you interested?</h1>
      <button type="button" class="btn btn-primary btn-lg outline text-center">Find Out More</button>
    </div>
  </div>

CSS:

.horizontal-center {
    display: inline-block;
    vertical-align: middle;
    text-align: center;
    float: none;
}

JSFiddle

最佳答案

您可以向左拉图像并将其从容器中取出,然后将 div 设置为 12,这样它将使用整个屏幕

<div class="col-sm-2 pull-left">
      <img src="Images/picture.png" alt="space taking image to push other columns off center" height="100%" width="100%">
 </div>
<div class="container">

  <div class="row spaced">

    <div class="col-sm-12 text-center horizontal-center">
      <h1 class="text-box text-center horizontal-center">Are you interested to find out more? Then click the button below.</h1>
      <button type="button" class="btn btn-primary btn-lg outline text-center">Find Out More</button>
    </div>
  </div>
</div>

https://jsfiddle.net/ygznu3gy/

关于html - Bootstrap 3 中的水平对齐中心与偏移量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34866178/

相关文章:

html - Bootstrap 4 Tables(改变垂直填充/间距?)

html - 图像未与 Bootstrap 行的中心对齐

html - 如何强制 div block 内的 HTML 表格仅扩展到页面底部?

C# 引号中的引号(正则表达式匹配)

javascript - 在一个 img 标签中一个接一个地加载两个图像

javascript - 在不使用滚动条时让 WOW.js 和 fullPage.js 协同工作?

php - 输入表单不保存在 phpmyadmin 中

JavaScript 函数名 alt()

jquery - Bootstrap 4 将按钮放在顶部紧 Angular

javascript - Bootstrap 导航栏下拉菜单和汉堡不起作用