【问题标题】:Icon font and label text in separate lines不同行中的图标字体和标签文本
【发布时间】:2017-03-03 09:04:39
【问题描述】:

我有一个标签标题和一个图标,我尝试使用 flex 在垂直和水平方向居中。标签工作正常;唯一的问题是图标。

我希望图标位于标签标题上方而不是旁边。我试过用<br>,还是不行。

下面的代码sn-p和JSFiddle link

.radio input[type="radio"] + label {
  align-items: center;
  background-color: white;
  border: 1px solid #cccbc8;
  display: flex;
  height: 150px;
  justify-content: center;
  position: relative;
  width: 150px;
}
<div class="radio-inline radio input_type">
  <input id="Best offers" name="54_answer" type="radio" next-question-id="" value="Best offers">
  <label for="Best offers">Best offers <br> <i class="fa fa-star-o"></i></label>
</div>

【问题讨论】:

  • 我不明白你想要什么。 this 你得到了什么?你把它放在哪里?
  • 这里一样,字体很棒的图标不见了
  • 尝试在 span 元素中添加图标,看看会发生什么
  • 您必须使用fontawesome.io 才能使用图标

标签: html css flexbox


【解决方案1】:

是的,所以通过使用display: flex,您的元素将内联显示。 flex 有一个选项可以指定我们是要以一行还是以列样式显示我们的元素(默认情况下是行)。在您的情况下,您想要按列,这就是为什么将其添加到您的班级

flex-direction: column-reverse

这会将您的图标放在文本上方。

【讨论】:

  • "inline" 的真正含义与您在这里所暗示的完全不同——您说的是水平对齐。
【解决方案2】:

您的 CSS 规则中的选择器完全错误,flex-direction 必须是 column。尝试如下:

.radio-inline.radio.input_type {
  align-items: center;
  background-color: white;
  border: 1px solid #cccbc8;
  display: flex;
  flex-direction: column;
  height: 150px;
  justify-content: center;
  position: relative;
  width: 150px;
}
.radio-inline label {
  margin-top: 10px;
}
<div class="radio-inline radio input_type">
  <input id="Best offers" name="54_answer" type="radio" next-question-id="" value="Best offers">
  <label for="Best offers">Best offers <br> <i class="fa fa-star-o"></i></label>
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-27
    • 1970-01-01
    • 2014-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多