我想知道将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>
将
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;
}