The picture shows what I want to render. The col-xs-6 divs are the main issue here; I'm assigning them a background-color to make each col-xs-6 look like a panel which means I also need there to be some visible separation between each col-xs-6.
However, any attempts at all to assign margins to the col-xs-6 divs results in them stacking under each other instead of side by side, irrespective of whether I'm testing on mobile or full desktop resolution.
[EDIT: Requested code]
<div class="row">
<div class="col-xs-12 col-sm-10 col-sm-offset-1" style="padding-left:0px; padding-right:0px">
<div class="row" data-bind="with: ElementPairs()[2]">
<div class="row">
<div class="col-xs-6 backgroundPanel fullpad" >
<div class="row">
<div class="col-xs-3">
<!-- Picture -->
<img class="img-responsive img-center" src="/Content/images/Land/buttons/button_blankImage.png" style="background: url('/content/images/land/buttons/button1.png') 50% 50% cover no-repeat;">
</div>
<div class="col-xs-9" data-bind="text: Caption">Some Caption here</div>
</div>
</div>
<div class="col-xs-6 backgroundPanel fullpad">
<div class="row">
<div class="col-xs-3">
<!-- Picture -->
<img class="img-responsive img-center" src="/Content/images/Land/buttons/button_blankImage.png" style="background: url('/content/images/land/buttons/button2.png') 50% 50% cover no-repeat;">
</div>
<div class="col-xs-9" data-bind="text: Caption">Some other caption here and additional description.</div>
</div>
</div>
</div>
</div>
</div>
</div>
However, any attempts at all to assign margins to the col-xs-6 divs
results in them stacking under each other instead of side by side,
irrespective of whether I'm testing on mobile or full desktop
resolution.
This is key for the answer. This is how the columns work in boostrap 3:
grid
grid-framework
As you can see, when they create grid layout, of 12 columns, they calculate widths in percentages, and corresponding paddings and margins. Every column is floating to the left (or right for RTL).
If one of the columns becomes wider than "standard" calculated value (in your case you added additional margin), then two div-blocks with of width col-*-6 are not fitting anymore in one row, and the last one floats to the left in the next line, it looks like it was stacked. This is what happening in your case (though, I don't exclude, that you simply messed up with the breakpoints :) - but you haven't provided the code snippet in the question).
If you need to enlarge margins, you need at the same time to give out the same space from paddings/width of each column, at the same time - playing responsive, and updating corresponding breakpoints. Normally, no one does it manually. It's recommended to use less or sass mixins to generate the new grid with your new parameters. The topic was well explained on their official website.
p.s. do not forget to wrap each column with row, when nesting columns. It's common mistake not to include rows to the layout, they are necessary.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-8">
<div class="panel panel-success">
<div class="panel-heading">
<h3 class="panel-title">Some Title</h3>
</div>
<div class="panel-body">
<p>Some Body Content Comes here</p>
</div>
<div class="panel-footer">
<p> some footer content of a box comes here</p>
</div>
</div>
</div>
<div class="col-xs-6 col-md-4">
<div class="panel panel-danger">
<div class="panel-heading">
<h3 class="panel-title">Some Title</h3>
</div>
<div class="panel-body">
<p>Some Body Content Comes here</p>
</div>
<div class="panel-footer">
<p> some footer content of a box comes here</p>
</div>
</div></div>
</div>
<div class="row">
<div class="col-xs-6 col-sm-4">
<div class="panel panel-warning">
<div class="panel-heading">
<h3 class="panel-title">Some Title</h3>
</div>
<div class="panel-body">
<p>Some Body Content Comes here</p>
</div>
<div class="panel-footer">
<p> some footer content of a box comes here</p>
</div>
</div>
</div>
<div class="col-xs-6 col-sm-4">
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title">Some Title</h3>
</div>
<div class="panel-body">
<p>Some Body Content Comes here</p>
</div>
<div class="panel-footer">
<p> some footer content of a box comes here</p>
</div>
</div>
</div>
<!-- Optional: clear the XS cols if their content doesn't match in height -->
<div class="clearfix visible-xs-block"></div>
<div class="col-xs-6 col-sm-4">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Some Title</h3>
</div>
<div class="panel-body">
<p>Some Body Content Comes here</p>
</div>
<div class="panel-footer">
<p> some footer content of a box comes here</p>
</div>
</div>
</div>
</div>
Here's the Best and simplest way of using bootstrap as boxes (panels as boxes).
The Bootstrap grid system requires col-* elements to be wrapped with "row": http://getbootstrap.com/css/#grid-example-basic
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-8">.col-xs-12 .col-sm-6 .col-md-8</div>
<div class="col-xs-6 col-md-4">.col-xs-6 .col-md-4</div>
</div>
<div class="row">
<div class="col-xs-6 col-sm-4">.col-xs-6 .col-sm-4</div>
<div class="col-xs-6 col-sm-4">.col-xs-6 .col-sm-4</div>
<!-- Optional: clear the XS cols if their content doesn't match in height -->
<div class="clearfix visible-xs-block"></div>
<div class="col-xs-6 col-sm-4">.col-xs-6 .col-sm-4</div>
</div>
Related
I can only find solutions for fixed sidebars (e.g. Creating a fixed sidebar alongside a centered Bootstrap 3 grid), but not for non-fixed ones, i.e. a sidebar that scrolls down with the content.
I am using a bootstrap grid (Bootstrap 4):
<nav class="navbar sticky-top">...</nav>
<!--content-->
<div class="container-fluid">
<div class="row">
<div class="col-md-3">
<img src="https://via.placeholder.com/150x130">
</div>
<div class="col-md-3">
<img src="https://via.placeholder.com/150x130">
</div>
<div class="col-md-3">
<img src="https://via.placeholder.com/150x130">
</div>
<div class="col-md-3">
<img src=https://via.placeholder.com/150x130">
</div>
<div class="row">
...
</div>
</div>
I need a sidebar to the left of this content, but under my top navigation bar. How do I do this?
(the number of rows I need is undefined. They will later be generated by a php loop, so I don't think I can put the sidebar in the grid system)
Just put the content in a wrapper, put another DIV before that, wrap a row around them and apply the usual classes to divide the page width:
<nav class="navbar sticky-top">...</nav>
<!--content-->
<div class="container-fluid">
<div class="row">
<div class="col-md-2 sidebar">
SIDEBAR
</div>
<div class="col-md-10">
<div class="row">
<div class="col-md-3">
<img src="https://via.placeholder.com/150x130">
</div>
<div class="col-md-3">
<img src="https://via.placeholder.com/150x130">
</div>
<div class="col-md-3">
<img src="https://via.placeholder.com/150x130">
</div>
<div class="col-md-3">
<img src="https://via.placeholder.com/150x130">
</div>
</div>
<div class="row">
some other content...
</div>
</div>
</div>
</div>
https://codepen.io/anon/pen/XZedxM
I'm using bootstrap and I have some html like this:
<div class="col-sm-12 mainContainer">
<div class="col-sm-4 imagesContainer">
<div class="col-sm-12 firstImage">
<img src="myimage1.jpg">
</div>
<div class="col-sm-12 secondImage">
<img src="myimage2.jpg">
</div>
</div>
<div class="col-sm-8 textContainer">
<p>here we have some text</p>
</div>
</div>
What I would like is to set the "imagesContainer" of the same height of the "textContainer", put the first image on top of "imagesContainer" and second image to bottom of "imagesContainer".
So, when resizing, stretching or even putting an enourm amount of text, I'll always have a image on top, one at the bottom, and a lot of white space between those two.
Thank you for your help
Please use the same bootstrap class for the following:
<div class="col-sm-4 imagesContainer">
<div class="col-sm-8 textContainer">
After change it will be like:
<div class="col-sm-8 imagesContainer">
<div class="col-sm-8 textContainer">
Final solution will be:
<div class="col-sm-12 mainContainer">
<div class="col-sm-8 imagesContainer">
<div class="col-sm-12 firstImage">
<img src="myimage1.jpg">
</div>
<div class="col-sm-12 secondImage">
<img src="myimage2.jpg">
</div>
</div>
<div class="col-sm-8 textContainer">
<p>here we have some text</p>
</div>
</div>
I'm not sure if this is a bootstrap bug or I am just not understanding the grid system. I would like the two headers (This Guy, That Guy) to align:
#import url( 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' );
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="panel panel-default">
<div class="panel-body">
<div class="row">
<div class="col-md-6">
<div class="row">
<div class="col-md-10 col-md-offset-1">
<h3>This Guy</h3>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="panel panel-default">
<div class="panel-body">
<div class="row">
<div class="col-md-12">
<div class="row">
<div class="col-md-10 col-md-offset-1">
<h3>That Guy</h3>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
I've been playing around with the grid system and in the bottom panel and column widths 1-7 all align the left margins but 9+ column width has a different left alignment.
So my question: Is there a way to align the contents of 6 and 12 column width rows in different panels using Bootstrap 3?
I think you're going to have to make your own offset class to make this work.
Every time you start a new row your starting a new column context of 12 columns. Your This Guy text is a 10 wide column offset by 1 inside of a 6 wide column. Your That Guy text is also a 10 wide column offset by 1 but it is inside of a 12 wide column. Bootstrap uses percentages so the size of .col-md-offset-1 will be different since the containers that .col-md-10 .col-md-offset-1 are in are different sizes.
Solution: create your own offset class, something like .col-md-offset-0-5.
#import url( 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' );
#media ( min-width: 992px ) {
.col-md-offset-0-5 {
margin-left: 4.1666666%;
}
}
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="panel panel-default">
<div class="panel-body">
<div class="row">
<div class="col-md-6">
<div class="row">
<div class="col-md-10 col-md-offset-1">
<h3>This Guy</h3>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="panel panel-default">
<div class="panel-body">
<div class="row">
<div class="col-md-12">
<div class="row">
<div class="col-md-10 col-md-offset-0-5">
<h3>That Guy</h3>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
I have already created this basic web page that has a header with an image and words, then below that header I have 3 blocks of text, I have one last thing to add which is another block of text below the 3 others. This block needs to be centered and extend downward instead of sideways when the text is long.
See layout example.
Here is a live example with lots of text.
Here is my current code
<div class="container-fluid">
<div class="row text-left">
<p>Having trouble viewing this email? View in browser</p>
</div>
</div>
<div class="container-fluid page-header">
<div class="row text-center">
<div class="col-xs-12">
<img src="http://ssiclouddev.azurewebsites.net/Content/Images/Icons/favicon-96x96.png" />
<h1>Susquehanna Software Inc.</h1>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row text-center">
<div class="col-xs-12 col-md-4">
<h3>From: <% =Request.QueryString["From"] %></h3>
</div>
<div class="col-xs-12 col-md-4">
<h3>Email: <% =Request.QueryString["FromEmail"] %></h3>
</div>
<div class="col-xs-12 col-md-4">
<h3>Subject: <% =Request.QueryString["FromSubject"] %></h3>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row text-center">
<div class="col-xs-12">
<div class="col-xs-6">
<h3><% =Request.QueryString["Content"] %></h3>
</div>
</div>
</div>
</div>
Replace
<div class="col-xs-12">
<div class="col-xs-6">
<h3><% =Request.QueryString["Content"] %></h3>
</div>
</div>
With
<div class="col-xs-6 col-xs-offset-3">
<h3><% =Request.QueryString["Content"] %></h3>
</div>
HTML (you shouldn't nest col- classes in another col- class without new row):
<div class="container-fluid">
<div class="row text-center">
<div class="col-xs-6 col-xs-offset-3">
<h3><% =Request.QueryString["Content"] %></h3>
</div>
</div>
</div>
CSS (allow long words to be able to break and wrap onto the next line):
h3 {
word-wrap: break-word;
}
Okay, your example actually is working fine. But because your content is just one massive word it continues outside of the parent. To check this, add this CSS: word-wrap:break-word to your h3.
I suggest using a source of dummy text such as Ipsum Lorem or Bacon Ipsum in future
I have a two columns one column is size 9 and other column is size 3. I have a Google Map inside col-3 but my map is at the bottom of the screen. How do I get it to move up?
<div class="container">
<div class="row">
<div class="col-sm-9">
content....
<div class="col-sm-3">
content...
</div>
<div>
</div>
</div>
You have your col-sm-3 nested within your col-sm-9
Try this:
<div class="container">
<div class="row">
<div class="col-sm-9">
content....
</div>
<div class="col-sm-3">
content...
</div>
</div>
</div>
If I understand your question correctly, you want the divs stacked with the 3-column div on top. If so, do it like this:
<div class="container">
<div class="row">
<div class="col-sm-9 col-sm-pull-3">
content....
</div>
<div class="col-sm-3 col-sm-pull-9">
content...
</div>
</div>
</div>