twitter-bootstrap CSS 引导程序:将图标添加到 h1

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18567098/
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-10-21 18:12:19  来源:igfitidea点击:

CSS bootstrap: add icon to h1

csstwitter-bootstrap

提问by B.B King

i add icon(Bootstrap Glyphicons) in h1but iconnot in text baseline. how to fix This?!

我在文本中添加图标(Bootstrap Glyphicons)h1icon不在文本中baseline。如何解决这个问题?!

Problem pic

问题图

Code:

代码:

<h1 ><a><i class="icon-play"></i>TEST TEXT</a></h1>

回答by Girish Thimmegowda

For Bootstrap version 3 use this.

对于 Bootstrap 版本 3,请使用它。

<h1>Hi this is heading<span class="glyphicon glyphicon-star"></span> Star</h1>

See thisjsfiddle.

看到这个jsfiddle。

your icon size will change according to size of its parent.

您的图标大小将根据其父级的大小而变化。

回答by user3460493

Im using Bootstrap v3.2 and I had the same problem.

我使用 Bootstrap v3.2,我遇到了同样的问题。

<h3><span class="glyphicon glyphicon-user"></span> User</h3>

<h3><span class="glyphicon glyphicon-user"></span> User</h3>

so I changed the display property of the glyphicon from inline-block to inline.

所以我将字形的显示属性从 inline-block 更改为 inline。

.glyphicon 
{position: relative;
top: 1px;
display: inline;
...
}

This is due the An inline element has no line break before or after it, and it tolerates HTML elements next to it but an inline-block element is placed as an inline element (on the same line as adjacent content), but it behaves as a block element.

这是因为内联元素之前或之后都没有换行符,并且它容忍旁边的 HTML 元素,但内联块元素被放置为内联元素(与相邻内容在同一行),但它的行为与块元素。

回答by Artur Fidelus

I would try:

我会尝试:

1) changing padding of i.icon-play

1) 改变 i.icon-play 的填充

2) background-position of i.icon-play

2) i.icon-play 的背景位置

3) vertical-align:center; line-height:12px; of i.icon-play

3) 垂直对齐:居中;行高:12px;i.icon-play

One of those will work, good luck ;-)

其中之一会起作用,祝你好运;-)