如何对齐显示项目?

How to display items aligned?

这肯定是一个常见问题,但文本对齐和显示属性没有解决它,所以我一定是有什么错误。 我应该怎么做才能在同一水平线上显示 3 个项目?

.contact__information {
  vertical-align: middle;
  margin-bottom: var(--mb-1);
  padding-right: var(--mb-.75);
  align-items: right;
  text-align: center;
  display: inline-flex;
  margin-left: auto;
  margin-right: auto;
}
<section class="contact section" id="contact">
  <h2 class="section__title">Contacte</h2>
  <span class="section__subtitle">Contacte para mais informações</span>

  <div class="contact__information">
    <i class="uil uil-phone contact__icon"></i>
    <div>
      <h3 class="contact__title">Telemóvel</h3>
      <span class="contact__subtitle">999-777-666</span>
    </div>
  </div>

  <div class="contact__information">
    <i class="uil uil-envelope contact__icon"></i>
    <div>
      <h3 class="contact__title">Email</h3>
      <span class="contact__subtitle">email.com</span>
    </div>
  </div>

  <div class="contact__information">
    <i class="uil uil-map-marker contact__icon"></i>
    <div>
      <h3 class="contact__title">Morada</h3>
      <span class="contact__subtitle">Portugal</span>
    </div>
  </div>
</section>

第 1 步:定义宽度
第 2 步:找到要伸缩的父项 - #contact
第 3 步:align-items: center; 使所有元素内联(对齐)
Step 4: justify-content: space-evenly; space 将所有元素均匀分布。用完多余的 space.

#contact {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-evenly;
}
<section class="contact section" id="contact">
  <h2 class="section__title">Contacte</h2>
  <span class="section__subtitle">Contacte para mais informações</span>

  <div class="contact__information">
    <i class="uil uil-phone contact__icon"></i>
    <div>
      <h3 class="contact__title">Telemóvel</h3>
      <span class="contact__subtitle">999-777-666</span>
    </div>
  </div>

  <div class="contact__information">
    <i class="uil uil-envelope contact__icon"></i>
    <div>
      <h3 class="contact__title">Email</h3>
      <span class="contact__subtitle">email.com</span>
    </div>
  </div>

  <div class="contact__information">
    <i class="uil uil-map-marker contact__icon"></i>
    <div>
      <h3 class="contact__title">Morada</h3>
      <span class="contact__subtitle">Portugal</span>
    </div>
  </div>
</section>

感觉像是一个 flex 的机会。我添加了边框和填充,只是为了让它们一目了然,并做了一些对齐,您可以根据需要进行自定义

.contact.section {
  display: flex;
  flex-direction: row;/* or column if you want the first two on top */
  justify-content: flex-start;
  align-items: center;
}

 .contact__information,
 .contact__information div { /*probably need a class for the div */
  display: flex;
  flex-direction: row;
  justify-content: center;
  border: solid 1px lime;
padding:0.25rem;
}

.contact__information div {
  display: flex;
  flex-direction: column;/* or row if titles are in line with data */
  border: solid 1px pink;
}

.contact__title {
  border: solid blue 1px;
  padding: 0.5rem;
  align-self: center;
}

.contact__subtitle {
  border: solid #8d8dff 1px;
  padding: 0.5rem;
  align-self: center;
}
<section class="contact section" id="contact">
  <h2 class="section__title">Contacte</h2>
  <span class="section__subtitle">Contacte para mais informações</span>

  <div class="contact__information">
    <i class="uil uil-phone contact__icon"></i>
    <div>
      <h3 class="contact__title">Telemóvel</h3>
      <span class="contact__subtitle">999-777-666</span>
    </div>
  </div>

  <div class="contact__information">
    <i class="uil uil-envelope contact__icon"></i>
    <div>
      <h3 class="contact__title">Email</h3>
      <span class="contact__subtitle">email.com</span>
    </div>
  </div>

  <div class="contact__information">
    <i class="uil uil-map-marker contact__icon"></i>
    <div>
      <h3 class="contact__title">Morada</h3>
      <span class="contact__subtitle">Portugal</span>
    </div>
  </div>
</section>