bootstrap grid for mobile layout - html

I have the following markup
<div class="container">
<div class="row">
<div class="col-sm-8">
content
</div>
<div class="col-sm-4">
sidebar
</div>
</div>
<div class="row">
<div class="col-sm-8">
content
</div>
<div class="col-sm-4">
sidebar
</div>
</div>
</div>
How can i have the content section sit on top of the sidebar for mobile view? for example with the above markup ill get the following in mobile view (stack)
<div class="col-sm-8">
content
</div>
<div class="col-sm-4">
siderbar
</div>
<div class="col-sm-8">
content
</div>
<div class="col-sm-4">
siderbar
</div>
but i want to achieve the following for mobile view
<div class="col-sm-8>
content
</div>
<div class="col-sm-8">
content
</div>
<div class="col-sm-4">
sidebar
</div>
<div class="col-sm-4">
sidebar
</div>
I've seen this done before but just forgot. Thanks everyone

After multiple attempts of just experimenting I found this way.
I decided to remove one whole row and squeeze all the contents in col-sm-8 and all the sidebar content in col-sm-4
<div class="col-sm-8">
content
content
</div>
<div class="col-sm-4">
sidebar
sidebar
</div>

The you are defining the behaviour for your columns to be the same for all displays. If you want them to appear differently, you've got to use them accordingly. The sm part of your css class name tells you how you want to render on that particular size of screen. So you use xs for very small screens, s for small screens, md for medium and so on.
Changing your markup to this should do the trick, I've always found best to play around with it a bit by changing your browser size or with some nifty browser addon. I changed your columns a bit, because it seems to me like you would want your content and sidebar to take the whole width of the screen on a mobile device.
<div class="container">
<div class="row">
<div class="col-md-8 col-sm-12">
content
</div>
<div class="col-md-4 col-sm-12">
sidebar
</div>
</div>
<div class="row">
<div class="col-md-8 col-sm-12">
content
</div>
<div class="col-md-4 col-sm-12">
sidebar
</div>
</div>
</div>
See this codepen snippet for reference: http://codepen.io/anon/pen/VLoMML
You can specify different layouts for each of the bootstrap supported different screen sizes, xs being good for mobile phones, x being good for tablets, md being good for regular sized computer screens and l for large displays. The documentation is really quite comprehensive: http://getbootstrap.com/css/#grid

Related

Why is bootstrap not aligning cells correctly?

I'm trying to use Bootstrap, and having an issue that in medium resolution two columns that should be side-by-side, are displaying underneath each other, see screenshot http://dynanetics.com/problem-screenshot.png, the code is at http://dynanetics.com
At higher resolutions (large and xlarge) this works correctly. Why is this happening at medium resolution?
Any help would be appreciated, thanks.
The relevant code is below:
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="row">
<div class="col-md-3 d-block float-left">
<img src="logo-sitesmall.png" class="d-block float-none">
</div>
<div class="col-md-6 d-block float-left text-center">
<h1 class="brandname">Test site name</h1>
</div>
</div>
</div>
<div class="col-md-4">
</div>
</div>
</div>
I think your div="col-md-4", after first row div is too small for both the content to be on same line in medium resolution, try to increase it.

How to make image scale to full width on bootstrap column after transition to mobile view

I'm struggling with making the image on the right stretch to full width in a moment when you'll make the screen size smaller so it transitions to mobile view.
Is there any other class in bootstrap that would do similar work that "img-fluid" does but display image full width when it goes below the text in bootstrap grid system?
<div class="row">
<div class="col-md-6 d-flex">
<div class="align-self-center">
<p class="lead font-weight-bold">sometext</p>
</div>
</div>
<div class="col-sm-6">
<img class="img-fluid" src="someimage.jpg">
</div>
</div>
Here is my fiddle: http://jsfiddle.net/x1hphsvb/2220/
To see what I mean simply lower the width of display window. Image goes below the text and fills only half of the div when I want it to fill it fully and behave as it does right now before the transition.
Both the columns should have the same breakpoint (ie; md/sm) so that they become full-width at the same time...
<div class="row">
<div class="col-md-6 d-flex">
<div class="align-self-center">
<p class="lead font-weight-bold">sometext</p>
</div>
</div>
<div class="col-md-6">
<img class="img-fluid" src="someimage.jpg">
</div>
</div>
http://jsfiddle.net/dwnu5zjq/

Bootstrap griding system ideas

Is there any way that i achieve this design but still using the bootstrap griding system?
I want to make that design. In the sides of the div there should be an accordion like div so that i can click to close the div. I tried using col-md-5 but the grid is to much space just for side panel like. I just want a small div in right side and left side.
What about putting the text <div> inside the <div class="col-md-6">
It would be something like this :
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="row">
<div class="col-md-1">
<!-- text -->
</div>
</div>
</div>
<div class="col-md-6">
<div class="row">
<div class="col-md-offset-11 col-md-1">
<!-- text -->
</div>
</div>
</div>
</div>
</div>

How to move element above multiple containers in Bootstrap 3

I'm building a website using Bootstrap 3.
Part of this site are 4 div-containers:
<div class="container">
<div id="content" class="row">
<div class="col-sm-4 col-md-3" style="background-color:#00F; color:#FFF">
Menu
</div>
<div class="col-sm-12 col-md-3 col-md-push-6 " style="background-color:#F00;">
<div class="row">
<div class="visible-md visible-lg col-md-12" style="background-color:#F08;">
Mod_1
</div>
<div class="col-md-12" style="background-color:#F80;">
Mod_2
</div>
</div>
</div>
<div class="col-sm-8 col-md-6 col-md-pull-3" style="background-color:#0F0;">
Main content goes here
</div>
</div>
</div>
Layout-View is shown here:
Code on Fiddler
"Mod_1" is only visible in the desktop view like expected. "Mod_2" should move above the Menu and Main container in the tablet view, but I can't find a way to place the container on top of both of them.
I already tried to use the col-sm-[colnumber]-push and -pull classes. But I didn't get the right results.

Switching column order using bootstrap

I have a two column layout which I would like to switch order on mobile devices.
When I try col-xs-push-12 it doesn't switch the columns, it merely places the first column out of sight.
Here is the code
<div class="row">
<div class="col-sm-6 col-xs-12 col-xs-push-12">
<h2>Title</h2>
</div>
<div class="col-sm-6 col-xs-12">
Content will go here
</div>
</div>
UPDATE: It appears its being push'd on viewports outside xs too.
A work around would be to take a mobile-first approach and do something like this:
<div class="row">
<div class="col-sm-6 col-sm-push-6">
Content will go here
</div>
<div class="col-sm-6 col-sm-pull-6">
<h2>Title</h2>
</div>
</div>