I am using Bootstrap 3. I have 5 different label
s and I want to set their width
to the maximum one and center the text.
For example every label
's width
should be equal to red one.
<span class="label label-md label-danger">Merkez Tarafından Reddedildi</span>
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.
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.
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.
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
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>
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With