Bootstrap - I cannot center my five two columns inside of a ten column inside of a twelve column - css

I cannot center my five two columns inside of a ten column inside of a twelve column. http://jsfiddle.net/p8znkgv2/. I have tried the following "solutions" without any luck:
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="col-sm-1"> </div>
<div class="col-sm-10 col-centered">
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
</div>
</div>
<div class="col-sm-1"> </div>
</div>
.col-centered{ margin: auto; float: none; }
Make the container a table and each column a table cell item ( failed )
Make the container (10 column) float none with an auto margin. ( failed on large displays )
So how can I center each two column inside the ten column with the ten column centered inside the twelve column?

So how can I center each two column inside the ten column with the ten column centered inside the twelve column?
By using .col-sm-offset-* class. Examples can be found here. http://getbootstrap.com/css/#grid-offsetting. Here's a fiddle as well. http://jsfiddle.net/yongchuc/m12cysv1/

Something like this? http://jsfiddle.net/p8znkgv2/2/
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="col-sm-10 col-sm-offset-1">
<div class="col-sm-2 col-sm-offset-1">Coontent</div>
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
</div>
</div>
<div class="col-sm-1"> </div>
</div>
</div>

A lot of problems with your structure.
One is you create child div elements with those grid classes e.g. col-sm-* without adding and element with .row class first.
Html should be:
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="row">
<div class="col-sm-1"> </div>
<div class="col-sm-10 col-centered">
<div class="row">
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
</div>
</div>
<div class="col-sm-1"> </div>
</div>
</div>
</div>
</div>
And regarding to center those 5 cols, since there's no specific class for 5 cols since it's a 12 grid system, add a custom style for those elements.
e.g.
.col-centered .row .col-sm-2 {
width: 20%;
}
Fiddle

Related

Bootstrap cols not in one row

I have an issue with col that aren't in one row. I have all of them in one container, row and 3 columns col-md-5, col-md-2 and col-md-5. All paddings and margins are set from CSS bootstrap.
<div class="container">
<div class="row">
<div class="col-xs-12">
<div>
<div class="col-md-5 col-xs-12">
<div>
<div class="row-7 clearfix">
<p class="text">Výtečně<br>chutnám</p>
<img class="text-2" src="../images/unk.png" alt="!" title="!">
</div>
<div class="button-holder">Koupit</div>
</div>
</div>
<div class="col-md-2 col-xs-12 mobile-hide">
<div class="line"></div>
</div>
<div class="col-md-5 col-xs-12">
<p class="text-3">TEXT</p>
</div>
</div>
</div>
</div>
</div>
Dev page here: http://dev.ekolok.cz/
Thank you for advice and help.
I don't know what exactly your layout should look like but here is how bootstrap column layout should look:
<div class="container">
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4"></div>
<div class="col-md-4"></div>
</div>
</div>
The problem in your code is that columns aren't a direct child of row etc.
Try to refactor the code and see if you understand what is going on...
Bootstrap columns must add up to 12 per row. If you would like multiple elements in a row, your 'col-whatevers' must add up to 12.
For example if you want your title and your button on the same row your code would need to look like this:
<div class="container">
<div class="row">
<div class="col-6">
<p class="text">Výtečně<br>chutnám</p>
</div>
<div class="col-6">
<img class="text-2" src="../images/unk.png" alt="!" title="!">
</div>
</div>
</div>
You would then need to add another 'row' element and fill that up with columns that add up to 12. Not sure if this is what you're asking but it's what I could make out from your question.
Also, empty 'divs' are redundant, it doesn't mean anything. You can remove all your tags that don't carry a class, id etc.

Scrollable Card bootstrap

I am using bootstrap 4. I have 3 columns in a single row. One of the columns contains a list and the other two do not. I want only the column with the list to be scrollable but not the entire container, which means that the scrollbar muss appear only within that column.
I would appreciate any help.
<div class="row">
<div class="col-sm-4">
<div class="card">...
<div class="col-sm-4">
<div class="card">...
<div class="col-sm-4">
<div class="card">...
</div>
You could do something like this:
<div class="row">
<div class="col-sm-4">
<div class="card">...</div>
</div>
<div class="col-sm-4 scroll">
<div class="card">...</div>
</div>
<div class="col-sm-4">
<div class="card">...</div>
</div>
</div>
then in your css:
.scroll {
max-height: 100px;
overflow-y: auto;
}

How to remove space between columns [duplicate]

This question already has answers here:
Remove spacing between cols
(11 answers)
Closed 6 years ago.
I have a bootstrap, 3 column web page. Currently there is a small amount of space between each column that I would like to remove. How can I do this without editing the bootstrap.css file? Thank you.
<div class="container">
<div class="row">
<div class="col-md-2">
<div class="customDiv">
<div id="collapsible-panels">
<p>Question One goes here?</p>
<div><p>Page 2</p></div>
<p>Question Two goes here?</p>
<div><p>Answer to Question Two goes here.</p></div>
<p>Question Three goes here?</p>
<div><p>Answer to Question Three goes here.</p></div>
</div>
</div>
</div>
<div class="col-md-8">
<div class="customDiv">Main Content Area</div>
</div>
<div class="col-md-2">
<div class="customDiv">Right Side Bar</div>
</div>
</div>
</div>
Remove padding-left & padding-right from col-*-* classes in a new css file by giving them an additional class (in my case div-holder), like:
CSS:
.div-holder {
padding-left: 0;
padding-right: 0;
}
HTML:
<div class="container">
<div class="row">
<div class="col-md-2 div-holder">
<div class="customDiv">
<div id="collapsible-panels">
<p>Question One goes here?</p>
<div><p>Page 2</p></div>
<p>Question Two goes here?</p>
<div><p>Answer to Question Two goes here.</p></div>
<p>Question Three goes here?</p>
<div><p>Answer to Question Three goes here.</p></div>
</div>
</div>
</div>
<div class="col-md-8 div-holder">
<div class="customDiv">Main Content Area</div>
</div>
<div class="col-md-2 div-holder">
<div class="customDiv">Right Side Bar</div>
</div>
</div>
</div>

Bootstrap column empty space vertically

I have a problem with Bootstrap columns - there is an empty space between the columns like it's shown in the picture:
My code is straightforward - one div with class row for all columns and each column has class col-xs-2
<div class="row">
<div class="col-xs-2">
.... checkboxes with labels....
</div>
/* col-xs-2 is repeated a few times */
</div>
I've read about clearfix on similar posts here on StackOverflow but I don't know how to apply it in my case. Thanks for any help provided!
Spilt the two columns first and then start a new row like so:
<div class="row">
<div class="col-md-6">
<div class="row">
<div class="col-md-12">
Red box content
</div>
</div>
<div class="row">
<div class="col-md-12">
blue box content
</div>
</div>
</div>
<div class="col-md-6">
<div class="row">
<div class="col-md-12">
green box content
</div>
</div>
<div class="row">
<div class="col-md-12">
Other box content
</div>
</div>
</div>
</div>

Two left columns and main content in right column

Problem:
Trying to create a layout using Bootstrap 3 that consist of two columns on the left of the page and one main column to the right of the two columns. The two columns on the left should be on top of each other.
Code:
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="widget">
<div class="widget-header">
<h3>Left column 1</h3>
</div>
<div class="widget-content" id="gallery"></div>
</div>
</div>
<div class="col-md-4">
<div class="widget">
<div class="widget-header">
<h3>Left column 2</h3>
</div>
<div class="widget-content" id="gallery"></div>
</div>
</div>
<div class="col-md-8">
<div class="widget">
<div class="widget-header">
<h3>Main column</h3>
</div>
<div class="widget-content">
<div id="map_canvas" style="height: 280px;"></div>
</div>
</div>
</div>
</div>
</div>
Output:
Current code produce two columns next to each other on top the main column.
Desired output:
You should use a div with class .col-sm-4 and .col-sm-8 respectively as the parent div for the two column layout you want to use and then create the desired widgets within those divs.
Check out my JSFiddle: http://jsfiddle.net/nJtX9/9/
Please make sure to enlarge the results window to see the correct layout. Otherwise it will stack the div containers for responsive purposes.
You are using 2 col-md-4 meaning is taking 8 columns already + using col-md-8 = 16 columns, bear in mind bootstrap can contain 12 columns per row,
so the way to go around this is use col-md-2 instead of col-md-4
Hope i make this clear.
<div class="container">
<div class="row">
<div class="col-sm-6" style="background-color:gray">
<div class="row" style="background-color:aliceblue">
<h1>col1----row1</h1>
</div>
<div class="row">
<h1>col1----row2</h1>
</div>
</div>
<div class="col-sm-6" style="background-color: aqua">
<h1>col2-----row<br />col2---row<br />col2---row</h1>
</div>
</div>
</div>

Resources