Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Article push/pull alignment using bootstrap 3

I'm using bootstrap 3 and I try to have a specific grid alignment for article on desktop.

On mobile I want to order content of the article like that :

  1. Title
  2. Image
  3. Content

On desktop, I want the image on the left and the title and content on the right.

Alignment i want

Here is my code

<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>

But with this code, the content is on the right but under the image.

Is there a simple way to get what I want ?

like image 979
alienlebarge Avatar asked Sep 27 '13 09:09

alienlebarge


2 Answers

Based on 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>
like image 128
Bass Jobsen Avatar answered Sep 28 '22 02:09

Bass Jobsen


it's your columns class:

md: 4 (image) - 8 (title) => 1st row (max 12 columns)
8 (content) => new row

that's will make a new row, the 2nd row placed below image/title column
so you must use this columns setting (using hidden class) like this:

md: 2 (image) - 5 (title) - 5 (hidden-xs hidden-sm)
5 (content)

just try this code:

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>

maybe it's not solve the problem. but you can use this trick.
sorry for my bad english

like image 36
juicided Avatar answered Sep 28 '22 01:09

juicided