Have group of buttons on same row but separate their alignments - html

I have a simple div that contains a few anchor tags and a button. I want the first three anchor tags to be aligned to the left, and the button to be aligned to the right. But I want them to be all on the same row. My example shows all four elements to the right. How can I achieve that? Thanks
Please see
My example
I just want the first three buttons to the left of the page and the last one to the right. However, I want to keep them aligned and on same row.

You can use flexbox for that, there are many ways, one of them is the following :
.extra-buttons {
display: flex;
margin-bottom: 5px;
}
button {
margin-left: auto;
}
Another (cleaner) way would be to wrap your links in a div and apply justify-content: space-between on the .extra-buttons:
HTML:
<div class="extra-buttons">
<!-- How do I align these three anchor tags to the left -->
<div>
<a class="btn">
<span class="glyphicon glyphicon-refresh"></span> Refresh
</a>
<a class="btn">
<span class="glyphicon glyphicon-print"></span> Print
</a>
<a class="btn">
<span class="glyphicon glyphicon-plus"></span> Add
</a>
</div>
<!-- But keep this at the right (end) -->
<button>Reset</button>
</div>
CSS:
.extra-buttons {
display: flex;
justify-content : space-between
margin-bottom: 5px;
}

Related

Horizontal alignment to margins while not losing vertical alignment

In HTML, I have two elements, one with text and one containing a couple of buttons.
Instead of touching in the middle, I want them spaced to align to the left and right margins. So I want my text aligned to the left margin, and my buttons aligned to the right margin, without losing their vertical alignment as is.
I also happen to be using Bootstrap 3.
When I use pull-left/pull-right, float:left/float:right, or align="left"/align="right", I get a change in the vertical alignment of these two elements.
Paired down code looks like this essentially:
<div style="width:200px;height:100px">
Delete dashboard?
<button class="btn btn-secondary cancel">
Cancel
</button>
<button class="btn btn-danger">
Delete
</button>
</div>
What is the the most straightforward way to align these items to the left and right margins? I can do it with a table, but is that not the ideal way?
[![A modal example][2]][2]
Without seeing your code, I would use a flex layout. The key in a flex row is to use justify-content: space-between to push 2 children in the row to the far edges. Then align-items on the parent will set the vertical alignment.
.flex {
display: flex;
}
.col {
flex-direction: column;
max-width: 250px;
border: 1px solid black;
}
.bot {
border-top: 1px solid #ccc;
justify-content: space-between;
align-items: center;
}
<div class="flex col">
<div>
<h1>confirm</h1>
</div>
<div class="flex bot">
<p>delete dashboard</p>
<div>
<button>cancel</button>
<button>delete</button>
</div>
</div>
</div>
What about this?
<div class="row">
<div class="col-md-6">Dashboard</div>
<div class="col-md-6 text-right">Cancel Delete</div>
</div>
This will split your area in two columns, where all content of the right column will be aligned right, without affecting the CSS of the elements itself.

Button styled as a glyphicon, with text inside?

I´m new here, and I have a bit of a struggle with a, most lightly, simple problem.
I want to use the glyphicon-arrow-right, as a button, with the text "to test" centered inside it, is there an easy way to do this? I have this code line atm:
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<a class="btn btn-default" style="color:green" href="textview" id="totestarrow">
<span style="font-size:10em;" class="glyphicon glyphicon-arrow-right">
</span><br>Til testene
</a>
</div>
With this I get a green arrow pointing right, with the text centered underneath it. so how do I manage to put it inside of the arrow?
Thanks!
You can set your button to use position:relative, which will cause all of the elements within it to be positioned relative to it and simply use position:absolute on your actual <span> containing your text and adjust the top and left properties to get it in the proper position :
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<a class="btn btn-default" style="color:green; position: relative;" href="textview" id="totestarrow">
<span style="font-size:10em;" class="glyphicon glyphicon-arrow-right"></span>
<span class='centered-text'>
Til testene
</span>
</a>
</div>
<style>
.centered-text {
/* This will cause your element to be positioned freely over it's container */
position: absolute;
/* This will bring the element roughly halfway down the existing element */
top: 47%;
/* Colored white to stand out */
color: white;
/* The following styles will center the element in it's container */
text-align: center;
left: 0;
width: 100%;
}
</style>
You can see an example of this here and the output demonstrated below :

Bootstrap control changes position height based on width of screen

I have a bootstrap row containing a header tag and a link tag. They are aligned on the same row when the screen width is less than 768 pixels. When the container width is 768 or greater the link element shifts a few pixels higher.
Here is an example that demonstrates this behaviour: https://jsfiddle.net/bz3399x8/
<div class="row">
<div class="col-sm-12">
<a class="btn btn-primary" href="#" style="width: 80px; float: right;">
<i class="icon-plus">
Add
</i>
</a>
<h1>
Hello World
</h1>
</div>
</div>
Here are screenshots demonstrating this behaviour.
There are two issues:
what is causing this?
how to i fix this?
your syntax according to Bootstrap Docs is wrong,
it needs the .container to wrap .row
and
h1 and a button elements needs to be wrapped in Bootstrap columns.
So, you can use .col-sm-10 + .col-sm-2 in this case.
Added .col-xs for demo
.row {
/* demo*/
background:red
}
.btn {
margin-top:20px /* choose as it fit you better */
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-xs-10 col-sm-10">
<h1>
Hello World
</h1>
</div>
<div class="col-xs-2 col-sm-2">
<a class="btn btn-primary" href="#">
<i class="icon-plus">
Add
</i>
</a>
</div>
</div>
</div>
While wrapping elements in different column will help answer your problem. If you are looking at wrapping both elements inside single column you need to specify elements to be inline. Problem is occurring since h1 element and a element even though in same row for bootstrap but are displayed as block and inline-block.
Add display: inline-block to h1 element with top padding to a element. This should answer it as well.
Try it with display: inline on h1 see the difference in behavior. inline element dont support vertical margins.
Fiddle: https://jsfiddle.net/dk_dragonknight/m8ey6mba/

How to place <h3> and <button> elements side to side

I'm trying to figure out how to place my <h4> tag and <button tag to be side by side.
Current Behaviour - Right now they are underneath my image and I want them to put in a horizontal position.
Required Behaviour - I want the <h4> to be side by side with the image and the <button> side by side with the <h4>.
I tried floating to the right and display blocks, but the elements are still underneath the image and one another.
Codepen Link
Browsers by default typically display header elements as block. Use inline-block to not have it be in it's own line.
HTML
<h4>title</h4>
<button>button</button>
CSS
h4 {
display: inline-block;
}
DEMO: http://codepen.io/anon/pen/bVPXOK
Maybe
<h4 style="display:inline-block;">
heading
</h4>
<button> submit </button>
?
I saw your codepan the real problem was that your button was outside the right div that is why it was not aligned next to <h4>. I have edited the code (Updated Working Codepan)-
Modified CODE
<div class=" panel-body">
<div class="row-fluid">
<div class="row-fluid">
<img class="hotel-img img-responsive img-rounded" src="http://en.hotel-palaciodelmar.com/static/galerias/hotel/01-hotel-santander-sercotel-palacio-del-mar-fachada-foto.jpg" />
<h4 class="hotel-title""><span class="hotel-location"></span> Grand Master Flex</h4>
<button class="btn btn-primary" type="button" href="#more-info" data-toggle="modal"><i class="fa fa-info-circle"></i> More info</button>
</div>
</div>
</div>
instead of this (your previous code) -
<div class=" panel-body">
<div class="row-fluid">
<div class="row-fluid">
<img class="hotel-img img-responsive img-rounded" src="http://en.hotel-palaciodelmar.com/static/galerias/hotel/01-hotel-santander-sercotel-palacio-del-mar-fachada-foto.jpg" />
<h4 class="hotel-title""><span class="hotel-location"></span> Grand Master Flex</h4>
</div>
<button class="btn btn-primary" type="button" href="#more-info" data-toggle="modal"><i class="fa fa-info-circle"></i> More info</button>
</div>
</div>
and to align both <h4> and <Button> next to image you have to change your css and add display: inline-block !important; like this (Updated Codepan with image alignment) -
CSS
/* Hotel Search Panel */
.hotel-img {
display: inline-block !important;
width: 250px;
}
Another option you can use is the "float-right" class. If you nest your button in the h4, it can be accomplished like so:
<h4>Title<button class="float-right">My Button</button></h4>
Hope that helps!

How can add links to a header element inline with bootstrap?

I'm ussing bootstrap and want to have in the header of a section a link (button) to edit it (like wikipedia [edit] section links).
This is what I have, but its bad aligned (the button is below the text):
<h3>
<span>Details</span>
<span>
<a class="btn pull-right" href="/edit">Edit</a>
</span>
</h3>
Is some better way to handle this? (I'm almost sure that I missed the path)
The align problem was because I was adding the pull-right class (floating) directly to the button, instead of that I have to float a wrapper.
<h3>
Details
<span class="actions">
<a class="btn" href="/edit">Edit</a>
</span>
</h3>
then, I need to add:
.actions {
float: right;
}
And the button align properly as it is not floating anymore.
This is the working fiddle.
Try this:
<h3>
<span>
<a class="btn pull-right" href="/edit">Edit</a>
</span>
<span>Details</span>
</h3>