Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Centering a glyphicon inside a div

Here's the fiddle: http://jsfiddle.net/sarvagnya1/BLAXF/

I need to center a glyphicon inside a div both vertically and horizontally.

Here's the code: HTML:

<div class="container">
<div class="item">
    <span class="glyphicon glyphicon-text-width"></span>
</div>

CSS:

.container{
width: 600px;
margin: 0 auto;
border: 1px solid #000;

}

.item{
width: 150px;
height: 150px;
border: 1px solid #ddd;

}

.item span{
font-size: large;

}

like image 356
Sarvagnya Avatar asked Jan 30 '14 15:01

Sarvagnya


People also ask

How do I move my icons to the center?

Drag the vertical line next to the icons to move the icons to an ideal center position on your taskbar. Once icons are centered, right-click on the taskbar and select Lock the taskbar from the pop-up menu.

How do I center an icon in HTML?

The most preferred way to center Font Awesome Icons is to assign a center class to each <i> tag. Setting width to 100%, let's each icon cover 100% area horizontally. Also text-align then centers the icon accordingly to the width being used. Example 1: Adding a custom class in all <i> tag.


1 Answers

You need the add this:

.item{
    ...
    text-align: center;
}
.item span{
    ...
    line-height: 150px;
}

http://jsfiddle.net/BLAXF/1/

like image 184
dgnin Avatar answered Oct 13 '22 00:10

dgnin