2

我水平有三个文本部分,每个文本都有不同的line-height. 但是,它们应该垂直对齐。

div {
  display: flex;
  align-items: center;
  width: 300px;
  background-color: skyblue;
}

p {
  font-size: 20px;
  font-weight: bold;
  margin: 0;
}

p:first-child {
  line-height: 1.33;
}

p:nth-child(2) {
  line-height: 1.65;
}
<div>
  <p>texttext1</p>
  <p>texttext2</p>
  <p>texttext3</p>
</div>

但是,当我使用align-itemsflex 时,它不起作用。还有其他解决方案吗?

4

1 回答 1

2

您正在寻找基线对齐

div {
  display: flex;
  align-items: baseline;
  width: 300px;
  background-color: skyblue;
}

p {
  font-size: 20px;
  font-weight: bold;
  margin: 0;
}

p:first-child {
  line-height: 1.33;
}

p:nth-child(2) {
  line-height: 1.65;
}
<div>
  <p>texttext1</p>
  <p>texttext2</p>
  <p>texttext3</p>
</div>

于 2021-02-24T08:19:13.577 回答