Align button group right - css

This button-group just doesn't want to be aligned. I've tried to add pull-right, text-right, float-right bootstrap classes to btn-group div. I've tried to change text-align, padding, margin, float css properties for buttons class. Nothing helps. Only if I set padding-left value like padding-left: 28px. But that's not what I'm looking for. I need a solution for general case but not to experiment with how much pixels needed for padding-left value.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row issue">
<div class="title col-md-7">
Google
</div>
<div class="buttons btn-group col-md-5">
<button class="btn btn-success btn-sm">PR</button>
<button class="btn btn-danger btn-sm">DEL</button>
</div>
</div>

bootstrap 4
<div class="text-right">
<div class="buttons btn-group col-md-5">
<button class="btn btn-success btn-sm">PR</button>
<button class="btn btn-danger btn-sm">DEL</button>
</div>
</div>

Bootstrap by default applies float:left to buttons in a button group. But overwriting that with float:right works perfectly fine ... but than you will have the effect of the elements showing up in reverse order.
If you don’t want that, you can set float: none - and use text-align on the parent element to align the inline buttons.
.buttons { display: block; text-align: right; }
.buttons .btn { float: none; }
https://jsfiddle.net/Lhfhaa2a/1/
I added display:block for the parent element as well here, so that it takes the full width on smaller screen resolutions, too (it originally has display: inline-block set, but that would make it as wide as its content requires only - and if it is only as wide as the buttons make it, you can’t “align” them to either side any more.)

flex is the best way:
<div style="display:flex">
<div> <button>PR</button></div>
<div> <button>DEL</button></div>
</div>
This aligns the buttons. You can play around this. Do you want spaces? aligned right?

The flexbox method is superior to the float method, which might cause unwanted side-effects.
Bootstrap v5
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous"/>
<div class='row g-0'>
<div class='col-md-5 w-auto ms-auto'>
<button class="btn btn-success btn-sm">PR</button>
<button class="btn btn-danger btn-sm">DEL</button>
</div>
</div>
Bootstrap v4.6.0:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous"/>
<div class='row no-gutters'>
<div class='col-md-5 w-auto ml-auto'>
<button class="btn btn-success btn-sm">PR</button>
<button class="btn btn-danger btn-sm">DEL</button>
</div>
</div>

Related

bootstrap 4 center heading and right align button all in one row

I'm using Bootstrap 4 with React. I'm trying to center a h4 and right align couple of buttons all in one row. I could get it done but the h4 text is not centered to the entire width. It is centered only to the space that is remaining after buttons are placed.
I would like to center the h4 element to the entire width while placing the buttons to the right all in one row.
May I know how to achieve this?
<div>
<div className="float-right">
<EditButton /> <DeleteButton />
</div>
<h4 style={{ textAlign: "center" }}>Application Name</h4>
</div>
I'm understanding you want something similar to this, you would have to first set a display: inline property to the h4 so the buttons (which are inline by default) follow the heading, and then a text-center class will center everything; but I think you also want the heading itself to be at the center of the screen and the buttons at the right of it, correct?
.buttons {
top: 0px;
right: 0px;
}
h4{
right: 50%;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet" />
<h4 class="text-center">H4 Title</h4>
<div class="text-center">
<h4 class="d-inline">H4 Title</h4>
<button class="btn btn-primary">Button</button>
<button class="btn btn-primary">Button</button>
<button class="btn btn-primary">Button</button>
</div>
<div class="text-center mt-5 position-relative">
<h4 class="w-100 text-center">
H4 Title
</h4>
<div class="position-absolute buttons">
<button class="btn btn-primary">Button</button>
<button class="btn btn-primary">Button</button>
<button class="btn btn-primary">Button</button>
</div>
</div>
You can center text by using class text-center and right align button by using class text-right
where container-fluid is use for full width and m-0 p-0 is margin: 0; & padding: 0 for remove corner space.
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<div class="container-fluid p-0 m-0">
<div class="text-center">
<h4 class="d-inline">i am H4</h4>
<button class="d-inline float-right btn btn-info">Demo</button>
</div>
</div>

HTML bootstrap div button alignement

I have this code:
<div class="panel-footer rounded" style="background-color: #B7B56E">
<button class="btn btn-xs rounded" (click)="refreshNow()" style="float: right"><span class="glyphicon glyphicon-refresh"></span><small>{{nextTick|date: 'mediumTime'}}</small></button>
</div>
and result appears as:
My question is: how do I align the button at the center of the panel?
PS: It should be inside the green panel.
First of all, remove float: right. Then text-align: center should do the job:
.panel-footer {
background-color: #B7B56E;
text-align: center;
}
<div class="panel-footer rounded">
<button class="btn btn-xs rounded" (click)="refreshNow()"><span class="glyphicon glyphicon-refresh"></span><small>12 Oct 2017</small></button>
</div>
Delete float from button and add text-align: center to div element.
Here you go. Full bootstraps' classes used with no tricks. Just adding align-items-center solves the problem. But do not use the float style itself. If you use the CSS framework, please be so kind to read the docs. There are a lot of features which are enough for not to manipulate the styles for layout.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row align-items-center bg-info">
<button class="col btn btn-outline-primary">Hello I'm centered</button>
</div>
</div>
you can do the following if you still want the button to be floated right, but centered vertically inside of your panel-footer div
.panel-footer {
background-color: #B7B56E;
overflow: auto;
}
.btnClass {
float: right;
}
<div class="panel-footer rounded">
<button class="btn btn-xs rounded btnClass" id="button" (click)="refreshNow()"><span class="glyphicon glyphicon-refresh"></span><small>12 Oct 2017</small></button>
</div>

Bootstrap 4, How do I center-align a button?

<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-8">
<div v-for="job in job">
<div class="text-center">
<h1>{{ job.job_title }}</h1>
<p><strong>Google Inc. </strong> - {{ job.location }}</p>
<h2><u>Job Description</u></h2>
</div>
<p v-html="desc"></p>
<p class="text-center">Posted: {{ formatDate(job.date_created) }}</p>
<button v-on:click="applyResume()" id="apply-btn" class="btn btn-primary">{{ buttonText }}</button>
</div>
</div>
<div class="hidden-sm-down col-md-4"></div>
</div>
</div>
Can't figure out how to center this button. In BS 3 I would just use center-block but that's not an option in BS4. Any advice?
In Bootstrap 4 one should use the text-center class to align inline-blocks.
NOTE: text-align:center; defined in a custom class you apply to your parent element will work regardless of the Bootstrap version you are using. And that's exactly what .text-center applies.
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<div class="container">
<div class="row">
<div class="col text-center">
<button class="btn btn-default">Centered button</button>
</div>
</div>
</div>
If the content to be centered is block or flex (not inline-), one could use flexbox to center it:
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<div class="d-flex justify-content-center">
<button class="btn btn-default">Centered button</button>
</div>
... which applies display: flex; justify-content: center to parent.
Note: don't use .row.justify-content-center instead of .d-flex.justify-content-center, as .row applies negative margins on certain responsiveness intervals, which results into unexpected horizontal scrollbars (unless .row is a direct child of .container, which applies lateral padding to counteract the negative margin, on the correct responsiveness intervals). If you must use .row, for whatever reason, override its margin and padding with .m-0.p-0, in which case you end up with pretty much the same styles as .d-flex.
Important note: The second solution is problematic when the centered content (the button) exceeds the width of the parent (.d-flex) especially when the parent has viewport width, specifically because it makes it impossible to horizontally scroll to the start of the content (left-most).
So don't use it when the content to be centered could become wider than the available parent width and all content should be accessible.
Try this with bootstrap
CODE:
<div class="row justify-content-center">
<button type="submit" class="btn btn-primary">btnText</button>
</div>
LINK:
https://getbootstrap.com/docs/4.1/layout/grid/#variable-width-content
With the use of the bootstrap 4 utilities you could horizontally center an element itself by setting the horizontal margins to 'auto'.
To set the horizontal margins to auto you can use mx-auto . The m refers to margin and the x will refer to the x-axis (left+right) and auto will refer to the setting. So this will set the left margin and the right margin to the 'auto' setting. Browsers will calculate the margin equally and center the element. The setting will only work on block elements so the display:block needs to be added and with the bootstrap utilities this is done by d-block.
<button type="submit" class="btn btn-primary mx-auto d-block">Submit</button>
You can consider all browsers to fully support auto margin settings according to this answer Browser support for margin: auto so it's safe to use.
The bootstrap 4 class text-center is also a very good solution, however it needs a parent wrapper element. The benefit of using auto margin is that it can be done directly on the button element itself.
Here is the full HTML that I use to center by button in Bootsrap form
after closing form-group:
<div class="form-row text-center">
<div class="col-12">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
Use text-center class in the parent container for Bootstrap 4
for a button in a collapsed navbar nothing above worked for me
so in my css file i did.....
.navbar button {
margin:auto;
}
and it worked!!
thing is you need to wrap your button in a parent element :
` <div class="text-center">
<a href="./templatemo_558_klassy_cafe/index.html" class="btn btn-
outline-light me-5 ">Lavande Restaurant PH</a>`
</div>
What worked for me was (adapt "css/style.css" to your css path):
Head HTML:
<link rel="stylesheet" type="text/css" href="css/style.css" media="screen" />
Body HTML:
<div class="container">
<div class="row">
<div class="mycentered-text">
<button class="btn btn-default"> Login </button>
</div>
</div>
</div>
Css:
.mycentered-text {
text-align:center
}
you can also just wrap with an H class or P class with a text-center attribute
Its Easy
<div class="align-self-center mx-auto">
<button type="button" class="btn btn-primary">
Click Me!
</button>
</div>

Different representation of valid HTML 5 code in Firefox and Chrome

The following code displays differently in Chrome and Firefox:
#category-chooser {
width: 600px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<div class="btn-group-vertical" id="category-chooser">
<div class="btn-group btn-group-justified" data-toggle="buttons">
<div class="btn-group">
<button class="btn btn-default">
a lot of content... foo bar foo bar
</button>
</div>
<div class="btn-group" role="group" id="choose-furniture">
<button class="btn btn-default">
short
</button>
</div>
</div>
<div class="btn-group btn-group-justified" data-toggle="buttons">
<div class="btn-group">
<button class="btn btn-default">
short
</button>
</div>
<div class="btn-group">
<button class="btn btn-default">
a lot of content... foo bar foo bar
</button>
</div>
</div>
</div>
The bootstrap classes seem to do something strange here. However, on the bootstrap page, the example seems to work fine across browsers.
In Chrome, the "columns" are spaced out proportionally to the content. In Firefox, all columns have the same width.
btn-group-justified makes use of display: table, however that CSS is overridden by btn-group-vertical to display: block. I guess browsers handle btn-group (display: table-cell) differently when the parent container does not display as table.
Your codes look fine, the Bootstrap sample does not show mixed use of btn-group-vertical and btn-group-justified. I believe it is the limitation not described.
I would suggest removing btn-group-vertical and adjust the border-radius yourself.

align elements to the left

I am using twitter bootstrap. Here is my code:
<div class="control-label">
We
<div class="btn-group">
<a href="javascript:;" data-toggle="dropdown" class="btn dropdown-toggle">
<span>search</span> <span class="caret"></span>
</a>
</div>
Something
</div>
http://jsfiddle.net/3j7QP/
How can I make the texts and the button appear in one line aligned to the left using thw twitter bootstrap classes?
Classes only
Btn toolbar
If you want to stick strictly to classes, you can try .btn-toolbar but you won't have the vertical alignment.
Demo btn-toolbar
<div class="control-label btn-toolbar">
<!-- ... -->
</div>
Floating
Floating doesn't seem to be an appropriate solution because you loose the line continuity. So you shouldn't use .pull-left.
CSS
Otherwise there are several solutions :
No btn-group
First of all you could remove the div.btn-group since apparently you are not using it.
Demo no div
Inline blocks
Or you could use display: inline-block; on all elements (but you should enclose text in blocks).
Demo inline blocks
.myClass > div {
vertical-align: middle;
display: inline-block;
}
<div class="control-label myClass">
<div>We</div>
<div class="btn-group"><!-- ... --></div>
<div>Something</div>
</div>

Resources