I have a bootstrap grid that contain an expand component.
My actual problem is that when I expand one column, the other columns get shifted because they are in the same row.
I would like to know How can I make column independs each one to another
expand component
<p>
<button type="button" class="btn btn-outline-primary" (click)="isCollapsed = !isCollapsed"
[attr.aria-expanded]="!isCollapsed" aria-controls="collapseExample">
Toggle
</button>
</p>
<div id="collapseExample" [ngbCollapse]="isCollapsed">
<div >
<div class="">
You can collapse this card by clicking Toggle
</div>
</div>
</div>
app component ( container )
<div class="row">
<div *ngFor="let card of cards; let index=index" class="col-4 col-sm-4 col-xl-4">
<app-expend></app-expend>
</div>
</div>
Here's what is happening
Here's what I expect
Here's an example to illustrate my actual problem
Is accordion what you need? Check this example,
https://getbootstrap.com/docs/4.0/components/collapse/#accordion-example
Background:The website I am working on there are several different filters that people can use in order to show only the data they need; basic stuff. To make things look nice since I am not css inclined, I am using bootstrap to make things look clean.
Problem: I can't seem to get the buttons to line up with the right side of the fields. I can make them pull to the very edge of the field set, I can make push/pull them to the general area they should be in, but I can't get them to line up nicely and stay that way regardless of how you rearrange the size of the page window.
JSFiddle: https://jsfiddle.net/v3cugpx1/1/
<div class="form-group col-md-12">
<div class="input-group-btn">
<div class="pull-right">
<a class="btn btn-info" href="#" title="Clear"><i class="glyphicon glyphicon-arrow-left"></i> Clear</a>
<button class="btn btn-primary" title="Filter" type="submit"><i class="glyphicon glyphicon-search"></i> Filter</button>
</div>
</div>
</div>
Any help would be greatly appreciated.
Cheers!
It's important to match the nesting of columns because of the gutters in the grid, which the other answers remark upon. If you start with the other two answers, it's easy enough to modify them to add the margin between the buttons you're looking for:
<div class="form-group col-md-12">
<div class="col-md-12">
<div class="btn-toolbar col-md-12">
<a class="btn btn-info pull-right" href="#" title="Clear"><i class="glyphicon glyphicon-arrow-left"></i> Clear</a>
<button class="btn btn-primary pull-right" title="Filter" type="submit"><i class="glyphicon glyphicon-search"></i> Filter</button>
</div>
</div>
</div>
The only really real addition is the btn-toolbar class to the inner-most div. And for posterity here's the Fiddle.
Don't use .input-group instead use col-sm-* classes to give extra padding multiple times, so that you can match the padding available on all other form elements. And then arrange the buttons inside of it, like:
<div class="form-group col-md-12"> <!-- Extra Padding (15px) -->
<div class="col-xs-12"> <!-- Extra Padding (15px) -->
<div class="col-xs-12"> <!-- Extra Padding (15px) -->
<a class="btn btn-info" href="#" title="Clear"><i class="glyphicon glyphicon-arrow-left pull-left"></i> Clear</a>
<button class="btn btn-primary pull-right" title="Filter" type="submit"><i class="glyphicon glyphicon-search"></i> Filter</button>
</div>
</div>
</div>
Have a look at the updated Fiddle.
Hope this helps!
You are using wrapper cols for the inputs. I included one "col-md-12" before the button's "form-group" and another one after it. This way your code stay consistent and you achieve what you want.
<div class="col-md-12"> <----
<div class="form-group col-md-12">
<div class="col-md-12"> <----
<div class="input-group-btn">
Updated Fiddle
I have read many topics here on stackoverflow regarding this question. I have read and used the solutions provided here, however! for some reason this stuff just doesn't work with me. I get a completely blank page.
The idea is to get primary button above the default button on extra small devices. For some reason i am completely blank even on md and sm devices.
Would appreciate help. Thank you
<body>
<div class="row">
<div class="col-md-6 col-xs-12 col-xs-push-12">
<button class="btn btn-default" type="button">Button</button>
</div>
<div class="col-md-6 col-xs-12 col-xs-pull-12">
<button class="btn btn-primary" type="button">Button</button>
</div>
</div>
</body>
You just need to think "mobile-first". Create the markup for the smallest device layout first, and then adjust it using push/pull for larger screens. The col-xs-12 is not necessary since the columns stack automatically on xs widths.
<div class="row">
<div class="col-md-6 col-md-push-6">
<button class="btn btn-primary" type="button">Button</button>
</div>
<div class="col-md-6 col-md-pull-6">
<button class="btn btn-default" type="button">Button</button>
</div>
</div>
Demo: http://codeply.com/go/aUME1OcT0S
Update: As of Bootstrap 4, it's possible to re-order 12 unit columns: bootstrap pulling/pushing 12 columns not working properly
Unfortunately you cannot use the push/pull method on col-*-12 because of the way push/pull works. So a solution that works very well is to have the order correct for mobile and then use the push/pull method on larger screen sizes like this:
<div class="row">
<div class="col-xs-12 col-md-6 col-md-push-6">
<button class="btn btn-primary" type="button">Button</button>
</div>
<div class="col-xs-12 col-md-6 col-md-pull-6">
<button class="btn btn-default" type="button">Button</button>
</div>
</div>
And here is a working codepen: http://codepen.io/egerrard/pen/NdqpXZ?
FYI, you are also only using md and xs column notations but you mention you only want this functionality for xs screen sizes. If that is the case you need to change your md columns to sm.
I am building a form in Twitter Bootstrap but I'm having issues with centering the button below the input in the form. I have already tried applying the center-block class to the button but that didn't work. How should I fix this?
Here is my code.
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="singlebutton"></label>
<div class="col-md-4">
<button id="singlebutton" name="singlebutton" class="btn btn-primary center-block">
Next Step!
</button>
</div>
</div>
Wrap the Button in div with "text-center" class.
Just change this:
<!-- wrong -->
<div class="col-md-4 center-block">
<button id="singlebutton" name="singlebutton" class="btn btn-primary center-block">Next Step!</button>
</div>
To this:
<!-- correct -->
<div class="col-md-4 text-center">
<button id="singlebutton" name="singlebutton" class="btn btn-primary">Next Step!</button>
</div>
Edit
As of BootstrapV4, center-block was dropped #19102 in favor of m-*-auto
According to the Twitter Bootstrap documentation: http://getbootstrap.com/css/#helper-classes-center
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="singlebutton"></label>
<div class="col-md-4 center-block">
<button id="singlebutton" name="singlebutton" class="btn btn-primary center-block">
Next Step!
</button>
</div>
</div>
All the class center-block does is to tell the element to have a margin of 0 auto, the auto being the left/right margins. However, unless the class text-center or css text-align:center; is set on the parent, the element does not know the point to work out this auto calculation from so will not center itself as anticipated.
See an example of the code above here: https://jsfiddle.net/Seany84/2j9pxt1z/
<div class="row">
<div class="col-sm-12">
<div class="text-center">
<button class="btn btn-primary" id="singlebutton"> Next Step!</button>
</div>
</div>
</div>
add to your style:
display: table;
margin: 0 auto;
<div class="container-fluid">
<div class="col-sm-12 text-center">
<button class="btn btn-primary" title="Submit"></button>
<button class="btn btn-warning" title="Cancel"></button>
</div>
</div>
You can do it by giving margin or by positioning those elements absolutely.
For example
.button{
margin:0px auto; //it will center them
}
0px will be from top and bottom and auto will be from left and right.
I tried the following code and it worked for me.
<button class="btn btn-default center-block" type="submit">Button</button>
The button control is in a div and using center-block class of bootstrap helped me to align the button to the center of div
Check the link where you will find the center-block class
http://getbootstrap.com/css/#helper-classes-center
use text-align: center css property
Update for Bootstrap 4:
Wrap the button with a div set with the 'd-flex' and 'justify-content-center' utility classes to take advantage of flexbox.
<!-- Button -->
<div class="form-group">
<div class="d-flex justify-content-center">
<button id="singlebutton" name="singlebutton" class="btn btn-primary">
Next Step!
</button>
</div>
</div>
The benefit of using flexbox is being able to add additional elements/buttons on the same axis, but with their own separate alignment. It also opens up the possibility of vertical alignment with the 'align-items-start/center/end' classes, too.
You could wrap the label and button with another div to keep them aligned with each other.
e.g. https://codepen.io/anon/pen/BJoeRY?editors=1000
You can do the following. It also avoids buttons overlapping.
<div class="center-block" style="max-width:400px">
Accept
Reject
</div>
It works for me
try to make an independent <div>then put the button into that.
just like this :
<div id="contactBtn">
<button type="submit" class="btn btn-primary ">Send</button>
</div>
Then Go to to your CSSStyle page and do the Text-align:center like this :
#contactBtn{text-align: center;}
For Bootstrap 3
we divide the space with the columns, we use 8 small columns (col-xs-8), we leave 4 empty columns (col-xs-offset-4) and we apply the property (center-block)
<!--Footer-->
<div class="modal-footer">
<div class="col-xs-8 col-xs-offset-4 center-block">
<button type="submit" class="btn btn-primary">Enviar</button>
<button type="button" class="btn btn-danger" data-dismiss="modal">Cerrar</button>
</div>
</div>
For Bootstrap 4
We use Spacing, Bootstrap includes a wide range of abbreviated and padded response margin utility classes to modify the appearance of an element.
The classes are named using the format {property}{sides}-{size} for xs and {property}{sides}-{breakpoint}-{size} for sm, md, lg, and xl.
more info here: https://getbootstrap.com/docs/4.1/utilities/spacing/
<!--Footer-->
<div class="modal-footer">
<button type="submit" class="btn btn-primary ml-auto">Enviar</button>
<button type="button" class="btn btn-danger mr-auto" data-dismiss="modal">Cerrar</button>
</div>
I had this problem. I used
<div class = "col-xs-8 text-center">
On my div containing a few h3 lines, a couple h4 lines and a Bootstrap button.
Everything besides the button jumped to the center after I used text-center so I went into my CSS sheet overriding Bootstrap and gave the button a
margin: auto;
which seems to have solved the problem.
or you can give specific offsets to make button position where you want simply with bootstrap grid system,
<div class="col-md-offset-4 col-md-2 col-md-offset-5">
<input type="submit" class="btn btn-block" value="submit"/>
this way, also let you specify button size if you set btn-block.
sure, this will only work md size range, if you want to set other sizes too, use xs,sm,lg.
I looked and haven't found my specific problem. I'm trying to build a responsive webpage, with a lg layout that has 12 images with text below them, a med and a sm layout with text and pics next to each other, and an xs layout with images above text again.
I cannot get the images and the paragraphs to sit beside each other in the column. I've tried push-x, pull-x, offset-x, media queries where I made a div for each .img and .p and made them float.
I'm sure there's an easy way to do it, but this is my first week of Bootstrap, and I can't figure it out. How is this done?
Here's a sample of my code:
<div class="row">
<div class="content col-lg-2 col-md-4 col-sm-6 col-xs-12">
<h2>Fork and Spoon</h2>
<div class="frame1"><img class="img-responsive" src="./images/spork.jpg" alt="Spork"></div>
<p>We are the <em>spork of the party!</em> Yes, we've endured most every cutting remark; just don't refer to my wife as "flatware" and she is happy. </p>
<p><a class="btn btn-default" href="#">More utensils here »</a></p>
</div>
Put a grid inside your larger grid. Code below, working example at http://bootply.com/91851
<div class="row">
<div class="content col-lg-2 col-md-4 col-sm-6">
<h2>Fork and Spoon</h2>
<div class="row">
<div class="col-lg-12 col-sm-6">
<img class="img-responsivet" src="./images/spork.jpg" alt="Spork">
</div>
<div class="col-lg-12 col-sm-6">
<p>We are the <em>spork of the party!</em> Yes, we've endured most every cutting remark; just don't refer to my wife as "flatware" and she is happy. </p>
</div>
</div>
<p><a class="btn btn-default" href="#">More utensils here »</a></p>
</div>
...repeat...
</div><!--/row-->
Also note that you do not need to explicitly set .col-xs-12, as this is the default if you do not set col-xs at all.