在Bulma列中居中内容

14

我有多列。每列中都包含在CSS中居中的字体awesome图标中的圆圈。现在我想将圆圈本身垂直居中于该列中。然而,它一直停留在左边,而文本本身则居中对齐。

HTML

<div class="features">
  <div class="container">
    <div class="columns is-mobile ">
      <div class="column">
        <div class="community">
          <font-awesome-icon col size="2x" :icon="['fas', 'tasks']" />
        </div>
        Features
      </div>
    </div>
  </div>
</div>

CSS

->

CSS(层叠样式表)

.features {
  background: #2a3a4c;
  height: 200px;
}

.community {
  width: 5rem;
  height: 5rem;
  background: linear-gradient(135deg, #b15757 0%, #b96868 100%);
  border-radius: 100%;
  text-align: center;
  vertical-align: middle;
  display: table-cell;
}

你是否忘记添加绘制圆形的CSS代码?尝试移除.text-align并为.community CSS添加margin:0 auto;,如果仍未居中,请为.column进行操作。 - boateng
3个回答

29

<div class="columns is-centered">...</div> 居中显示列。你需要在内部设置列的宽度才能使其正常工作。类is-narrow 只占用其所需的空间。

示例

.features {
  background: #2a3a4c;
}

.features .columns {
  height: 200px;
}

.circle {
  width: 5rem;
  height: 5rem;
  background: linear-gradient(135deg, #b15757 0%, #b96868 100%);
  border-radius: 100%;
  text-align: center;
  vertical-align: middle;
  display: table-cell;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css" rel="stylesheet" />
<div class="features">
  <div class="container">
    <div class="columns is-centered is-vcentered is-mobile">
      <div class="column is-narrow has-text-centered">
        <div class="circle">
          <font-awesome-icon col size="2x" :icon="['fas', 'tasks']" />
        </div>
        Features
      </div>
    </div>
  </div>
</div>

更多信息: Bulma列大小


7
这将使您的文本、按钮或图像居中。
在 HTML 内容中添加:
class="has-text-centered"

如果你想让文件上传输入框居中显示,可以按照以下步骤操作:
将以下内容添加到HTML代码中:
class="is-centered"

2
如果您编辑一下您的回答并展示更多的努力(例如小的解释,指明放置位置等),那就太好了。同时请参考[答案]。 - fuggerjaki61

0
你需要在.community中使用table-cell吗?它似乎没有起到任何作用。如果不需要,可以更改。
.community {
  width: 5rem;
  height: 5rem;
  background: linear-gradient(135deg, #b15757 0%, #b96868 100%);
  border-radius: 100%;
  text-align: center;
  vertical-align: middle;
  display: table-cell;
}

.community {
  width: 5rem;
  height: 5rem;
  background: linear-gradient(135deg, #b15757 0%, #b96868 100%);
  border-radius: 100%;
  text-align: center;
  margin: 0 auto;
}

并添加

.column {
  text-align: center;
}

这将使所有内容居中。

您可以在https://codepen.io/anon/pen/odQGoj上看到工作示例。

附注:您缺少</div>来关闭<div class="features">


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