Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap same width for labels

I am using Bootstrap 3. I have 5 different labels and I want to set their width to the maximum one and center the text.

enter image description here

For example every label's width should be equal to red one.

<span class="label label-md label-danger">Merkez Tarafından Reddedildi</span>
like image 211
fatiherdem Avatar asked Jun 16 '16 02:06

fatiherdem


People also ask

What are Bootstrap labels?

The bootstrap labels are layout components that provide tips and additional small information on the main content. The bootstrap labels are highlight or markup the content with minimum space and information. The labels are the adjustable component which is modified as per tag, elements, and content size.

How to add width to the <label> tag in HTML?

Since it is an inline element, using the width property alone won’t have any effect. But there are some methods to add width to the <label> tag. In this tutorial, we’ll demonstrate some examples of controlling the width of the <label> tag by using the display property set to “block” in combination with the width property.

Why can't I center the text in a bootstrap label?

It's because .label is an inline element, you must set as inline-block and then set a min-width The bootstrap already centers the text in .label so no need to worry about that. Note: I've used !important just for the demo, avoid at all cost using in your code.

How to set input size in Bootstrap?

Bootstrap Input Sizing 1 Input Sizing in Forms. Set the heights of input elements using classes like .input-lg and .input-sm. Set the widths of elements using grid column classes like .col-lg-* and .col-sm-*. 2 Height Sizing 3 Column Sizing 4 Help Text


Video Answer


2 Answers

It's because .label is an inline element, you must set as inline-block and then set a min-width

The bootstrap already centers the text in .label so no need to worry about that.

Note: I've used !important just for the demo, avoid at all cost using in your code.

.label {
  min-width: 200px !important;
  display: inline-block !important
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<span class="label label-md label-danger">Merkez Tarafından Reddedildi</span>
<hr />
<span class="label label-md label-info">Merkez</span>
<hr />
<span class="label label-md label-warning">Merkez Tarafından </span>
<hr />
<span class="label label-md label-success">Tarafından Reddedildi</span>
<hr />
<span class="label label-md label-default">Tarafından</span>
<hr />
<span class="label label-md label-primary">Tarafından lipsum</span>
like image 114
dippas Avatar answered Nov 03 '22 02:11

dippas


Can't think of the exact answer you want, but maybe this will be even better for you.

.label {
    width:200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.label:hover {
    white-space: normal;
}
like image 39
Frutis Avatar answered Nov 03 '22 02:11

Frutis