如何使用Bootstrap在英雄单元中显示两列?

Ale*_*ker 4 rows alignment twitter-bootstrap

我试图让bootstrap的行在英雄单位内部工作.我厌倦了这个例子如何使用Bootstrap在英雄单元中显示缩略图?但它似乎不起作用.我只在英雄中获得1列.我的猜测是填充导致列换行,因为当将填充设置为0时它似乎正确对齐,但我不确定如何正确地解决这个问题.

<div class="hero-unit" style="padding: 15px;">
    <div class="page-header">
        <h2>
            Example Page Header
            <small>Example Sub Header</small>
        </h2>
    </div>

    <div class="row">
        <div class="span4">
            <img src="http://placehold.it/360x268" alt="">
        </div>

        <div class="span8">
            test
        </div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

Gar*_*ryP 12

亚历克斯,

如果您正在使用bootstrap-responsive.css或流体模板,则应用以下标记.

  <div class="hero-unit">
    <div class="row-fluid">
        <div class="columnA pull-left">
             <h2>Column A</h2>
            <img src="http://placehold.it/500x300.png"/>
        </div>

        <div class="columnB pull-right">
             <h2>Column B</h2>
            <img src="http://placehold.it/500x300.png"/>
        </div>

    </div>
  </div>
Run Code Online (Sandbox Code Playgroud)

然后在头部插入以下样式.

  .columnA,
  .columnB{
    width: 500px;

  }
Run Code Online (Sandbox Code Playgroud)

上述代码应输出类似于下图的文件:

在此输入图像描述

  • 有没有使用跨度的原因?我认为跨度通常是将信息分解为列的方式. (2认同)

ami*_*sim 11

您可以使用最多为11(而不是12)的跨度.没有额外的CSS是必要的:

<div class="hero-unit">
    <div class="row">
        <div class="span8"> column A </div>
        <div class="span3"> column B </div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

  • 为了这个,我不得不使用``row-fluid'` (3认同)
  • 当我使用排液时,这比加里接受的答案更有效.在接受的答案中,Gary让你在CSS中定义宽度 - 这些没有效果.左拉和右拉有效地将英雄分成两部分.如果您需要将列作为差异宽度,请使用上面的amirnissim答案. (2认同)