I am trying to align some font-awesome arrow vertically inside two Bootstrap buttons.
Actually both the text and the icons should be vertically aligned in the middle of the button.
If the text inside falls into a single line or wraps in multiple ones the arrow icon should always adjust to the middle of the total height of the button, if that makes sense.
I've been trying to sort this one out for hours now but for the life of me I can't figure this out.
Here's the markup:
<div class="container">
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
<button type="button" class="btn btn-block btn-foo1"><span> this is <br>button<br>one</span><i class="icon-angle-right"></i></button>
<button type="button" class="btn btn-block btn-foo2"><span>this is button two</span><i class="icon-angle-right"></i></button>
</div>
</div>
and here's a jsFiddle (updated) with what I currently have. Please note that the red background of the icons should touch the edges of the button (top/bottom/right) as opposed to what it is now.
Set both elements to display inline-block and then set the span to take up a percentage of the space. In this case 90% / 10% seems to work good.
span {
vertical-align:middle;
display:inline-block;
width:90%;
}
To remove the padding you can do this: (probably want to add a some left padding)
.btn-foo1,
.btn-foo2 {
padding:0;
border:0;
}
Change display to inline block, and remove right float:
.btn-foo1 [class^="icon-"],
.btn-foo2 [class^="icon-"],
.btn-foo1 [class*=" icon-"],
.btn-foo2 [class*=" icon-"] {
background-color: red;
display:inline-block;
vertical-align:middle;
padding:24px;
width:10%;
}
Demo:
http://jsfiddle.net/9brbD/19/
Also I would add a class to the span, instead of using span {} use myClass {}.
Related
I'm trying to center my button vertically, but isn't working:
HTML:
<div class="col-md-6 text-right">
<a class="btn btn-small btn-gray" ui-sref="login">Start Session</a>
</div>
CSS:
.btn {
vertical-align: middle;
}
Possible duplicate of How to vertical align middle a button in a dynamic div
But, I think you need to just add
display:inline-block;
to your .btn CSS.
Please see this website
How do I get the test TEST to be in the middle of the span it is contained in?
This is using Twitter Bootstrap.
I have tried loads of different ways, like css, inline styling, setting margins, etc but I cannot get the span to do what I need. It appears as though its being drawn to the exact width of it's text.
My main aim is actually to be able to bring the text Nationwide Alerts down so that it is on the same row as the buttons.
The tricky thing is that I cant give this span a hard coded width because of the page being resized
Paul
Just adding that you can now simply use css flexbox to position text inside any element including spans.
The original link is no longer working, but this should center the text horizontally regardless of the size of the element.
span { display: flex;
justify-content: center }
If you want to align vertically, use align-items: center
Put a background color on the span to see why it isn't working. Those three items are in a div with no CSS associated with it. In order for the span to be in the middle, you need the div that surrounds it to, at the very least, have width & text-align properties.
Change
<div>
<button id="btnPrevious" type="button">Previous</button>
<span style="width: 100%;text-align: center">TEST</span>
<button id="btnNext" type="button" style="float: right">Next</button>
</div>
to
<div class="centerTest">
<button id="btnPrevious" type="button">Previous</button>
<span style="width: 100%;text-align: center">TEST</span>
<button id="btnNext" type="button" style="float: right">Next</button>
</div>
with whatever name you want & use
.centerTest {
width:100%;
text-align:center;
}
Additionally, with this markup, your code as is will cause the span to center, but you would have to add float:left to your btnPrevious id. I would refrain, as much as possible, from using inline CSS unless you are designing HTML email, so just create a CSS file that you include LAST in your list of CSS files and add your edits to there.
For example, if btnPrevious is in your template's CSS file, in YOUR CSS file, just add
#btnPrevious {
float:left;
}
and you're good.
EDIT:
Sorry missed the Bootstrap part as I just did a search for TEST inside your code. Bootstrap is built with these classes, and being that those are already inside of a container, you should be able to add text-center to the blank div and it should do the trick
Change
<div>
<button id="btnPrevious" type="button">Previous</button>
<span style="width: 100%;text-align: center">TEST</span>
<button id="btnNext" type="button" style="float: right">Next</button>
</div>
to
<div class="text-center">
<button id="btnPrevious" type="button">Previous</button>
<span style="width: 100%;text-align: center">TEST</span>
<button id="btnNext" type="button" style="float: right">Next</button>
</div>
Spans are, as you suspected, drawn to the exact width of it's text. You can circumvent this by setting it's style to display: block; width: 100%;, or any width you would like. This will mess up everything in your case, since you have other elements before and after the span itself.
Therefor you'll need to in addition set it's position to absolute.
Using bootstrap 2.3.0, there is a .text-center class you can use 3
<span class="text-center">...</span>
and a pagination-centered for bootstrap 3
<span class="pagination-centered">...</span>
You can also use
margin-top: auto;
margin-bottom: auto;
Or if using TailwindCSS my-auto
I want to position the elements via input-group attribute, one of which is textarea and next ones are a couple of glyphes and button, not really important, i suppose. I want to put it in vertical order, not horizontal one which is provided by default input-group.
How can i do it in the right way?
Update: code example here. as you can see, all the elements are positioned horizontally. I want to move the glyph + button block on next line. How can I do it without regreting of input-group attribute?
HTML:
<div class="textareaField input-group">
<textarea class="form-control custom-control" rows="3"></textarea>
<div class="textareaFooter input-group-addon">
<span class="glyphicon glyphicon-picture"></span>
<span class=" btn btn-primary">Send</span>
</div>
</div>
http://jsfiddle.net/sva6nr8z/
OK, change your CSS to this:
.input-group textarea{display:block; float:none;}
.input-group .textareaFooter{display:block; float:none; clear:both; width:100%;}
.input-group .glyphicon-picture{display:block; float:none; margin:20px auto;}
.input-group .btn{display:block; float:none; clear:both; width:100%;}
Of course you'll need to adjust margins and sizes to your needs, but the important part is to give a display:block property to both textarea and .textareaFooter
See JSFiddle
I am working with bootstrap v3 and trying to center a <span class="badge">1</span> between two buttons, one of which uses the pull-right class.
The exact html looks as follows:
<button type="button" class="btn btn-success">Decient</button>
<span class="badge">10</span>
<button type="button" class="pull-right btn btn-danger">Garbage</button>
However this results in the following:
I would like to have the 10 centered but have not been successful. I have tried pagination-centered, text-centerand custom CSS to no avail. Also to provide some additional context, this is in the caption div of a thumbnail.
The following provides a basic scenario of my situation: http://jsfiddle.net/vvA78/1/
It is bootstrap, just use text-center on house-container div and pull-left on btn-success.
JSFiddle
To center vertically just add margin-top.
JSFiddle
Of course do not follow the example and don't set margin-top to the entire .badge class.
.badge is probably an inline element. If you make it an inline-block or a block element, you can center it relative to the parent.
try this:
.badge { display: inline-block; margin: 0 auto; width: 40px; }
If it does not work, I'd need a fiddle or a link.
I would like to make a simple panel with buttons that are placed horizontally and aligned to the right. Willing to align it to the left I can easily do this like that :
.button {
float:left;
background-color: #55cc66;
margin-right: 50px;
padding: 5px;
}
//......
<div id="switcher">
<h3>Style Switcher</h3>
<div class="button selected" id="switcher-default">
Default
</div>
<div class="button" id="switcher-narrow">
Narrow Column
</div>
<div class="button" id="switcher-large">
Large Print
</div>
</div>
But when I do the same with float:right it obviously aligns it to the right but in inverted order. I have also tried text-align: right, position: absolute; right:150; and position: fixed; right:150;. The last two align to the right but awkwardly overlap the 'buttons'.
How can I achieve this then ?
You can remove floats and align the container of your "buttons" to the right with the property text-align.
You don't want your heading to be aligned to the right so you've to cancel it with text-align: left;.
One problem remains: you're using non-semantic div when what you really want are buttons. You should use ... button elements (or maybe input[type"button|image|submit"]).
These ones are focusable and are made for an action taking place when clicked (with mouse, keyboard or tap).
Back to these div: they are displayed as blocks by default, you've to change for inline-block - IE8+.
Fiddle: http://jsfiddle.net/PhilippeVay/YZaRW/
Leave the class .button with float left, wrap all your buttons with another division (btn_wrapper) and add a specific width to it and float right. Just make sure that all your buttons fit inside the wrapper
.btn_wrapper{
width:300px;
float:right
}
<div id="switcher">
<h3>Style Switcher</h3>
<div class="btn_wrapper">
<div class="button selected" id="switcher-default">
Default
</div>
<div class="button" id="switcher-narrow">
Narrow Column
</div>
<div class="button" id="switcher-large">
Large Print
</div>
</div>
</div>