I am using bootstrap 3 and have a my data coming from a service. I am using ng-repeat to render the design,I need two buttons to appear in one row and if we are using mobile then one button in a row. The Buttons should be center on the screen as indicated below.
Button Text 1 Button Text 2
Button Tex 3 Button Text 4
This is my html code
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-sm-4 col-md-offset-2"><button type="button" class="btn btn-default btn-block">Here sits text 1</button></div>
<div class="col-sm-4"><button type="button" class="btn btn-default btn-block">Here sits text 2</button></div>
</div>
<div class="row">
<div class="col-sm-4 col-md-offset-2"><button type="button" class="btn btn-default btn-block">Here sits text 3</button></div>
<div class="col-sm-4">
<button type="button" class="btn btn-default btn-block" style="word-wrap: break-word;">Here sits text 4 </button></div>
</div>
</div>
How would I avoid using multiple rows in order to force two columns?
I am asking for that to make my ng-repeat just render some columns because, it would not work with this design?
Update For Question:
I have updated using the answer suggested below, its working now:
<div class="container">
<div class="row">
<div class="col-sm-4 col-md-offset-2 col-sm-offset-2 col-lg-offset-2 col-lg-4 col-md-4 col-sm-4 col-xs-12" style="text-align:center;">
<button type="button" class="btn btn-primary btn-block">Button text 1</button>
</div>
<div class="col-sm-4 col-lg-4 col-md-4 col-sm-4 col-xs-12" style="text-align:center;">
<button type="button" class="btn btn-primary btn-block">Button text 2</button>
</div>
<div class="col-sm-4 col-md-offset-2 col-sm-offset-2 col-lg-offset-2 col-lg-4 col-md-4 col-sm-4 col-xs-12" style="text-align:center;">
<button type="button" class="btn btn-primary btn-block">Button text 1</button>
</div>
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-12" style="text-align:center;">
<button type="button" class="btn btn-primary btn-block">Button text 4</button>
</div>
</div>
Is it possible to use the same styling for cols and and make it work (there are offsets on alternate cols.
I thinkyou should take a look at this: https://jsfiddle.net/2zu0oksc/
You can have a div with class row and many col-*
Setting the col-xs-12 to the div, you are saying taht in small devices it will take all the row width.
This is the code:
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12" style="text-align:center;">
<button type="button" class="btn btn-primary">Button text 1</button>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12" style="text-align:center;">
<button type="button" class="btn btn-primary">Button text 2</button>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12" style="text-align:center;">
<button type="button" class="btn btn-primary">Button text 3</button>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12" style="text-align:center;">
<button type="button" class="btn btn-primary">Button text 4</button>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-xs-8 col-xs-offset-2">
<div class="col-xs-2 col-xs-offset-4">
<button class="btn btn-primary">
Text 1
</button>
</div>
<div class="col-xs-2 col-xs-offset-1">
<button class="btn btn-primary">
Text 1
</button>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-8 col-xs-offset-2">
<div class="col-xs-2 col-xs-offset-4">
<button class="btn btn-primary">
Text 1
</button>
</div>
<div class="col-xs-2 col-xs-offset-1">
<button class="btn btn-primary">
Text 1
</button>
</div>
</div>
</div>
</div>
https://jsfiddle.net/wuy235f9/
This works but you'll have to adjust the offset and col size you want for it!
Related
I am using Bootstrap 5's flexbox grid to design a responsive mobile-first Angular web application.
I would like the home screen of my app to have these 3 elements :
The name of the app at the top of the screen
A row of buttons in the middle of the screen
A footer at the bottom of the screen
What would be the best responsive way to position these elements at the top, middle and bottom of the screen respectively, while keeping them horizontally centered.
My code at the moment looks like this :
<div class="container-fluid">
<div class="row">
<div class="col-12 d-flex justify-content-center">
<h1>App name</h1>
</div>
</div>
<div class="row">
<div class="col-12 col-sm-6 col-lg-3 d-flex">
<button type="button" class="btn btn-outline-primary flex-fill">First button</button>
</div>
<div class="col-12 col-sm-6 col-lg-3 d-flex">
<button type="button" class="btn btn-outline-primary flex-fill">Second button</button>
</div>
<div class="col-12 col-sm-6 col-lg-3 d-flex">
<button type="button" class="btn btn-outline-primary flex-fill">Third button</button>
</div>
<div class="col-12 col-sm-6 col-lg-3 d-flex">
<button type="button" class="btn btn-outline-primary flex-fill">Fourth button</button>
</div>
</div>
<div class="row">
<div class="col-12 d-flex justify-content-center">
<p>Footer</p>
</div>
</div>
Thank you!
The same way as with any flexbox vertical alignment in Bootstrap. For example, auto-margins in flexbox container...
<div class="container-fluid vh-100 d-flex flex-column">
<div class="row">
<div class="col-12 d-flex justify-content-center">
<h1>App name</h1>
</div>
</div>
<div class="row my-auto">
<div class="col-12 col-sm-6 col-lg-3 d-flex">
<button type="button" class="btn btn-outline-primary flex-fill">First button</button>
</div>
<div class="col-12 col-sm-6 col-lg-3 d-flex">
<button type="button" class="btn btn-outline-primary flex-fill">Second button</button>
</div>
<div class="col-12 col-sm-6 col-lg-3 d-flex">
<button type="button" class="btn btn-outline-primary flex-fill">Third button</button>
</div>
<div class="col-12 col-sm-6 col-lg-3 d-flex">
<button type="button" class="btn btn-outline-primary flex-fill">Fourth button</button>
</div>
</div>
<div class="row">
<div class="col-12 d-flex justify-content-center">
<p>Footer</p>
</div>
</div>
</div>
Demo
I need to center horizontally a set of buttons into div.
My problem is that the buttons continues left aligned.
//css
.space-btn{
margin-bottom:5px!important;
}
here is my markup:
<div class="row">
<div class="col-sm-12">
<div class="panel panel-default">
<div class="panel-body">
<div class="text-center">
<div class="btn-toolbar">
<button class="btn btn-primary space-btn" type="button">Histórico</button>
<button class="btn btn-primary space-btn" type="button">Reagendar</button>
<button class="btn btn-primary space-btn" type="button">Detalhes</button>
</div>
</div>
</div>
</div>
</div>
</div>
The issue is that btn in bootstrap used inside btn-toolbar are floated
so you may add this code :
.space-btn {
float: none!important;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="row">
<div class="col-sm-12">
<div class="panel panel-default">
<div class="panel-body">
<div class="btn-toolbar text-center">
<button class="btn btn-primary space-btn" type="button">Histórico</button>
<button class="btn btn-primary space-btn" type="button">Reagendar</button>
<button class="btn btn-primary space-btn" type="button">Detalhes</button>
</div>
</div>
</div>
</div>
</div>
There is no big issue in code you have to change position of text-center class. this will come like this.
<div class="row">
<div class="col-sm-12">
<div class="panel panel-default">
<div class="panel-body">
<div class="btn-toolbar text-center">
<button class="btn btn-primary space-btn" type="button">Histórico</button>
<button class="btn btn-primary space-btn" type="button">Reagendar</button>
<button class="btn btn-primary space-btn" type="button">Detalhes</button>
</div>
</div>
</div>
</div>
</div>
There is a small change also in css which is
.space-btn{
float:none!important;
}
Add text-center class to the button container.
<div class="row">
<div class="col-sm-12">
<div class="panel panel-default">
<div class="panel-body">
<div class="btn-toolbar text-center">
<button class="btn btn-primary space-btn" type="button">Histórico</button>
<button class="btn btn-primary space-btn" type="button">Reagendar</button>
<button class="btn btn-primary space-btn" type="button">Detalhes</button>
</div>
</div>
</div>
</div>
</div>
I cant find the way to put the button on the same line as the form and text in responsive desing for mobile.
<div class="col-xs-12 col-md-6 nopadding">
<div class="row col-xs-8 col-md-8 pts-vcenter">
<div class="col-xs-4 col-sm-5 col-md-5">
<span class="bold">{l s='Voucher' mod='onepagecheckoutps'}</span>
</div>
<div class="col-xs-4 col-sm-7 col-md-7 nopadding-xs">
<input type="text" class="discount_name form-control" id="discount_name" name="discount_name" value="{if isset($discount_name) && $discount_name}{$discount_name|escape:'htmlall':'UTF-8'}{/if}" />
</div>
</div>
<div class="col-xs-4">
<span type="button" id="submitAddDiscount" name="submitAddDiscount" class="btn btn-default btn-small">
{l s='Add' mod='onepagecheckoutps'}
</span>
</div>
</div>
Try to use col-xs-12 like this:
<div class="col-xs-12">
<span type="button" id="submitAddDiscount" name="submitAddDiscount" class="btn btn-default btn-small">
{l s='Add' mod='onepagecheckoutps'}
</span>
</div>
And don't forget to use the row class :)
I have a group of buttons group:
<div class="row">
<div class="col-md-2">
<div class="btn-group-vertical btn-group-justified" role="group" id="nav_bar">
<div id="accordion" role="tablist" aria-multiselectable="true">
<div class="row">
<a class="btn btn-primary" data-toggle="collapse" href="#Setup1" data-parent="#accordion">Setup1</a>
<div id="Setup1" class="panel-collapse collapse">
<div class="col-md-12">
<div class="btn-group-vertical btn-group-justified" role="group">
<div class="row">
<button type="button" class="btn btn-default">MAIN</button>
</div>
<div class="row">
<button type="button" class="btn btn-default">EXEC</button>
</div>
<div class="row">
<button type="button" class="btn btn-default">ROUTER</button>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<a class="btn btn-primary" data-toggle="collapse" href="#Setup2" data-parent="#accordion">Setup2</a>
<div id="Setup2" class="panel-collapse collapse">
<div class="col-md-12">
<div class="btn-group-vertical btn-group-justified" role="group">
<div class="row">
<button type="button" class="btn btn-default">MAIN</button>
</div>
<div class="row">
<button type="button" class="btn btn-default">EXEC</button>
</div>
<div class="row">
<button type="button" class="btn btn-default">ROUTER</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
and in output this is:
but I cant figure out, how to make collapse one group, when you expand other. Could someone help with that?
I was trying to play with panels, but it's unsuitable, because i need a style, which showed on attached image. And in panels only text is clickable.
Thanks
You can do it by setting up your elements with bootstrap properly.
But you can also extend the collapse by:
$('.btn').on('click',function(){
$('.panel-collapse').each(function(){
$(this).removeClass('in');
}):
});
<div class="row">
<div class="col-md-6 col-sm-8 col-xs-12">
<a class="btn btn-default" id="lnkBtnSave" onclick=" GetSaveData(); ">Save</a>
<a class="btn btn-default" id="lnkBtnSubmit" onclick=" GetSubmitData(); ">Submit</a>
<asp:LinkButton class="btn btn-default" id="lnkBtnAttach" runat="server" OnClick="lnkBtnAttach_OnClick" Text="Attach" ></asp:LinkButton>
<asp:LinkButton class="btn btn-default" id="lnkBtnExit" runat="server" OnClick="lnkBtnExit_OnClick" Text="Exit"></asp:LinkButton>
</div>
</div>
I have 4 buttons in row. How can i stretch this buttons on all row?
Currently it looks like :
What i want looks like this :
Add a div around each of them and give it the dimensions you want. Tried it on my website just now and I have four buttons stretching across the page.
<div class="row">
<div class="col-md-3 col-sm-3 col-xs-6 text-center">
<a class="btn btn-default" id="lnkBtnSave" onclick=" GetSaveData(); ">Save</a>
</div>
<div class="col-md-3 col-sm-3 col-xs-6 text-center">
<a class="btn btn-default" id="lnkBtnSubmit" onclick=" GetSubmitData(); ">Submit</a>
</div>
<div class="col-md-3 col-sm-3 col-xs-6 text-center">
<asp:LinkButton class="btn btn-default" id="lnkBtnAttach" runat="server" OnClick="lnkBtnAttach_OnClick" Text="Attach" ></asp:LinkButton>
</div>
<div class="col-md-3 col-sm-3 col-xs-6 text-center">
<asp:LinkButton class="btn btn-default" id="lnkBtnExit" runat="server" OnClick="lnkBtnExit_OnClick" Text="Exit"></asp:LinkButton>
</div>
</div>
Wrap each button in a .col-xs-3 div and apply a text-align:center on those divs:
.row > div {
text-align:center
}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-xs-12">
<div class="col-xs-3">
<a class="btn btn-default" id="lnkBtnSave" onclick=" GetSaveData(); ">Save</a>
</div>
<div class="col-xs-3">
<a class="btn btn-default" id="lnkBtnSubmit" onclick=" GetSubmitData(); ">Submit</a>
</div>
<div class="col-xs-3">
<a class="btn btn-default" id="lnkBtnAttach" runat="server" OnClick="lnkBtnAttach_OnClick" Text="Attach" >Attach</a>
</div>
<div class="col-xs-3">
<a class="btn btn-default" id="lnkBtnExit" runat="server" OnClick="lnkBtnExit_OnClick" Text="Exit">Exit</a>
</div>
</div>
</div>