html - 如何在单个 <p> 中垂直对齐 2 种不同的字体大小

标签 html css

正如标题所说,我应该如何垂直对齐:-

需要:- - | - | - -

目前垂直对齐默认为基线。

目前:_ _ | _ | _ _

HTML:

<div class="moduleResult">
    <p>You have
        <span class="moduleCard">88</span>
        out of
        <span class="moduleCard">88</span>
    correct</p>
</div>

CSS:

.moduleResult{
    width:100%;
    }

p{
    font-family:'Arial';
    font-size:20px !important;
    line-height:30px;
    text-align:center;
    }

.moduleCard{
    font-size:60px !important;
    line-height:60px;
    padding:0 4px;
    }

并且文本必须在

内居中对齐

这是 Fiddle Link

最佳答案

参见 http://jsfiddle.net/kfVGf/2/

.moduleCard{
    font-size:60px !important;
    padding:0 4px;
    display: inline-block;
    vertical-align: middle;
}

结果:

enter image description here


备注:unless you have a valid reason为此,避免使用 !important

关于html - 如何在单个 <p> 中垂直对齐 2 种不同的字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21112799/

相关文章:

javascript - 如何设置当前小时下拉列表的默认选择?

javascript - 为多个表格行重用单个 HTML 选择/下拉列表?

php - file_put_contents 在服务器上不工作

css - 线性渐变在 Chrome 中不起作用

html - 如何组织彼此嵌套的 div?

javascript - 关于创建元素的最佳方式的意见

css - 输入类型文本不在同一位置?

html - 在内容 CSS 结束后停止过度滚动

html - 输入[类型="radio"]#amountSelectionOther :checked+label+input#amountSelectionOtherField{display: inline-block;} not working in Safari

c# - 使用angular js和WebAPI上传excel文件