1

I have an H1 element immediately after an anchor tag. For design purposes the line-height of the H1 element is set to '0.9'.

This makes the H1's computed height shorter, but the actual Text element inside the H1 seems to be overflowing and partially covering up the anchor tag, making it hard to click. (Tested in Chrome and Safari, the bottom two thirds of the link is un-clickable)

I've added borders to both elements here to show the boundaries, and selected part of the title in my browser so you can see how the overflowing text is covering the link:

enter image description here

I can fix this by setting overflow: hidden on the H1, but I'm wondering if there are any cleaner solutions.

a {
  border: 1px solid blue;
}

h1 {
  color: magenta;
  font-size: 120px;
  margin-top: 0px;
  line-height: 0.9;
  border: 1px solid magenta;
}
<a href="www.google.com">Link Covered By </a>
<h1>Title</h1>

See the problem in action here: CodePen

disinfor
  • 10,865
  • 2
  • 33
  • 44
Arian Khosravi
  • 457
  • 3
  • 11

1 Answers1

1

I'm not too sure what you mean by "cleaner", but one trick you can use instead of hiding the overflow (which isn't ideal, because it might cut off diacritics) is to lower the h1's z-index, so that it is drawn behind the a rather than in front of it.

a {
  border: 1px solid blue;
}

h1 {
  color: magenta;
  font-size: 120px;
  margin-top: 0px;
  line-height: 0.9;
  border: 1px solid magenta;
  position:relative; z-index:-1; /* there you go. */
}
<a href="www.google.com">Link Covered By </a>
<h1>Title</h1>
Mr Lister
  • 45,515
  • 15
  • 108
  • 150