Bootstrap - Container-fluid with two columns. Right side needs to be confined - html

I need a section in bootstrap where there are two columns (6 and 6) in a row.
The left 6 column div needs to have the fluid effect where its contains stretch to the browser window's left edge.
The right 6 column div needs its contents to match/be kept within the right-side confines of the other sections of the page that have a normal (non-fluid) container class (which has a width of 1170px).
How can I best achieve this effect?

This is for 1170px wide container, you need media queries for the rest of the sizes. Hopefully helps.
CSS:
.stretch-left {
margin-left: calc((100vw - 1170px) / -2);
}
HTML:
<div class="container">
<div class="row">
<div class="col-md-6 stretch-left">
content
</div>
<div class="col-md-6">
content
</div>
</div>
</div>

Related

Can two columns with multiple elements be created without containers or JS?

I have two columns of divs, that I want to display like this.
<div id="cont">
<div class="left">
<div id="d1">1left</div>
<div id="d3">3left</div>
<div id="d5">5left</div>
</div>
<div class="right">
<div id="d4">4right</div>
<div id="d2">2right</div>
<div id="d6">6right</div>
</div>
</div>
However, for purposes of creating a responsive design I don't want to use containers, and I would prefer to not use JS for basic formatting purposes.
The problem with this, is that simply floating containers left and right creates "rows," as you can see here (3left is pushed right due to the increased size of 1left).
Is it possible to create columns of multiple divs without using containers or JS, and if so, how?
Here is my attempt:
.left {
float:left;
width: 185px;
clear:both;
}
.right {
margin-left:185px;
}
Basically, whatever width you set for .left, use that for margin-left in .right. This way you don't have to use the float property on both the div.
UPDATE #1
In .left, add:
clear:both;
JSFiddle Demo
UPDATE #2
For the extra space in the left column (if other columns on the right are larger), use:
margin-top:-50px; // (Other columns height minus the shorter left column's height.)
On the left columns below the one with a shorter height.
JSFiddle Demo
I suggest using the Bootstrap (http://getbootstrap.com/) and create your "grid" like:
<div class="container-fluid">
<!-- left column -->
<div class="col-md-6">
</div>
<!-- right column -->
<div class="col-md-6">
</div>
</div>
With Bootstrap you can specify different layout for various device sizes by just adding some CSS classes. For example if you want to have two columns in large screens and just one in mobile you can add classes like:
<div class="container-fluid">
<!-- left column in medium screens and up -->
<!-- just one column in small screens -->
<div class="col-xs-12 col-md-6">
</div>
<!-- right column in medium screens and up -->
<!-- just one column in small screens -->
<div class="col-xs-12 col-md-6">
</div>
</div>
DEMO:
http://www.bootply.com/f1zspwlokR

Responsive 4 box grid from two to one columns

I'm a beginner in css and I have a little problem. I tested different methods to handle a responsive 4 div grid with css, and I failed.
I want to responsively arrange the 4 divs as an grid with 2 columns and, if the display is to narrow it should be floating to a one column layout.
Here is a sketch of the responsive grid:
Here is a simple responsive grid with 4 div boxes in plain CSS and HTML it aranges from two to one columns when the browser width becomes smaller :
DEMO (resize the result window to see the effect)
Note that the max-width value on the #container is set to 450px so that 2 blocks + their margin can fit by width in two colmuns.
When the widow is smaller than 450px the width of the #container adapts to the window width and as the block can't fit anymore, they rearage to one column.
#container {
text-align: center;
max-width: 450px;
margin: 0 auto;
}
.block {
width: 200px;
height: 200px;
margin: 10px;
display: inline-block;
background: #00CC99;
}
<div id="container">
<div class="block">1</div>
<div class="block">2</div>
<div class="block">3</div>
<div class="block">4</div>
</div>
You may want to check out Bootstrap, and specifically their Grid System. You can easily accomplish what you want with that. Otherwise, you'd want to look into writing your own CSS Media Queries to handle the different screen sizes.
Here's a JSFiddle showing how this can be achieved using Bootstrap. Just drag the side of the Result container to make it smaller and you can see the blocks shift. This may need some tweaking but it should get you going.
<div class="row">
<div class="col-sm-2 col-sm-offset-3 col-xs-12">
<div class="block">1</div>
</div>
<div class="col-sm-3 col-xs-12">
<div class="block">2</div>
</div>
<div class="col-sm-2 col-sm-offset-3 col-xs-12">
<div class="block">3</div>
</div>
<div class="col-sm-3 col-xs-12">
<div class="block">4</div>
</div>
</div>
In the above code, I'm creating a Bootstrap Grid which uses 12 columns. You can specify the column width at different screen sizes, for example the class col-sm-2 is saying use 2/12ths of the width for small screen sizes, then offset it 3 to center it. col-xs-12 says to use the full width for extra small screen sizes (essentially moving each block to its own row for extra small screens). Note the row class as well which is also Bootstrap specific.
Hopefully this helps!
Bootstrap is a great tool to do this as the above answerer said. Bootstrap allows you to position items in a grid layout (as you want).
Another way to do this is create media queries in css that will take effect when the browser has a smaller or larger min-width.
I recommend using Bootstrap as all of the heavy lifting is done for you and you would just have to make small tweaks to ensure it looks like you want it to.

Maintaining divs side-by-side in responsive design

As a beginner user of Bootstrap's grid system, I need to keep two divs side-by-side using a float:left regardless of device. This is so that a jQuery animation moves a parent div right and left to bring either div into view. How to structure the HTML of the green boxes to achieve this effect? Or it purely a css media query matter?
Disregard the blue box.
This is what I have so far:
<div class="container">
<div class="col-xs-12 col-md-7 view">
<div id="panelviewer">
<div class="row">
<div class="col-xs-12 col-md-6 panel1">one</div>
<div class="col-xs-12 col-md-6 panel2">two</div>
</div>
</div>
</div>
</div>
Jsfiddle
There are other ways to keep the divs side by side and achieve what you need:
#panelviewer .row {white-space:nowrap;}
.panel1 {display:inline-block;float:none;background:#aaa;}
.panel2 {display:inline-block;float:none;background:#eee;}
Demo http://jsfiddle.net/7HcQ8/3/
No matter what unless you implicitly specify in a media query and your cells are too wide to fit in mobile it will force onto two lines. In this case when it hits the mobile breakpoint decrease the size of the content so it will fit. Place a unique class on those DIVs such as class="sizeSmaller" and this might help out:
#media (max-width: 768px) {
.sizeSmaller {
height:50%;
width:50%;
}
}
Adjust the width of the media query to suit your neds.

adapt bootstrap3 grid size to my needs

I have to make a very simple responsive website, thinking to use Bootstrap 3. First time playing around...
All content is maximum width 960px, very simple, just header (960px), a main interface (630px) and a sidebar (320px), with an space of 10px between both.
When we are on small devices, the sidebar should be stacked under main interface.
So, I know that Bootstrap3 accepts 12 grids, each grid maximum 70px + max 30px gutter (dividing each grid).
If I apply the code below...
<div class="container">
<div class="row">
<div class="col-sm-12">
<h1>my Header, should be 960px</h1>
</div>
</div>
<div class="row">
<div class="col-sm-8 ">This should be 630px</div>
<div class="col-sm-4 col-xs-12">This should be 320px</div>
</div>
</div>
Of course I allways get a 1170px in all content (8+4=12 grids) in desktop devices.
How can I do to make the content 960px width?
Wrap your rows in a fixed width container like..
.container-fixed {
margin: 0 auto;
max-width: 960px;
}
The row and col-* will still work responsively inside the fixed width container.
Here's a working demo: http://bootply.com/96043

How to maintain "gutter space" between "responsive" grid divs when they collapse?

Im using the newest twitter bootstrap to construct a responsive grid website. i have three divs across a responsive grid like so:
<div class="row-fluid">
<div class="span4">...</div>
<div class="span4">...</div>
<div class="span4">...</div>
</div>
...and this works as intended via the bootsrap documentation. However I have a separate background color on these divs from the html body background color, and when i drag the browser window to a smaller width to "collapse" the divs to show on top of each other, the gutter space between them disappears (creating a look of one big div versus three separate ones) is there anything i can do to create some gutter space between the divs when the width gets small enough to cause them to stack vertically?
You have a couple options...
(1) You could define a class and apply it to any divs you want to have a bottom margin.
In your application.css (or similar):
.mb10 {margin-bottom:10px;}
In your html page:
<div class="row-fluid">
<div class="span4 mb10">....</div>
<div class="span4 mb10">....</div>
<div class="span4 mb10">....</div>
</div>
OR
(2) You could make sure you wrap your div.span4 content in <p></p> tags.
<div class="row-fluid">
<div class="span4"><p>....</p></div>
<div class="span4"><p>....</p></div>
<div class="span4"><p>....</p></div>
</div>
From the Bootstrap - Typography section:
http://twitter.github.io/bootstrap/base-css.html#typography
In addition,
<p> (paragraphs) receive a bottom margin of half their line-height
(10px by default).