【问题标题】:Article push/pull alignment using bootstrap 3使用 bootstrap 3 的文章推/拉对齐
【发布时间】:2019-09-07 11:29:29
【问题描述】:

我正在使用 bootstrap 3,并尝试为桌面上的文章设置特定的网格对齐方式。

在移动设备上,我想订购这样的文章内容:

  1. 标题
  2. 图片
  3. 内容

在桌面上,我想要左边的图像和右边的标题和内容。

这是我的代码

<article class="row">
    <header class="col-md-8 col-md-push-4">
        <a href="#">
            <h2>Title</h2>
        </a>
    </header>
    <div class="col-md-4 col-md-pull-8">
        <figure>
            <a class="thumbnail" href="#">
        <img src="..." alt="4x3 Image" class="img-responsive">
                <figcaption>Caption</figcaption>
            </a>
        </figure>
    </div>
    <div class="col-md-8 col-md-push-4">
        <p>Content</p>
    </div>
</article>

但是使用此代码,内容在右侧但在图像下方。

有没有一种简单的方法可以得到我想要的东西?

【问题讨论】:

标签: css twitter-bootstrap twitter-bootstrap-3


【解决方案1】:

基于Possible to achieve this Mobile/Desktop layout using Bootstrap? (or other grid)

css:

.floatright{float:right;}
@media (max-width: 768px)
{    
    .floatright{float:none;}
}  

html:

<div class="container" style="background-color:green">
<article class="row">
    <header class="col-md-8 floatright">
        <a href="#">
            <h2>Title</h2>
        </a>
    </header>
    <div class="col-md-4">
        <figure>
            <a class="thumbnail" href="#">
        <img src="..." alt="4x3 Image" class="img-responsive">
                <figcaption>Caption</figcaption>
            </a>
        </figure>
    </div>
    <div class="col-md-8 floatright">
        <p>Content</p>
    </div>
</article>
</div>

【讨论】:

  • 我已经做了类似的事情来解决我的问题。我创建了一个.pull-left-md.pull-right-md
【解决方案2】:

这是你的列类:

md: 4(图片)- 8(标题)=> 第一行(最多 12 列)
8(内容)=> 新行

这将创建一个新行,第二行位于图像/标题列下方
所以你必须像这样使用这个列设置(使用隐藏类):

md: 2(图片)- 5(标题)- 5(hidden-xs hidden-sm)
5(内容)

试试这个代码:

CSS:

<style>
        .col-md-2{
            height: 300px;
            background-color: blue;
            color: white;
            border: 2px solid red;
        }
        .col-md-4{
            height: 100px;
        }
        .col-md-5{
            height: 100px;
            background-color: red;
            color: white;
            border: 2px solid black;
        }
</style>

HTML:

    <article class="row">
        <header class="col-md-5 col-md-push-2">
            <a href="#">
                <h2>Title</h2>
            </a>
        </header>
        <div class="col-md-2 col-md-pull-5">
            <figure>
                <a class="thumbnail" href="#">
                    <img src="" alt="4x3 Image" class="img-responsive">
                    <figcaption>Caption</figcaption>
                </a>
            </figure>
        </div>
        <div class="hidden-xs hidden-sm">
            <div class="col-md-4"></div>
        </div>
        <div class="col-md-5 col-md-pull-5">
            <p>Content</p>
        </div>
    </article>

也许这并不能解决问题。但你可以使用这个技巧。
对不起我的英语不好

【讨论】:

  • 通常最好在答案中提供一些解释以及您的代码,甚至根本没有代码。给一个男人一条鱼和所有这些......
【解决方案3】:

使用带有 col-md-8 类的更大 div 并在其中放置标题和文本,并在两者上使用 bootstrap 的 col-md-12 类相互堆叠

【讨论】:

    【解决方案4】:

    这是解决问题的方法

    <article class="row">
        <header class="col-md-8 pull-right">
            <a href="#">
                <h2>Title</h2>
            </a>
        </header>
        <div class="col-md-4 pull-left">
            <figure>
                <a class="thumbnail" href="#">
            <img src="..." alt="4x3 Image" class="img-responsive">
                    <figcaption>...</figcaption>
                </a>
            </figure>    </div>
        <div class="col-md-8 pull-right">
            <p>content</p>
        </div>
    </article>
    

    【讨论】:

    • pull-rightpull-left 没有响应,所以你的移动视图没有区别(列仍然浮动)?
    猜你喜欢
    • 2015-05-05
    • 2015-01-28
    • 2014-03-22
    • 2018-05-03
    • 1970-01-01
    • 2014-10-25
    • 1970-01-01
    • 2013-09-07
    • 2017-06-13
    相关资源
    最近更新 更多