【问题标题】:Bootstrap button not aligned in center after aligning with CSS与 CSS 对齐后,引导按钮未居中对齐
【发布时间】:2016-06-19 05:50:48
【问题描述】:

我目前正在关注 Michael Hartl 的 ruby​​ on rails 教程,并且我目前正在使用 Bootstrap 版本 3。问题是我的按钮没有像文本那样在中心对齐

这就是它的样子

但是我的看起来像

在实现这些 CSS 样式之后,对齐文本和按钮的教程发生了变化:

有人可以指导我正确的方向吗?我的 Jumbotron 的代码是这样的:

  <div class="jumbotron">
  <h1>Welcome to the Sample App</h1>

   <h2>
       This is the home page for the
       <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
       sample application.
   </h2>

     <%= link_to "Sign up now!", '#', class: "btn btn-primary btn-lg" %>
  </div>

 <%= link_to image_tag("rails.png", alt: "Rails"), 'http://rubyonrails.org/' %>

我承认,我对 CSS 不是很好,否则我会自己解决这个问题 谢谢!

【问题讨论】:

    标签: css ruby-on-rails html twitter-bootstrap


    【解决方案1】:

    将 center-block 类添加到 div 就可以了

        <div class="center-block jumbotron">
    
        </div>
    

    现在这个 jumbotron 将居中对齐。

    编辑:截至 2016 年,您可以使用 text-centre 类来执行此操作。

    【讨论】:

    • 你能提供一个小例子吗?
    【解决方案2】:

    center 类添加到您的jumbotron div

    <div class="center jumbotron">
      <h1>Welcome to the Sample App</h1>
    
      <h2>
       This is the home page for the
       <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
       sample application.
      </h2>
    
      <%= link_to "Sign up now!", '#', class: "btn btn-primary btn-lg" %>
    </div>
    

    【讨论】:

    • 为什么我必须在我的 jumbotron 中添加一个中心?
    • @ApprenticeProgrammer,因为你想把它放在你的 jumbotron 中。看看一些 CSS 提示和技巧:w3.org/Style/Examples/007/center.en.html
    猜你喜欢
    • 2017-02-19
    • 1970-01-01
    • 1970-01-01
    • 2014-03-20
    • 2022-08-19
    • 1970-01-01
    • 2011-01-29
    • 2016-08-10
    • 2017-04-16
    相关资源
    最近更新 更多