0

我想知道将p元素中的文本对齐为垂直居中。

这是我的代码:

p.task{font-family: Arial,Helvetica Neue,Helvetica,sans-serif; font-weight: 700;  display: table-cell; vertical-align: middle;}
span.label {float: left; width: 60px; color: red}
span.text {float: left; width: calc(100% - 60px);}
<link href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/katex.css" rel="stylesheet"/>

<p class="task">
  <span class="label">2</span>
  <span class="text">Vypočtěte jednu třetinu z \( 3^{3k+3} \) , kde \( k \space \epsilon \space Z \).</span>
</p>

<script src="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/katex.js"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/contrib/auto-render.min.js" 
    onload="renderMathInElement(document.body);"></script>

4

1 回答 1

1

vertical-center类添加到p

.vertical-center {
    display: flex;
    align-items: center;
}

或者可以在任务类中添加上述 2 个样式规则。

.task {
    font-family: Arial,Helvetica Neue,Helvetica,sans-serif; 
    font-weight: 700;
    display: flex;
    align-items: center;
}
于 2019-02-10T18:08:12.523 回答