html - Flex box,内容右对齐

标签 html css flexbox

我需要在其容器 div op__list__operatorop__add__icon 的右侧对齐。 我试过 text-align 但不起作用。

知道怎么解决吗?非常感谢大家!

.op {
  width: 250px;
  height: 355px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  z-index: 1;
  background-color: rgba(255, 0, 0, 0.5);
}

.op__add {
  background-color: yellow;
}

.op__add__icon {
  width: 70px;
  height: 70px;
  background-color: #446ac2;
  border-radius: 35px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  box-shadow: 0 3px 15px 0 rgba(0, 0, 0, 0.75);
}

.op__add__icon:hover {
  filter: brightness(110%);
}

.op__add__icon .material-icons.md-38 {
  font-size: 38px;
}

.op__list {}

.op__list__operator {
  display: flex;
  justify-content: space-between;
  background-color: orange;
  width: 173px;
}

.op__list__operator__label {
  width: 123px;
  height: 32px;
  background-color: #000000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.op__list__operator__label__value {
  text-transform: uppercase;
  color: #ffffff;
  font-size: 13px;
}

.op__list__operator__icon {}
<div class="op">
  <div class="op__list">
    <div class="op__list__operator">
      <div class="op__list__operator__label">
        <div class="op__list__operator__label__value">
          hello
        </div>

      </div>
      <div class="op__list__operator__icon">
        <i>avatar</i>
      </div>
    </div>
  </div>
  <div class="op__add">
    <div class="op__add__icon">
      <i>x</i>
    </div>
  </div>
</div>

最佳答案

使用inline-flex代替.op__list__operator,并将text-align:right设置为.op__list

.op__list {
  text-align:right
}

.op__list__operator {
  display: inline-flex;
  justify-content: space-between;
  background-color: orange;
  width: 173px;
}

.op {
  width: 250px;
  height: 355px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  z-index: 1;
  background-color: rgba(255, 0, 0, 0.5);
}

.op__add {
  background-color: yellow;
}

.op__add__icon {
  width: 70px;
  height: 70px;
  background-color: #446ac2;
  border-radius: 35px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  box-shadow: 0 3px 15px 0 rgba(0, 0, 0, 0.75);
}

.op__add__icon:hover {
  filter: brightness(110%);
}

.op__add__icon .material-icons.md-38 {
  font-size: 38px;
}

.op__list {
  text-align:right
}

.op__list__operator {
  display: inline-flex;
  justify-content: space-between;
  background-color: orange;
  width: 173px;
}

.op__list__operator__label {
  width: 123px;
  height: 32px;
  background-color: #000000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.op__list__operator__label__value {
  text-transform: uppercase;
  color: #ffffff;
  font-size: 13px;
}

.op__list__operator__icon {}
<div class="op">
  <div class="op__list">
    <div class="op__list__operator">
      <div class="op__list__operator__label">
        <div class="op__list__operator__label__value">
          hello
        </div>

      </div>
      <div class="op__list__operator__icon">
        <i>avatar</i>
      </div>
    </div>
  </div>
  <div class="op__add">
    <div class="op__add__icon">
      <i>x</i>
    </div>
  </div>
</div>

关于html - Flex box,内容右对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45630892/

相关文章:

css - JavaFX:您可以使用 CSS 定义 TextField 的最大宽度/高度吗?

jquery - 如何使 flexbox 布局的一部分变得粘性?

html - 当 div 具有部分透明背景时,有没有办法让 div 的文本淡化

javascript - 标题的固定高度和变化宽度(HTML 表格)

javascript - 要显示的 Youtube 播放器选项

css - 如何在淡入淡出过渡之前使轮播图像稍微缩放

javascript - 如何添加和删除双列表框中的所有选项?

html - 在 float (或内联 block )父级内水平均匀分布 div

html - 当宽度>100% 时,如何在 flexbox 中居中放置一个 div?

html - "Pull center"in Bootstrap : A -D- B -E- C columns collapsing to A-B-C//D-E, 如何在D和E之间获取B?