Overlapping Anchor Tags When Hovering Over One

Sven Grosen

I'm working on solving a CSS display issue and I'm stumped on how to solve this besides simply expanding the width of the parent div.

Here's the layout:

<div>
  <ul>
    <li>
      <a href="javascript:void(0)">Test</a>
    </li>
    <li>
      <a href="javascript:void(0)">Test Longer 23 Item</a>
    </li>
    <li>
      <a href="javascript:void(0)">Test 2</a>
    </li>
  </ul>
</div>

And the relevant CSS:

a {
  text-decoration: none;
  display: inline-block;
  padding: 0 10px;
  box-sizing: border-box;
}

a:hover {
  font-weight: bold;
  text-decoration: underline;
}

li + li {
  border-width: 0;
}

li {
  height: 28px;
  line-height: 28px;
  padding: 0 5px;
  width: 100%;
}

ul {
  padding: 14px 0;
  list-style: outside none none;
}

div {
  position: absolute;
  right: 0;
  top: 72px;
  width: 150px;
}

This all works fine, except when hovering over the second link (Test Longer 23 Item), which results in the bolded, underlined text wrapping to a second line which overlaps with the anchor tag below it. I could easily fix this by expanding the width of the div so that it doesn't wrap, but I'm hoping there's a more dynamic solution available to "push" the subsequent li elements down when hovering.

Is this possible in pure CSS?

JS Bin

Rahul Desai

You can fix it by adding display: inline-block; to li.

Working Code Snippet:

a {
  text-decoration: none;
  display: inline-block;
  padding: 0 10px;
  box-sizing: border-box;
}

a:hover {
  font-weight: bold;
  text-decoration: underline;
}

li + li {
  border-width: 0;
}

li {
  display: inline-block; /* <-- this! */
  height: 28px;
  line-height: 28px;
  padding: 0 5px;
  width: 100%;
}

ul {
  padding: 14px 0;
  list-style: outside none none;
}

div {
  position: absolute;
  right: 0;
  top: 72px;
  width: 150px;
}
<div>
  <ul>
    <li>
      <a href="javascript:void(0)">Test</a>
    </li>
    <li>
      <a href="javascript:void(0)">Test Longer 23 Item</a>
    </li>
    <li>
      <a href="javascript:void(0)">Test 2</a>
    </li>
  </ul>
</div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

CSS div that appears when hovering on anchor; keeping it visible while hovering over div

From Dev

How to make text appear when hovering over an image that's inside an anchor tag and the anchor tag is inside a div?

From Dev

How to change css of one class when hovering over another?

From Dev

How to highlight multiple rows when hovering over one row

From Dev

Only fire one onmouseover when hovering over multiple elements

From Dev

Changing the style of one div when hovering over another

From Dev

Hover effect is not working: Div color is not changed when hovering over a <a> anchor tag

From Dev

keep mouse over active if hovering over another overlapping element

From Dev

How to check if checkbox has been checked when hovering over an submit / anchor and display an alert prompting users to do so

From Dev

Show text over a image when hovering over it

From Dev

Which plot.ly json property enables all hover data to be displayed when hovering over one line

From Dev

How do I change the class of several tds when hovering over one of them?

From Dev

How do I change the class of several tds when hovering over one of them?

From Dev

Which plot.ly json property enables all hover data to be displayed when hovering over one line

From Dev

Chart.js - Fill Text only appearing when hovering over one part of the doughnut

From Dev

In Labview how can I change the mouse pointer when hovering over one of my boolean controls?

From Dev

Hovering over one element changes another?

From Dev

Hovering over one element changes another?

From Dev

Popup Image when hovering over a div (Jquery)

From Dev

Show content when hovering over DIV

From Dev

Specify the location of the tooltip when hovering over an element

From Dev

Hide image when hovering over a parent element

From Dev

Revealing text when hovering over a list

From Dev

Change image color when hovering over li

From Dev

Selecting color when hovering over navbar

From Dev

Losing hover when hovering over text

From Dev

Hide image when hovering over a parent element

From Dev

Changing divs when hovering over a different div

From Dev

Zoom in when hovering over image - CSS & HTML

Related Related

  1. 1

    CSS div that appears when hovering on anchor; keeping it visible while hovering over div

  2. 2

    How to make text appear when hovering over an image that's inside an anchor tag and the anchor tag is inside a div?

  3. 3

    How to change css of one class when hovering over another?

  4. 4

    How to highlight multiple rows when hovering over one row

  5. 5

    Only fire one onmouseover when hovering over multiple elements

  6. 6

    Changing the style of one div when hovering over another

  7. 7

    Hover effect is not working: Div color is not changed when hovering over a <a> anchor tag

  8. 8

    keep mouse over active if hovering over another overlapping element

  9. 9

    How to check if checkbox has been checked when hovering over an submit / anchor and display an alert prompting users to do so

  10. 10

    Show text over a image when hovering over it

  11. 11

    Which plot.ly json property enables all hover data to be displayed when hovering over one line

  12. 12

    How do I change the class of several tds when hovering over one of them?

  13. 13

    How do I change the class of several tds when hovering over one of them?

  14. 14

    Which plot.ly json property enables all hover data to be displayed when hovering over one line

  15. 15

    Chart.js - Fill Text only appearing when hovering over one part of the doughnut

  16. 16

    In Labview how can I change the mouse pointer when hovering over one of my boolean controls?

  17. 17

    Hovering over one element changes another?

  18. 18

    Hovering over one element changes another?

  19. 19

    Popup Image when hovering over a div (Jquery)

  20. 20

    Show content when hovering over DIV

  21. 21

    Specify the location of the tooltip when hovering over an element

  22. 22

    Hide image when hovering over a parent element

  23. 23

    Revealing text when hovering over a list

  24. 24

    Change image color when hovering over li

  25. 25

    Selecting color when hovering over navbar

  26. 26

    Losing hover when hovering over text

  27. 27

    Hide image when hovering over a parent element

  28. 28

    Changing divs when hovering over a different div

  29. 29

    Zoom in when hovering over image - CSS & HTML

HotTag

Archive