4

When there is a list of links and you apply the 'column-count' CSS property to the container and you hover slightly below the last link in the first column (link 3 in the example) then the hover state will apply to the first link in the second column instead.

.two-column {
  column-count: 2;
  column-gap: 2.5rem;
  width: 200px;
}

a:hover {
  text-decoration: none;
}
<ul class="two-column">
                          
  <li>
    <a href="#">
      Link 1
    </a>
  </li>

  <li>
    <a href="#">
      Link 2
    </a>
  </li>

  <li>
    <a href="#">
      Link 3
    </a>
  </li>

  <li>
    <a href="#">
      Link 4
    </a>
  </li>

  <li>
    <a href="#">
      Link 5
    </a>
  </li>

</ul>

I have also made a pen of the issue here codepen.

Edit: You can see it happening in this GIF. Tested in Chrome 92 on macOS Big Sur, this doesn't seem to be a problem on Windows. enter image description here

TylerH
  • 20,799
  • 66
  • 75
  • 101
tay
  • 138
  • 2
  • 13
  • I'm unable reproduce it in Edge 92 – vanowm Aug 12 '21 at 15:17
  • Looks fine in latest Chrome. – Rob Moll Aug 12 '21 at 15:19
  • Looks Fine in firefox 78 – Ravi Aug 12 '21 at 15:23
  • It's subtle but there in the Codepen in Chrome 92 but you have to hover *really* close. Frankly it's so small as to be **almost** irrelevant. Perhaps something with breaking? – Paulie_D Aug 12 '21 at 15:24
  • No repro in either Firefox 91 or Chrome 92 in the CodePen or in the Stack Snippet, even when zoomed in 500% to try and get as close as possible. – TylerH Aug 12 '21 at 15:28
  • What OS and OS version are you using? Can you reproduce in a private browsing session, or after you shut your computer down and start it back up again with a new session of Chrome? I suspect caching or first-time load only. I still can't reproduce this on Chrome-latest (92.x) in Windows 10 (or any other browser). – TylerH Aug 16 '21 at 15:34
  • 2
    I think you're right @TylerH, I just tried on Windows myself and couldn't recreate the issue so it looks like this is a macOS specific issue. I can reproduce in Chrome 92.x and on macOS Big Sur. – tay Aug 17 '21 at 13:28

5 Answers5

1

You have to increase the vertical gap between each list item. Here you can apply a line-height: 20px; to the li tag.

PS: Value is not specific.

1

I found that Windows users can see the issue when tabbing to focus on each link.
Seems like giving the anchor tags a display of inline-block actually makes it better. Hopefully this will solve the issue on macOS aswell.

.two-column {
  column-count: 2;
  column-gap: 2.5rem;
  width: 200px;
}

a {
 display: inline-block;
}

a:hover {
  text-decoration: none;
}
<ul class="two-column">
                          
  <li>
    <a href="#">
      Link 1
    </a>
  </li>

  <li>
    <a href="#">
      Link 2
    </a>
  </li>

  <li>
    <a href="#">
      Link 3
    </a>
  </li>

  <li>
    <a href="#">
      Link 4
    </a>
  </li>

  <li>
    <a href="#">
      Link 5
    </a>
  </li>

</ul>
Art
  • 431
  • 4
  • 12
0

This worked in Chrome on macOS.

a:hover::after {
  content: ' ';
}
Julaine
  • 15
  • 1
  • 4
0

Problem

The problem you have is the gap between your list-items. If items are in same column, then it is not a problem at all. But in your case, the next list-item lies in the second column.

My Understanding

You have created only columns without rows. The content in the column can be anything like text, image, link, etc. which is divided into two columns(in your case) by the browser. As, there are no rows then you cannot apply properties like row-gap which only works with the grids.


Solution

  1. Change the existing structure by - either using CSS grid or flex.
  2. With the existing structure - make a gap between list-items. Possibly by using either of the following CSS property on list items
  • line-height
  • margin
  • padding
0

As a workaround for this bug, you can add a 1px tall element to cover the bottom of the column to prevent hover events:

.two-column {
  column-count: 2;
  column-gap: 2.5rem;
  width: 200px;
  position: relative;
}

/* Hack for Chrome column hover bug */
.two-column::after {
  content: '';
  height: 1px;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
}

a:hover {
  text-decoration: none;
}
<ul class="two-column">
                          
  <li>
    <a href="#">
      Link 1
    </a>
  </li>

  <li>
    <a href="#">
      Link 2
    </a>
  </li>

  <li>
    <a href="#">
      Link 3
    </a>
  </li>

  <li>
    <a href="#">
      Link 4
    </a>
  </li>

  <li>
    <a href="#">
      Link 5
    </a>
  </li>

</ul>
zacharyliu
  • 25,578
  • 4
  • 21
  • 15