【问题标题】:Trying to create circle with Vertically-Centered Text and Under circle text exist [duplicate]尝试使用垂直居中的文本创建圆圈并且存在圆圈下的文本[重复]
【发布时间】:2020-04-22 14:44:26
【问题描述】:

尝试使用 Flexbox 创建具有垂直居中文本和下圆圈文本的圆圈,

但不能这样做,

  • 我必须完全按照下面给出的图片进行操作

我正在分享我的代码

https://stackblitz.com/edit/angular-rzyhff?file=src%2Fapp%2Fapp.component.html

.flex-container {
  display: flex;
  background-color: #DDD8D8;
    justify-content: center;
}

.flex-container > div {
  background-color: #f1f1f1;
  height: 25px;
  width: 25px;
  padding: 29px;
  margin: 17px;
  border-radius: 50%
}
<div class="flex-container">
    <div style='background-color: #30D829;'>1</div>
    <div style='background-color: #72A7E5;'>2</div>
    <div style='background-color: #F0CD09;'>3</div>  
    <div style='background-color: #A552ED;'>2</div>
    <div style='background-color: #EF4E92;'>3</div>  
  </div> 

【问题讨论】:

    标签: html css flexbox


    【解决方案1】:

    您只需将display: flex;align-items: center; justify-content: center; 添加到您的子div。

    由于 flexbox 是一个完整的模块而不是单个属性,它涉及到很多东西,包括它的整个属性集。其中一些是要设置在容器上(父元素,称为“flex container”),而其他是要设置在子级(称为“flex items”)上。

    您可以通过以下链接了解更多关于 flexbox 布局的信息。

    https://www.w3schools.com/css/css3_flexbox.asp

    .flex-container {
      display: flex;
      background-color: #DDD8D8;
      justify-content: center; 
      padding-bottom: 45px;
    }
    .flex-container > div {
      background-color: #f1f1f1;
      height: 25px;
      width: 25px;
      padding: 29px;
      margin: 17px;
      line-height: 25px;
      border-radius: 50%;
      display: flex;
      color: white;
      flex-wrap: wrap;
      align-items: center;
      justify-content: center;
    }
    .flex-container > div p {
      display: block;
      margin-top: 40px;
      color: #000;
      line-height: normal;
      text-align: center;
    }
    <div class="flex-container">
      <div style='background-color: #30D829;'>
        <span>1</span>
        <p>Active</p>
      </div>
      <div style='background-color: #72A7E5;'>
        <span>2</span>
        <p>Pending Approval</p>
      </div>
      <div style='background-color: #F0CD09;'>
        <span>3</span>
        <p>Pending Approval</p>
      </div>  
      <div style='background-color: #A552ED;'>
        <span>4</span>
        <p>Pending Approval</p>
      </div>
      <div style='background-color: #EF4E92;'>
        <span>5</span>
        <p>Pending Approval</p>
      </div>  
    </div>

    我希望这会有所帮助。

    【讨论】:

    • 我必须在圆圈下写文本的问题,例如。活动、待批等..您可以在我发布的图片中看到
    【解决方案2】:

    将 text-align:center 和 line-height 与子类的高度相同:

       <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>Document</title>
      <style>
      .flex-container {
        display: flex;
        background-color: #DDD8D8;
        justify-content: center;
        height: 160px;
      }
      .flex-container > div{
        background-color: #f1f1f1;
        height: 25px;
        width: 25px;
        line-height: 25px;
        text-align: center;
        padding: 29px;
        margin: 17px;
        border-radius: 50%;
      }
      p {
       display: flex;
       justify-content: center;
       margin-top: 35px;
       line-height: 18px;
       font-weight: 600;
     }
    </style>
    </head>
    <body>
      <div class="flex-container">
        <div style='background-color: #30D829;'>1 <p>Active</p></div>
        <div style='background-color: #72A7E5;'>2 <p>pending Approvals</p></div>
        <div style='background-color: #F0CD09;'>3 <p>pending Approvals</p></div>
        <div style='background-color: #A552ED;'>2 <p>pending Approvals</p></div>
        <div style='background-color: #EF4E92;'>3 <p>pending Approvals</p></div>
      </div>
    </body>
    </html>

    【讨论】:

    • 我必须在圆圈下写文本的问题,例如。活动、待批等..您可以在我发布的图片中看到
    猜你喜欢
    • 2015-11-30
    • 1970-01-01
    • 1970-01-01
    • 2016-07-01
    • 2016-05-31
    • 2022-07-15
    • 1970-01-01
    • 2015-11-05
    • 2023-03-10
    相关资源
    最近更新 更多