如何将FontAwesome图标置于方块内?
此时,除了facebook图标外,所有图标都或多或少地放在右侧,尤其是soundcloude图标。
我一直在使用" w3schools - 社交媒体按钮"例如,当正方形按比例缩小时,似乎会出现此问题。
.fa {
padding: 15px;
text-align: center;
vertical-align:middle;
text-decoration: none;
margin: 15px 3px;
border-radius: 50%;
width: 7.5px;
height: 7.5px;
font-size: 15px;
line-height: 7.5px !important;
}
.fa {
background: #F0F0F0;
color: #282828;
}
.fa-facebook:hover {
background: #3B5998;
color: white;
line-height: inherit;
}
.fa-youtube:hover {
background: #bb0000;
color: white;
line-height: inherit;
}
.fa-instagram:hover {
background: #125688;
color: white;
line-height: inherit;
}
.fa-soundcloud:hover {
background: #ff5500;
color: white;
line-height: inherit;
}

<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<a href="#" class="fa fa-facebook"></a>
<a href="#" class="fa fa-youtube"></a>
<a href="#" class="fa fa-instagram"></a>
<a href="#" class="fa fa-soundcloud"></a>
&#13;
答案 0 :(得分:3)
杀死不必要的填充(不留下图标的空间)并让元素的width
/ height
/ line-height
确定其布局。
在:
padding: 15px;
width: 7.5px;
height: 7.5px;
line-height: 7.5px !important;
后:
width: 30px;
height: 30px;
line-height: 30px !important;
您还可以从:hover
状态中删除一些冗余样式。
实例:
.fa {
text-align: center;
vertical-align: middle;
text-decoration: none;
margin: 15px 3px;
border-radius: 50%;
width: 30px;
height: 30px;
font-size: 15px;
line-height: 30px !important;
}
.fa {
background: #F0F0F0;
color: #282828;
}
.fa:hover {
color: #fff;
}
.fa-facebook:hover {
background: #3B5998;
}
.fa-youtube:hover {
background: #bb0000;
}
.fa-instagram:hover {
background: #125688;
}
.fa-soundcloud:hover {
background: #ff5500;
}
&#13;
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<a href="#" class="fa fa-facebook"></a>
<a href="#" class="fa fa-youtube"></a>
<a href="#" class="fa fa-instagram"></a>
<a href="#" class="fa fa-soundcloud"></a>
&#13;
答案 1 :(得分:0)
是,您可以将图标居中。
我添加了我的代码段。
建议,请不要为课程fa
写css。请为同一个
.decoration-fa{
padding:15px;
text-align:center;
text-decoration: none;
border-radius: 50%;
background: #F0F0F0;
color: #282828;
width:18px;
height:18px;
}
.decoration-fa.fa-facebook:hover {
background: #3B5998;
color: white;
}
.decoration-fa.fa-youtube:hover {
background: #bb0000;
color: white;
}
.decoration-fa.fa-instagram:hover {
background: #125688;
color: white;
}
.fa-soundcloud:hover {
background: #ff5500;
color: white;
}
&#13;
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<a href="#" class="fa fa-facebook decoration-fa"></a>
<a href="#" class="fa fa-youtube decoration-fa"></a>
<a href="#" class="fa fa-instagram decoration-fa"></a>
<a href="#" class="fa fa-soundcloud decoration-fa"></a>
&#13;