两个圆圈并排(响应)

时间:2018-02-13 16:26:18

标签: html css twitter-bootstrap

我试图让两个圆圈并排显示(响应)。

HTML

<div class="col-sm-12">
  <div class="circle col-sm-6">450 reviews</div>
  <div class="circle col-sm-6">4.2 million readers</div>
</div>

CSS

.circle{
  width:100px;
  height:100px;
  border-radius:100px;
  font-size:20px;
  color:#fef;
  line-height:100px;
  text-align:center;
  background:#000
}

但是有了这个CSS,圈子就在彼此之下。

在圈子里面,也可以在一行中加上“450”并在其下面“评论”。同样地,“420万”在一行中,“读者”在另一行中?

Live Demo

3 个答案:

答案 0 :(得分:0)

试试这个:

  .circle
   {
    float:left; //to put side by side
    width:100px;
    height:100px;
    border-radius:100px;
    font-size:20px;
    color:#fef;
    line-height:100px;
    text-align:center;
    background:#000
  }

答案 1 :(得分:0)

好的,我会让你的项目内联flex以使它们在同一行(并使内容居中),并删除你的boostrap类:

.circle {
  display: inline-flex;         /* use this so theat items are on same line */
                                
  justify-content: center;      /* by using above, you can vertical and horizontal align without the need for a stupid line-height hack*/
  align-items: center;
  text-align: center;
  
  margin-right: 10px;
  width: 150px;
  height: 150px;
  font-size: 20px;
  border-radius: 50%;
  color: #fef;
  background: #000
}
<div class="col-sm-12">
  <div class="circle">450
    <br> reviews </div>
  <div class="circle">4.2 million
    <br> readers </div>
</div>

答案 2 :(得分:0)

您需要使用rowcontainer-fluid来更改标记...

此外,您需要将内部文本包装到<p>标记中,并使用transform:translate(-50%, -50%)position:absolute组合来使文本居中

Stack Snippet

.circle {
  float: left;
  margin-right: 10px;
  width: 150px;
  height: 150px;
  border-radius: 150px;
  font-size: 16px;
  color: #fef;
  text-align: center;
  background: #000;
  position: relative;
}

.circle p {
  margin: 0;
  transform: translate(-50%, -50%);
  top: 50%;
  left: 50%;
  position: absolute;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="conatiner-fluid">
  <div class="row">
    <div class="col-xs-12">
      <div class="circle">
        <p>450
          <br> reviews</p>
      </div>
      <div class="circle">
        <p>4.2 million
          <br> readers</p>
      </div>
    </div>
  </div>
</div>