0

我有以下 HTML 类:

<div class="image-changing">
    <ion-icon name="ios-arrow-back" class="arrow-back"></ion-icon>
    <ion-icon name="ios-arrow-back" class="arrow-back"></ion-icon>
    <span class="circle"></span>
    <ion-icon name="ios-arrow-forward" class="arrow-forward"></ion-icon>
    <ion-icon name="ios-arrow-forward" class="arrow-forward"></ion-icon>
</div>

以及以下 CSS:

.arrow-back {
    position: relative + 100px;
    // margin-right: auto;
    // align: center;       
    float:left;
    font-size:60px;
    color:white;
}

.arrow-forward {
    left: 20%;
    float:right;
    font-size:60px;
    color:white;
    position: calc(100% - 1 em);
}

.image-changing {
    width: 80%; margin: 0 auto;
}

有谁知道如何将五个组件居中对齐?

4

2 回答 2

1

尝试添加以下属性:

.image-changing { text-align: center;} 
.arrow-back, .circle, .arrow-forward  { display: inline-block; }
于 2017-07-13T09:23:06.883 回答
0

这应该可以解决问题。使用元素居中的 flexbox。

.arrow-back {
  font-size: 60px;
  color: white;
}

.arrow-forward {
  font-size: 60px;
  color: white;
}

.image-changing {
  width: 80%;
  margin: 0 auto;
  display: flex;
  justify-content: center;
}
<div class="image-changing">
  <ion-icon name="ios-arrow-back" class="arrow-back"></ion-icon>
  <ion-icon name="ios-arrow-back" class="arrow-back"></ion-icon>
  <span class="circle"></span>
  <ion-icon name="ios-arrow-forward" class="arrow-forward"></ion-icon>
  <ion-icon name="ios-arrow-forward" class="arrow-forward"></ion-icon>
</div>

于 2017-07-13T08:52:03.060 回答