html - 为什么链接区域的高度比文本大很多?

标签 html css text hyperlink font-size

出于某种原因,我的文本的可点击区域的高度比设置的 div 和“a”标签大得多。如果您运行代码片段并将鼠标悬停在文本下方和下方,您会看到可点击区域比 div 和“a”标签大得多。有什么想法吗?

谢谢。

.title {

  display: flex;
  position: absolute;
  background-color: red;
  z-index: 6;
  height: 7em;
  width: 20em;
  bottom: 11.25vh;
  text-align: left;
}

.title a {

  font-size: 108px;
  line-height: 108px;
  text-decoration: none;
  color: #000;
  font-family: 'Inknut Antiqua', serif;
 }
<link href="https://fonts.googleapis.com/css?family=Inknut+Antiqua" rel="stylesheet">

<div class="title">
  <a href="javascript:;">Work</a>
</div>

最佳答案

这是因为你设置的行高实际上比默认行高小很多。 (如果您删除 line-height: 108px;,您会发现它更大)。

如果您不希望链接溢出 div 大小,您可以将 overflow: hidden 添加到 .title div。

.title {
  display: flex;
  position: absolute;
  background-color: red;
  z-index: 6;
  height: 7em;
  width: 20em;
  bottom: 11.25vh;
  text-align: left;
  
  overflow: hidden;
}

.title a {
  font-size: 108px;
  line-height: 108px;
  text-decoration: none;
  color: #000;
  font-family: 'Inknut Antiqua', serif;
}
<link href="https://fonts.googleapis.com/css?family=Inknut+Antiqua" rel="stylesheet">

<div class="title">
  <a href="http://www.google.com">Work</a>
</div>

关于html - 为什么链接区域的高度比文本大很多?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55301005/

相关文章:

html - 使用字体系列转义引用

android - 如何在 Android 中将默认应用程序字体设置为自定义字体?

php - 使用 PHP 在数据库中插入信息

javascript - 使用 Google Chrome 扩展程序抓取当前 URL 并将其设置为 HTML 框架中的文本框

html - CSS 标题图像 div

jquery - 条件悬停的问题 - jQuery

html - 我怎样才能得到一个顶级元素,比如 xpath 上一个元素的前面?

javascript - 如何将图像 (byte[]) 从 servlet 发送到 HTML 页面

c++ - 如何使用 C++ 从 Internet 读取文本

css - 将子 div 文本与父 div 对齐