尝试创建一个带有垂直居中文本和在圆形下方的文本的圆形

3

尝试使用Flexbox创建垂直居中文本和下方圆形文本,

但是无法实现,

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

I have to do exactly like Image given Below

我分享了我的代码

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> 

2个回答

5
给子类添加 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>


问题是我必须在圆形下面写文本,例如“活动的”,“待批准的”等等。您可以在我发布的图片中看到。 - Anurag Ranjan

3
你只需要在子div中添加display: flex;align-items: center; justify-content: center;即可。 由于flexbox是一个完整的模块而不是单个属性,它包括许多内容,包括其整套属性。其中一些属性应该设置在容器(父元素,称为“flex容器”)上,而其他属性则应该设置在子元素(称为“flex项目”)上。 您可以通过下面的链接了解更多有关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>

我希望这可以帮到您。

问题是我必须在圆圈下面写文本,例如“活动的”,“待批准的”等等。您可以在我发布的图片中看到。 - Anurag Ranjan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接