我感到困惑line-height的inline元素.我一直在寻找:
但我不确定我是否理解.我知道如果我使用display:inline-block转换为块,我可以使高度准确.但我试图理解的是行高内联元素的工作原理.以下是问题:
我有一个文本,font-size: 15px但如果我看到浏览器的开发人员工具,它会18px.为什么?在font-size刚刚aproximate?或者它不衡量跌宕起伏?
为什么背景色inline元素不具有相同的height比line-height?的line-height在inline元件测量线箱的空间,即空间的上方和下方的线,而不是inline元素本身.这是解释吗?
CSS:
#block-element {
font-family: 'verdana', sans-serif;
font-size: 15px;
line-height: 15px;
text-decoration: none;
color: black;
margin: 0;
background-color: grey;
}
#inline-element {
-webkit-box-sizing: border-box;
font-family: 'verdana', sans-serif;
font-size: 15px;
line-height: 15px;
text-decoration: none;
color: black;
margin: 0;
background-color: green;
}Run Code Online (Sandbox Code Playgroud)
<div id="block-element">
<a id="inline-element" href="#">
inline element font-size:15px but height:18px …Run Code Online (Sandbox Code Playgroud)是否可以在我的跨度中编辑背景颜色的高度?
HTML
<span class="highlight">Some highlighted text</span>
Run Code Online (Sandbox Code Playgroud)
CSS
.highlight{
font-family: 'Roboto', sans-serif;
font-weight: 300;
font-size: 1.5em;
background-color: #4db6ac;
line-height: 2em;
}
Run Code Online (Sandbox Code Playgroud)
我想要做的是让高光为 1.8em。我不知道如何实现它而不是太乏味(即很多 div )。