Bootstrap container divs - html

Hi guys using bootstrap and struggling to understand how to get a my main div box to have other divs inside of it
For example i am trying to make this:
This big box is just a div.
What i got so far:
<div class="container">
<div class="MainBox">
<div class="Leftbox">
<h3>Box</h3>
<div class="btn-group-vertical">
<button type="button" class="btn btn-primary btn-responsive">P</button>
<button type="button" class="btn btn-success btn-responsive">B</button>
<button type="button" class="btn btn-success btn-responsive">L</button>
<button type="button" class="btn btn-success btn-responsive">R</button>
<button type="button" class="btn btn-success btn-responsive">T</button>
<button type="button" class="btn btn-success btn-responsive">F</button>
</div>
</div>
<div class="CentreBox">
</div>
</div>
</div>
I am not so sure how to do the boxes on the right hand side , i have tried different methods but it mucks up the whole div. Any help would be great. Thanks xx

You really want to look into Bootstraps grid system, as suggested by #Sringland in his comments, found here: Bootstrap Docs
The grid system creates 12 columns on any screen size (from xtra small - large), and can be defined as a class by col-(screensize)-(span). For example - if you want 12 columns spanning a large sized screen add the class: col-lg-12 to your div.
These columns are "embeddable", and will create a new 12-column layout inside one another. So if you want to split up an 8 column layout into two equal sized containers within it, it would like like this:
<div class="col-md-8">
<div class="col-md-6"> </div>
<div class="col-md-6"> </div>
</div>
So remember, each time you "open" a column regardless of its size, that container will have another 12 columns to work with.
After all this is said, your layout will look something like this:
<div class="row height-500px">
<div class="container">
<div class="col-md-3 border height-500px">
<!-- Content goes here -->
</div>
<div class="col-md-7 border height-500px">
<!-- CONTENT GOES HERE -->
</div>
<div class="col-md-2 height-500px">
<div class="col-md-12 height-125px border">
<!-- Content goes here -->
</div>
<div class="col-md-12 height-125px border">
<!-- Content goes here -->
</div>
<div class="col-md-12 height-125px border">
<!-- Content goes here -->
</div>
<div class="col-md-12 height-125px border">
<!-- Content goes here -->
</div>
</div>
</div>
</div>
Here is a link to a Bootply to see it in action. Please see the bootply for a better understanding of the height classes and border classes. I created these simply to represent your layout.
Now, gutters (the space between the columns) are not working as intended, and I hope someone help there. But, hopefully this will be a good starting point for you.

Jus try using bootstrap grid system. I used buttons for the right column, but you can use whatever you need.
<div class="container MainBox border-on">
<div class="col-md-2 left border-on">
<h3>Box</h3>
<div class="btn-group-vertical">
<button type="button" class="btn btn-primary btn-responsive">P</button>
<button type="button" class="btn btn-success btn-responsive">B</button>
<button type="button" class="btn btn-success btn-responsive">L</button>
<button type="button" class="btn btn-success btn-responsive">R</button>
<button type="button" class="btn btn-success btn-responsive">T</button>
<button type="button" class="btn btn-success btn-responsive">F</button>
</div>
</div>
<div class="col-md-8 CentreBox border-on">
<h3>
center
</h3>
</div>
<div class="col-md-2 right border-on">
<h3>
right
</h3>
<div class="col-md-12">
One
</div>
<div class="col-md-12">
Two
</div>
<div class="col-md-12">
Three
</div>
<div class="col-md-12">
Four
</div>
</div>
</div>

Related

How to fix CSS with placing multiple buttons on one side of a row in Bootstrap?

I am trying to make a simple example where I have a row and inside that row is columns. One column is for the name of the left-hand side and on the right-hand side is the three buttons that exist. However, I am having issues placing the buttons properly on the right side as well as spacing them at an appropriate distance. I tried using the max-width in my CSS but I just ended up screwing up the project even more. Below is my HTML/CSS file:
#submitGPBtn {
margin-right: 30px;
}
<div class="row">
<div>
<h4> Group Pattern Test</h4>
</div>
<div class="mx-auto">
<button class="btn btn-primary">Save</button>
</div>
<div class="mx-auto">
<button class="btn btn-primary">Close</button>
</div>
<div class="ml-auto">
<button class="btn btn-primary" id="submitGPBtn">Submit</button>
</div>
</div>
You would want to use a btn-toolbar to group your buttons in-line.
#submitGPBtn {
margin-right: 30px;
}
<div class="row">
<div class="col">
Group Pattern Test
</div>
<div class="col">
<div class="btn-toolbar">
<button class="btn btn-primary">Save</button>
<button class="btn btn-primary">Close</button>
<button class="btn btn-primary" id="submitGPBtn">Submit</button>
</div>
</div>
</div>
This question has been answered well here. But here's an example below, add float-right class to your button bar, you can put a breakpoint in the class like float-sm-right but float-right works on any viewport width.
#submitGPBtn {
margin-right: 30px;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col">
Group Pattern Test
</div>
<div class="col">
<div class="btn-toolbar float-right">
<button class="btn btn-primary">Save</button>
<button class="btn btn-primary">Close</button>
<button class="btn btn-primary" id="submitGPBtn">Submit</button>
</div>
</div>
</div>
In bootstrap ml-auto is fine to align buttons to the right, but you should apply it only to the first item after the "offset".
I added ml-1 to space the other buttons and a lightyellow background just to show where the container ends.
My personal suggestion when you use bootstrap is to code inside a container, you can't set its size to what you want but it prevents stretching in wide monitors.
.container {
background-color: lightyellow;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col text-left">
<h4> Group Pattern Test</h4>
</div>
<button class="btn btn-success ml-auto">Save</button>
<button class="btn btn-success ml-1">Close</button>
<button class="btn btn-success ml-1" id="submitGPBtn">Submit</button>
</div>
</div>

right aligning a bootstrap footer

I have a footer that is set up as follows:
<hr>
<footer>
<div class="row">
<div class="col-md-6">
<button type="button" class="btn btn-primary" onclick="window.location.href='Glossary.html'">Glossary</button>
<button type="button" class="btn btn-primary" onclick="window.location.href='Bibliography.html'">Bibliography</button>
<button type="button" class="btn btn-primary" onclick="window.location.href='For_Help.html'">Where To Go For Help</button>
</div>
<div class="col-md-6 col-md-offset-6" style="padding-top: 5px">
<div class="panel panel-default">
<div class="panel-body col-xl-1">
<p> For questions or concerns regarding this webpage, contact: <strong>checkeredflags#gmail.com</strong></p>
<p>© 2017 Checkered Flags</p>
</div>
</div>
</div>
</div>
</footer>
How could I set it up such that the buttons are on the left, and the 2 paragraph tags are aligned with the buttons, however pulled to the right side of the screen? Currently the div with the paragraphs sits underneath the buttons. Ideally they would only go underneath when the screen size was small enough
Try This
<div class="panel-body col-xl-1">
<div class="pull-right">
<p> For questions or concerns regarding this webpage, contact:
<strong>checkeredflags#gmail.com</strong></p>
<p>© 2017 Checkered Flags</p>
</div>
</div>
Looks like the col-md-offset-6 class is pushing it down as well as the padding-top: 5px;.
See: https://codepen.io/anon/pen/ZJaJwe

Responsive table navigation bar with twitter bootstrap

Im trying to create a navigation bar for my table using twitter bootstrap.
The end result would look something like this
Im trying to use bootstraps grid system for this and seem to have gotten the showing rows part to look as planned but cant get the buttons to be responsive when the user switches to mobile.
HTML
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-8"> <!-- controls !-->
<div class="col-xs-12 col-sm-12">
Back
</div>
<div class="col-xs-12 col-sm-12">
First
</div>
<div class="col-xs-12 col-sm-12">
Previous
</div>
<div class="col-xs-12 col-sm-12">
Next
</div>
<div class="col-xs-12 col-sm-12">
Last
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4"><!-- page number !-->
<div class="pull-right">
<span>Showing rows 1 to 10 of 20</span>
</div>
</div>
</div>
</div>
The buttons seem to only render on top of each other.
Here is a jsfiddle showing whats happening.
What about a button group?
<div class="btn-group" role="group" aria-label="...">
<div class="btn-group" role="group">
<button type="button" class="btn btn-default">Back</button>
</div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-default">First</button>
</div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-default">Previous</button>
</div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-default">Next</button>
</div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-default">Last</button>
</div>
<div class="btn-group" role="group">
<span>Showing rows 1 to 10 of 20</span>
</div>
</div>
EDIT added in showing rows and made more responsive on mobile devices
Each of your button is wrapped in a div with a bootstrap class "col-sm-12" and "col-xs-12" . This means that each of those div will occupy 12 columns EACH, thereby leaving no column for other buttons or divs to lie on the same row.
To obtain the desired result, change their classes to "col-sm-2" so that each button's div occupies two columns out of twelve.

Put elements in a row and keep vertically centered no matter the size

Ok so I'm designing a Bootstrap accordion heading panel with multiple elements in it:
A big button
Some (shortish) text/title that could be multiple lines long
A small button group on the left
In theory that's working quite fine, at least if the title is not too long for the container. If it starts spilling into a second or third line, the whole concept falls apart. See my fiddle here.
What I want is that all elements are always 1. Next to each other, 2. Vertically centered.
So let me try and draw how it should look with bigger titles:
-----------------------------------------------------
| |
| ------- Text that spillls over ---------- |
| | BTN | into the next line and | | | | |
| ------- beyond! ---------- |
| |
-----------------------------------------------------
So basically, each of the three elements has it's well defined space and is vertically centered inside that.
How do I achieve this?
You can do this very simple with bootstrap grid system, read some information here: http://getbootstrap.com/css/
It should be something like:
<div class="row">
<div class="col-md-2">left content</div>
<div class="col-md-8">middle content</div>
<div class="col-md-2">right content</div>
</div>
You should read bootstrap documentation, there are more examples and more "how to", so you can find what you exactly need
Just some basics:
bootstrap grid has 12 "spaces" for columns. In example above, I created 3-column layout with middle column larger than the other (you can see 2-8-2 - and you can play wiht 3-6-3 or similar - sum must be always 12)
the "md" in col-md-... means that this column is visible only on Medium devices Desktops (≥992px), you can use "xs", or other for smaller device - it depends on what you need
Here is something that maybe what you're looking for, with vertical centering.
Here is a fiddle
And the code :
Css:
.cell {
display: table-cell;
vertical-align: middle;
float: none;
}
HTML:
<div id="panel-1" class="panel panel-default">
<div class="panel-heading clearfix">
<div class="row">
<div class="col-xs-2 cell">
<button type="button" class="btn btn-default some-button">button!</button>
</div>
<div class="col-xs-8 cell">
<h4 class="panel-title pull-left heading">
<a>Short</a>
</h4>
</div>
<div class="col-xs-2 cell" >
<div class="btn-group">
<button type="button" class="btn btn-default">a</button>
<button type="button" class="btn btn-default">b</button>
<button type="button" class="btn btn-default">c</button>
</div>
</div>
</div>
</div>
<div id="panel-2" class="panel panel-default">
<div class="panel-heading clearfix">
<div class="row">
<div class="col-xs-2 cell">
<button type="button" class="btn btn-default some-button">button!</button>
</div>
<div class="col-xs-8 cell">
<h4 class="panel-title pull-left heading">
<a>Some string that's really longish and stuff hehe right? (looooong long long)</a>
</h4>
</div>
<div class="col-xs-2 cell">
<div class="btn-group">
<button type="button" class="btn btn-default">a</button>
<button type="button" class="btn btn-default">b</button>
<button type="button" class="btn btn-default">c</button>
</div>
</div>
</div>
</div>
</div>
</div>
Why not put your button and button group into your h4 element? Also take the pull left off your div elements. Here is a fiddle with everything line up. I dont know if this is what you were looking for but I added a center align to the css class and removed the pull left from the panel title elements. I also threw the buttons into the header element
<h4 class="panel-title heading">
<div class="pull-left">
<button type="button" class="btn btn-default some-button">
button!
</button>
</div>
<a>
Some string (short)
</a>
<div class="btn-group pull-right">
<button type="button" class="btn btn-default">a</button>
<button type="button" class="btn btn-default">b</button>
<button type="button" class="btn btn-default">c</button>
</div>
</h4>

Bootstrap Button Grid-Size

I'm trying to make a button that spans 12 columns.
I know how to create a div that is 12 columns as such
<div class="row">
<div class="col-lg-12 well"></div>
</div>
But that only makes the div 12 columns long. If I was to replace the div with a input:button how would I get that to work?
Add the class btn-block and place it inside the 12-column <div>. (Note: this is Bootstrap 2.3.2)
<div class="row"><div class="span12">
<button class="btn btn-large btn-block btn-primary" type="button">Block level button</button>
</div></div>
Why not use <button></button>? (bootstrap3)
<div class='row'>
<button class='btn btn-lg btn-warning col-lg-12' >button</button>
</div>