【问题标题】:Circle and text alignment CSS3圆形和文本对齐 CSS3
【发布时间】:2016-11-24 22:32:58
【问题描述】:

我想将圆形下方的文本对齐,完全在中间。

这里是一个 sn-p(我简化了所有内容,因为圆形和文本是由 angular 处理的,所以它们是我的屏幕截图和 sn-p 之间的一些区别)

.circle2 {
  border-radius: 50%;
  width: 18px;
  height: 18px;
  background: RoyalBlue;
  display: inline-block;
  z-index: 2;
}
.wrapper2 {
  display:flex;
  width:100%;
  justify-content: space-around;
  position:relative;

}
.wrapper2:after {
  position:absolute;
  content:'';
  display:block;
  width: 100%;
  top:7px;
  height: 3px;
  background: RoyalBlue;

}
.advanced2 {
  width: 18px;
  height: 18px;
}
.circleActive2 {
  border-radius: 50%;
  width: 25px;
  height: 25px;
  background: RoyalBlue;
  display: inline-block;
}
<div class="w3-container">
  <div class="wrapper2">
    <span>
    <span><div class="circle2 advanced2" ></div>test</span>
    <span><div class="circle2 advanced2 circleActive2" ></div>test2</span>
    <span><div class="circle2 advanced2" ></div>test3</span>
        <span><div class="circle2 advanced2" ></div>test4</span>
        <span><div class="circle2 advanced2" ></div>test5</span>
      </span>
 </div>
</div>

【问题讨论】:

    标签: css alignment geometry text-align


    【解决方案1】:

    .circles {
      display: flex;
      width: 100%;
      justify-content: space-around;
      position: relative;
    }
    
    .circles:after {
      position: absolute;
      content: '';
      display: block;
      width: 100%;
      top: 7px;
      height: 3px;
      background: RoyalBlue;
    }
    
    .circles > div {
      display: flex;
      flex-direction: column;
      align-items: center;  
    }
    
    .circle {
      border-radius: 50%;
      width: 17px;
      height: 17px;
      background: RoyalBlue;
    }
    
    .circle.active {
      width: 25px;
      height: 25px;
      margin-top: -4px;
    }
    <div class="circles">
      <div><span class="circle"></span>test</div>
      <div><span class="circle active"></span>test2</div>
      <div><span class="circle"></span>test3</div>
      <div><span class="circle"></span>test4</div>
      <div><span class="circle"></span>test5</div>
    </div>

    【讨论】:

    • 所以如果我理解得很好,circle > div 选择所有
      元素,其中父元素是圆形元素并且 felx-direction: column + align-items: center align 完全符合预期?
    • The > selector flex-direction: column; align-items: center; 将元素放在自己的行上并垂直对齐
    【解决方案2】:

    我想它应该像下面这样工作: 您可以将“.wrapper2”的最大宽度和边距更改为没有问题。

    .wrapper2 {
    	width:100%;
    	position:relative;
    	text-align:center;
    	max-width:600px;
    	margin:50px auto;
    }
    
    .wrapper2 > span {
    	position:relative;
    	width:100%;
    	-webkit-flex-flow: row wrap;
    	-moz-flex-flow: row wrap;
    	flex-flow: row wrap;
    	-webkit-justify-content: space-around;
    	-moz-justify-content: space-around;
    	justify-content: space-around;
    	display: -webkit-flex;
    	display: -moz-flex;
    	display: flex;
    }
    
    .wrapper2:after {
    	content:"";
    	position:absolute;
    	display:block;
    	width: 100%;
    	top:7px;
    	left:0;
    	height: 4px;
    	background: RoyalBlue;
    }
    
    .advanced2 {
    	width: 18px;
    	height: 18px;
    	display:block;
    	position:relative;
    	margin: 0 auto 5px;
    	border-radius: 50%;
    	width: 18px;
    	height: 18px;
    	background: RoyalBlue;
    	z-index: 2;
    }
    
    .circleActive2 {
    	margin: -4px auto 1px;
    	width: 26px;
    	height: 26px;
    }
    
    .advanced2 + i {
    	font-style:normal;
    	display:block;
    }
    <div class="wrapper2">
      <span>
        <span><div class="advanced2"></div><i>test</i></span>
        <span><div class="advanced2 circleActive2"></div><i>test2</i></span>
        <span><div class="advanced2"></div><i>test3</i></span>
        <span><div class="advanced2"></div><i>test4</i></span>
        <span><div class="advanced2"></div><i>test5</i></span>
       </span>
    </div>

    希望我能帮上忙!

    【讨论】:

      猜你喜欢
      相关资源
      最近更新 更多
      热门标签