Html 将 div 内的字形居中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21460610/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 00:46:15  来源:igfitidea点击:

Centering a glyphicon inside a div

csstwitter-bootstraphtml

提问by Sarvagnya

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

这是小提琴:http: //jsfiddle.net/sarvagnia1/BLAXF/

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

我需要在垂直和水平方向的 div 内居中一个字形。

Here's the code: HTML:

这是代码:HTML:

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

CSS:

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;

}

}

回答by dgnin

You need the add this:

你需要添加这个:

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

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

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