Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vertically center span (bootstrap label) together with other elements

I'd like to use the inline labels of the bootstrap css framework:

<span class="label">Default</span>

Unfortunately these labels are not vertically centered when used together with other elements.

<p>
  <span class="label"><a href="#">test</a></span>This is a test heading.
</p>

Please see the full code for a visual example: http://jsfiddle.net/kvPpm/

I am aware of the line-height and absolute/relative positioning workarounds but was not able to apply them correctly.

How can I vertically center these labels?

like image 383
fanti Avatar asked Feb 16 '12 20:02

fanti


People also ask

How do you center elements vertically in bootstrap?

In Bootstrap 5, if we want to vertically align an <div> element in the center, we can do this by applying the class align-items-center on the containing element of that div.

How do you center a span element vertically?

The CSS just sizes the div, vertically center aligns the span by setting the div's line-height equal to its height, and makes the span an inline-block with vertical-align: middle. Then it sets the line-height back to normal for the span, so its contents will flow naturally inside the block.

How do I make div center vertically and horizontally bootstrap 5?

To center div both vertically and horizontally use flexbox utilities. See the examples. Add d-flex align-items-center justify-content-center classes to the parent element to center its content vertically and horizontally.


2 Answers

Since <span> is an inline element by default you can just do:

span { vertical-align: middle|top|bottom; }

And it should work. http://jsfiddle.net/kvPpm/1/

But then <a> inside <span> is not semantically correct. You can just use <a> and style it display: inline.

http://jsfiddle.net/kvPpm/3/

like image 62
elclanrs Avatar answered Sep 20 '22 12:09

elclanrs


.label { vertical-align: top; } 

This worked for me when I wanted it to be aligned properly in a ul

like image 30
Adam K Dean Avatar answered Sep 20 '22 12:09

Adam K Dean