I have the following HTML and am wondering why there is a margin between my "equals" button and the neighbouring buttons (3 and .)
<div class="row">
<div class="col-md-9">
<div class="row">
<button class="col-md-4">1</button>
<button class="col-md-4">2</button>
<button class="col-md-4">3</button>
</div>
<div class="row">
<button class="col-md-8">0</button>
<button class="col-md-4">.</button>
</div>
</div>
<div class="col-md-3">
<button class="col-md-12" id="equal">=</button>
<br/>
</div>
</div>
screen shot of described margin
SOLUTION 1:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="row">
<div class="col-xs-9">
<div class="row">
<button class="col-xs-4">1</button>
<button class="col-xs-4">2</button>
<button class="col-xs-4">3</button>
</div>
<div class="row">
<button class="col-xs-8">0</button>
<button class="col-xs-4">.</button>
</div>
</div>
<button class="col-xs-1" id="equal">=</button>
<br/>
</div>
You are getting a gap because there is a padding of 15px for bootstrap columns. So I made a few changes to your code and removed the parent div wrapper for the button with = sign and added col-xs-1 class to it. You can add col-xs-3 if you wish.
Note that I have also changed all the classes from col-md- to col-xs- which is entirely optional. You can keep it md. I have added xs so that the result can be seen on the preview screen.
SOLUTION 2:
.equal-wrapper {
padding-left: 0 !important;
padding-right: 0 !important;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="row">
<div class="col-xs-9">
<div class="row">
<button class="col-xs-4">1</button>
<button class="col-xs-4">2</button>
<button class="col-xs-4">3</button>
</div>
<div class="row">
<button class="col-xs-8">0</button>
<button class="col-xs-4">.</button>
</div>
</div>
<div class="col-xs-3 equal-wrapper">
<button class="col-xs-12" id="equal">=</button>
<br/>
</div>
</div>
Just put your button in a row, bootstrap columns have padding by default.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="row calculator">
<div class="col-md-9">
<div class="row">
<button class="col-md-4">1</button>
<button class="col-md-4">2</button>
<button class="col-md-4">3</button>
</div>
<div class="row">
<button class="col-md-8">0</button>
<button class="col-md-4">.</button>
</div>
</div>
<div class="col-md-3">
<div class="row">
<button class="col-md-12" id="equal">=</button>
</div>
</div>
</div>
Note: Check the above example in full screen mode.
HTML
Add a class calculator
<div class="row calculator">
<div class="col-md-9">
<div class="row">
<button class="col-md-4">1</button>
<button class="col-md-4">2</button>
<button class="col-md-4">3</button>
</div>
<div class="row">
<button class="col-md-8">0</button>
<button class="col-md-4">.</button>
</div>
</div>
<div class="col-md-3">
<button class="col-md-12" id="equal">=</button>
<br/>
</div>
</div>
CSS:
Remove Paddings.
.calculator .col-md-9{
padding-right:0;
}
.calculator .col-md-3{
padding-right:0;
}
You missed to wrap button tag in row class like below code
<div class="row">
<div class="col-md-9">
<div class="row">
<button class="col-md-4">1</button>
<button class="col-md-4">2</button>
<button class="col-md-4">3</button>
</div>
<div class="row">
<button class="col-md-8">0</button>
<button class="col-md-4">.</button>
</div>
</div>
<div class="col-md-3">
<div class="row">
<button class="col-md-12" id="equal">=</button>
<br/>
</div>
</div>
Related
I'm trying to center my columns across the page. I'm instead stacking rows on top of each other.
Here is my code:
<tr>
<td colspan="2" style="padding-left: 25px; padding-right: 25px;">
<div class="container">
<div class="row">
<div class="col">
<div class="row">
<div class="col-" style="font-weight:bold;">
Total Open
</div>
</div>
<div class="row">
<div class="col" id="TotalOpen">
1
</div>
</div>
</div>
<div class="col">
<div class="row">
<div class="col" style="font-weight:bold;">
Total Unassigned
</div>
</div>
<div class="row">
<div class="col" id="TotalUnassigned">
2
</div>
</div>
</div>
<div class="col">
<div class="row">
<div class="col" style="font-weight:bold;">
LSA Unassigned
</div>
</div>
<div class="row">
<div class="col" id="LSAUnassigned">
3
</div>
<button id="LSAUnassignedButton" type="button" class="btn btn-primary">TAKE</button>
</div>
</div>
<div class="col">
<div class="row">
<div class="col" style="font-weight:bold;">
LS Unassigned
</div>
</div>
<div class="row">
<div class="col" id="LSUnassigned">
4
</div>
<button id="LSUnassignedButton" type="button" class="btn btn-primary">TAKE</button>
</div>
</div>
<div class="col">
<div class="row">
<div class="col-lg-12" style="font-weight:bold;">
SLO Unassigned
</div>
</div>
<div class="row">
<div class="col" id="SLOUnassigned">
5
</div>
<button id="SLOUnassignedButton" type="button" class="btn btn-primary">TAKE</button>
</div>
</div>
<div class="col">
<div class="row">
<div class="col" style="font-weight:bold;">
ATTY Unassigned
</div>
</div>
<div class="row">
<div class="col" id="ATTYUnassigned">
6
</div>
<button id="ATTYUnassignedButton" type="button" class="btn btn-primary">TAKE</button>
</div>
</div>
</div>
</div>
</td>
</tr>
Which looks like this:
stacked columns
I'd like it to look like this:
goal
I'm using .cshtml and Bootstrap to try and accomplish this.
I'm not very good at HTML and I don't understand why columns are stacking vertically instead of horizontally.
I apologize for my terrible MS Paint skills.
If you using a bootstrap 4, use a structure row like this.
If you added a more <div> code will got block element.
So let's try like this
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="row">
<div class="col-md-2 col-sm-2">
<div style="font-weight:bold;">
Total Open
</div>
<div id="TotalOpen">
1
</div>
</div>
<div class="col-md-2 col-sm-2">
<div style="font-weight:bold;">
Total Unassigned
</div>
<div id="TotalUnassigned">
2
</div>
</div>
<div class="col-md-2 col-sm-2">
<div style="font-weight:bold;">
LSA Unassigned
</div>
<div id="LSAUnassigned">
3
</div>
<button id="LSAUnassignedButton" type="button" class="btn btn-primary">TAKE</button>
</div>
</div>
I am trying to make the background fit within bootstrap's column sizing, but still appear across the whole row. How could I achieve this?
I tried the following:
.yourcontent {
margin-bottom: 5px;
}
.yourcontent [class^=col-] {
background-color: cyan;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-xs-12">
<div class="btn-group" role="group" style="margin-top: 5px; margin-bottom: 5px">
<button type="button" class="btn btn-primary">Foo</button>
<button type="button" class="btn btn-primary">Bar</button>
<button type="button" class="btn btn-primary">Foobar</button>
<button type="button" class="btn btn-primary">Barfoo</button>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class="row yourcontent">
<div class="col-xs-6">
<div class="">
Foo
</div>
</div>
<div class="col-xs-2">
<div class="">
Bar
</div>
</div>
<div class="col-xs-2">
<div class="">
Foobar
</div>
</div>
<div class="col-xs-2">
<div class="">
Barfoo
</div>
</div>
</div>
</div>
</div>
</div>
JSFiddle
I want it to appear like this, except that the white space between the columns should be filled in with a color as well:
.yourcontent {
margin-bottom: 5px;
background-color: cyan;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-xs-12">
<div class="btn-group" role="group" style="margin-top: 5px; margin-bottom: 5px">
<button type="button" class="btn btn-primary">Foo</button>
<button type="button" class="btn btn-primary">Bar</button>
<button type="button" class="btn btn-primary">Foobar</button>
<button type="button" class="btn btn-primary">Barfoo</button>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class="row">
<div class="col-xs-6">
<div class="yourcontent">
Foo
</div>
</div>
<div class="col-xs-2">
<div class="yourcontent">
Bar
</div>
</div>
<div class="col-xs-2">
<div class="yourcontent">
Foobar
</div>
</div>
<div class="col-xs-2">
<div class="yourcontent">
Barfoo
</div>
</div>
</div>
</div>
</div>
</div>
JSFiddle
I would like the background to stretch for the whole row but not the padding-left of the first col-xs-* element and the padding-right of the last col-xs-* element within given row. Would anyone happen to know how to approach this?
In Bootstrap 4 you have the .no-gutters class. As you are using Bootstrap 3 this class isn't included. However, you can easily create this class yourself. This will remove the gutters between the columns.
.yourcontent {
margin-bottom: 5px;
background-color: cyan;
}
/*
Optional, to fix to width of the row
*/
.row.no-gutters {
margin-left: 0;
margin-right: 0;
}
.row.no-gutters > [class^="col-"] {
padding-left: 0;
padding-right: 0;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-xs-12">
<div class="btn-group" role="group" style="margin-top: 5px; margin-bottom: 5px">
<button type="button" class="btn btn-primary">Foo</button>
<button type="button" class="btn btn-primary">Bar</button>
<button type="button" class="btn btn-primary">Foobar</button>
<button type="button" class="btn btn-primary">Barfoo</button>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class="row no-gutters">
<div class="col-xs-6">
<div class="yourcontent">
Foo
</div>
</div>
<div class="col-xs-2">
<div class="yourcontent">
Bar
</div>
</div>
<div class="col-xs-2">
<div class="yourcontent">
Foobar
</div>
</div>
<div class="col-xs-2">
<div class="yourcontent">
Barfoo
</div>
</div>
</div>
</div>
</div>
</div>
I have used bootstrap for my website, simply put there are two column enclosed in col-md-12, they are col-md-6,
They should not be collapsing because enough space is given, why is this happening?
<div class="container-fluid" style="margin: 0">
<div class="row">
<div class="col-md-12">
<div class="col-md-6 ">
<div class="col-sm-12">
<img class="centering newReq" src="add-512.png" height="132" width="142">
</div>
<div class="col-sm-12">
<button type="button" class="btn btn-warning centering btnAdjust">New Request</button>
</div>
</div>
<div class="col-md-6 ">
<div class="col-sm-12">
<img class="centering newReq" src="contact.png" height="132" width="142">
</div>
<div class="col-sm-12">
<button type="button" class="btn btn-warning centering btnAdjust">My request</button>
</div>
</div>
</div>
</div>
</div>
Just remove the col-md-12 because each row contains each column. Optionally try to use
img-responsive class instead of setting width and height for image.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="container-fluid" style="margin: 0">
<div class="row">
<div class="col-md-6 ">
<div class="col-sm-12">
<img class="centering newReq img-responsive" src="https://via.placeholder.com/150" height="132" width="142">
</div>
<div class="col-sm-12">
<button type="button" class="btn btn-warning centering btnAdjust">New Request</button>
</div>
</div>
<div class="col-md-6 ">
<div class="col-sm-12">
<img class="centering newReq img-responsive" src="https://via.placeholder.com/150" height="132" width="142">
</div>
<div class="col-sm-12">
<button type="button" class="btn btn-warning centering btnAdjust">My request</button>
</div>
</div>
</div>
</div>
I'm practicing bootstrap buttons.
I've written the following code
<div class="row">
<div class="col-md-1"></div>
<div class="col-md-5">
<button class="btn btn-success performanceButton">Best case performance</button>
</div>
<div class="col-md-6"> </div>
</div>
<div class="row">
<div class="col-md-1"></div>
<div class="col-md-5">
<button class="btn btn-warning performanceButton">Average case performance </button>
</div>
<div class="col-md-6"> </div>
</div>
The code is working well, but when I test it for small screen size by downsizing the browser it seems that the text in the second button expands out of the button.
Here is a screen capture of the issue.
Does anyone know how to solve this please ? Thank you in advance :)
You need to make your columns bigger for smaller screens, try this:
<div class="row">
<div class="col-md-1"></div>
<div class="col-sm-8 col-md-5">
<button class="btn btn-success performanceButton">Best case performance</button>
</div>
<div class="col-sm-3 col-md-6"> </div>
</div>
<div class="row">
<div class="col-sm-1 col-md-1"></div>
<div class="col-sm-8 col-md-5">
<button class="btn btn-warning performanceButton">Average case performance </button>
</div>
<div class="col-sm-3 col-md-6"> </div>
</div>
By giving min-width property to your button, it won't break.
button {
min-width: 200px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="row">
<div class="col-md-1"></div>
<div class="col-md-5">
<button class="btn btn-success performanceButton">Best case performance</button>
</div>
<div class="col-md-6"> </div>
</div>
<div class="row">
<div class="col-md-1"></div>
<div class="col-md-5">
<button class="btn btn-warning performanceButton">Average case performance </button>
</div>
<div class="col-md-6"> </div>
</div>
you can also make the text of button wrap instead of making button larger
just jive button a class like and in css
.wrapit{
width: 30px;
white-space: normal;
word-Wrap: break-word;
}
Quick question on bootstrap and columns/rows. I have a cascade effect that has managers, then employees, then employee family members.
The problem is that I do not have a full understanding of bootstrap and how it uses columns/rows.
I get this result when running my code at the bottom here
But I need this result
I know this is not achieveable with my current code... Any suggestions?
Thanks in advance!
<div class="container">
<div class="row">
#{i++;}
<div class="col-md-4">
<button type="button" class="btn btn-default" data-toggle="collapse" data-target="##i">Manager Name</button>
<div id="#i" class="collapse">
<div class="row">
<div class="col-md-2">
</div>
<div class="col-md-10">
<h5>Employees</h5>
</div>
</div>
<div class="row">
<div class="col-md-2">
</div>
<div class="col-md-8">
j++;
<button type="button" class="btn btn-default" data-toggle="collapse" data-target="##j">Employee Name</button>
<br />
<div id="#j" class="collapse">
<div class="row">
<div class="col-md-4">
</div>
<div class="col-md-8">
<h5>Employee Fam Members</h5>
</div>
</div>
<div class="row">
<div class="col-md-4">
</div>
<div class="col-md-8">
#Html.ActionLink(Employee Fam Member Name, blah, blah)
</div>
</div>
<br />
</div>
<br />
</div>
<div class="col-md-2">
<br />
<br />
</div>
</div>
</div>
</div>
<div class="col-md-1">
Edit Button
</div>
<div class="col-md-7">
Delete Button
</div>
</div>
<br />
Rather than putting rows inside of columns, you'll have to make a bunch of rows on the same level instead. Otherwise the new rows would only be the width of the column it was placed in. Also, container-fluid to make it fully full width if you'd like.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="container">
<div class="row">
<div class="col-md-4">
<button type="button" class="btn btn-default" data-toggle="collapse" data-target="#i">Manager Name</button>
</div>
<div class="col-md-1">
Edit Button
</div>
<div class="col-md-7">
Delete Button
</div>
</div>
<div id="i" class="collapse">
<div class="row">
<div class="col-md-2">
</div>
<div class="col-md-10">
<h5>Employees</h5>
</div>
</div>
<div class="row">
<div class="col-md-2">
</div>
<div class="col-md-8">
<button type="button" class="btn btn-default" data-toggle="collapse" data-target="#j">Employee Name</button>
</div>
</div>
</div>
<div id="j" class="collapse">
<div class="row">
<div class="col-md-4">
</div>
<div class="col-md-8">
<h5>Employee Fam Members</h5>
</div>
</div>
<div class="row">
<div class="col-md-4">
</div>
<div class="col-md-8">
#Html.ActionLink(Employee Fam Member Name, blah, blah)
</div>
</div>
</div>
</div>