0

.btnup, .btndown{
    	display:inline-block;
    	font-size:20px;
    	background:#ddd;
    	border-radius:5px;
    	cursor:pointer;
    	width:25px;
    	line-height:30px;
    	height:30px;
    	color:#999;
    	text-align:center;
    	margin:0 5px;
    }
    <link href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" rel="stylesheet"/>

    <i class="fas fa-angle-up btnup" id='btnup'></i>
    <i class="fas fa-angle-down btndown" id='btndown'></i>

如何将箭头垂直放置在中心?

4

5 回答 5

0

您可以将 FA 图标放在另一个元素中,这将是您的灰色背景元素,或者您可以添加以下 CSS 属性:

        height:25px;
  padding-top: 5px;

基本上是降低高度,但是用 padding-top 来补偿它,这迫使 FA 箭头图标向下到灰色区域的中心。

于 2018-10-19T16:18:16.487 回答
0

您可以添加顶部和底部填充(并从设置中减去这些值height):

.btnup, .btndown{
    	display:inline-block;
    	font-size:20px;
    	background:#ddd;
    	border-radius:5px;
    	cursor:pointer;
    	width:25px;
    	line-height:30px;
    	height:20px;
    	color:#999;
    	text-align:center;
    	margin:0 5px;
      padding: 5px 0 5px 0;
    }
<link href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" rel="stylesheet"/>

    <i class="fas fa-angle-up btnup" id='btnup'></i>
    <i class="fas fa-angle-down btndown" id='btndown'></i>

于 2018-10-19T16:19:41.500 回答
0

line-height被 font-awesome 覆盖,添加!important让它成为你的

.btnup,
.btndown {
  display: inline-block;
  font-size: 20px;
  background: #ddd;
  border-radius: 5px;
  cursor: pointer;
  width: 25px;
  line-height: 30px!important;
  height: 30px;
  color: #999;
  text-align: center;
  margin: 0 5px;
}
<link href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" rel="stylesheet" />

<i class="fas fa-angle-up btnup" id='btnup'></i>
<i class="fas fa-angle-down btndown" id='btndown'></i>

于 2018-10-19T16:19:45.683 回答
0

height, 和padding-top:

.btnup, .btndown{
    	display:inline-block;
    	font-size:20px;
    	background:#ddd;
    	border-radius:5px;
    	cursor:pointer;
    	width:25px;
    	line-height:10px;
      padding-top: 5px;
    	height:24px;
    	color:#999;
    	text-align:center;
    	margin:0 5px;
    }
<link href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" rel="stylesheet"/>

    <i class="fas fa-angle-up btnup" id='btnup'></i>
    <i class="fas fa-angle-down btndown" id='btndown'></i>

于 2018-10-19T16:21:39.617 回答
0

我将 a 包裹<span>在角色周围并使用flexbox将其定位在中心。

.btnup,
.btndown {
  display: flex;
  justify-content: center; /* Horizontal alignment */
  align-items: center; /* Vertical alignment */
  font-size: 20px;
  background: #ddd;
  border-radius: 5px;
  cursor: pointer;
  width: 25px;
  height: 30px;
  color: #999;
  margin: 5px;
}
<link href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" rel="stylesheet" />

<span class="btnup"><i class="fas fa-angle-up"></i></span>
<span class="btndown"><i class="fas fa-angle-down"></i></span>

于 2018-10-19T16:24:58.780 回答