CSS drop down menue using absolute positioning with a left:auto position

Robert Rocha

So I have your basic HTML menu structure:

<div id="page">

    <h1>Home</h1>
    <ul id="nav">
      <li><a href="http://example.com/">Home</a>
        <ul>
            <li><a href="http://example.com/">Nested Item</a></li>
            <li><a href="http://example.com/">Nested Item</a></li>
        </ul>
      </li>
      <li><a href="http://example.com/">About Us</a>
        <ul>
            <li><a href="http://example.com/">Nested Item</a></li>
            <li><a href="http://example.com/">Nested Item</a></li>
        </ul>
      </li>
      <li><a href="http://example.com/">Our Products</a>
        <ul>
            <li><a href="http://example.com/">Nested Item</a></li>
            <li><a href="http://example.com/">Nested Item</a></li>
        </ul>
      </li>
      <li><a href="http://example.com/">Contact Us</a>
        <ul>
            <li><a href="http://example.com/">Nested Item</a></li>
            <li><a href="http://example.com/">Nested Item</a></li>
        </ul>
      </li>
    </ul>

    <h2>Stuff</h2>
    <p>
    Some text</p>
    <p>
    Some text.</p>

</div>

Here is the menu css:

#nav, #nav ul{
    padding: 0;
    margin: 0;
    list-style: none;
}

#nav a{
    display: block;
    border:1px solid cyan;
}

#nav li {
    border:1px solid;
    float: left;
}

#nav li ul {
/* note that this method hides the sub-items but they remain available to screen readers. this is important! you should never use display: none; as that removes the sub-items entirely. */
    position:absolute;
    width: 10em;
    left: -999em;
}

 #nav li:hover ul {
    left: auto;
}

My question is about the last CSS rule:

 #nav li:hover ul {
        left: auto;
    }

How does the "left:auto" bring the negative position of "left:-999em" back to normal and make a perfect drop down?

Out put example.

jmiller3496

The original "left:-999em" is just 'hiding' the 'ul' by moving it so far off the page that it can't be seen. All the "left:auto" property is doing is resetting the 'ul' to its default position, where it can be seen.

See here: http://www.w3schools.com/cssref/pr_pos_left.asp

It works because the "position:absolute" tag makes it so the 'ul' can appear on top of other content, and when you hover your mouse over the 'li' it sets the "left" value to its default.

See here http://www.w3schools.com/cssref/pr_class_position.asp

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 Absolute Position Not Positioning a Button

From Dev

Drop down menu not visible at all when using position absolute

From Dev

Fluid CSS Product Grid with Full width Drop Down Panel (Without Absolute Positioning)

From Dev

CSS: Float left and position absolute

From Dev

How to switch position from left to bottom without using absolute positioning and negative margins?

From Dev

css positioning drop down under parent

From Dev

CSS Menu- Submenu drop down positioning?

From Dev

css positioning drop down under parent

From Dev

Changing drop down submenu positioning CSS only

From Dev

Positioning two blocks in absolute position for desktop and relative position for mobile using CSS or Jquery

From Dev

Positioning two blocks in absolute position for desktop and relative position for mobile using CSS or Jquery

From Dev

Position element without using absolute positioning

From Dev

Can't get css("left") of Stack Exchange help drop down - returns auto, wanted in px

From Dev

I can not figure out why my drop down menue is not hiding

From Dev

Css position corner absolute bottom left

From Dev

css position absolute off center to the left

From Dev

Drop down animation positioning

From Dev

How to align DIV right or left or center in CSS without absolute positioning?

From Dev

having an offset on the left using position absolute

From Dev

CSS positioning independently of other overlapping elements (without position: absolute)

From Dev

CSS list style drop-down menu positioning

From Dev

CSS list style drop-down menu positioning

From Dev

Why does the default left: auto; in absolute positioning not align to the left of the relative element unless set to 0?

From Dev

How to position a div to the bottom of the container, without using absolute positioning?

From Dev

css hover div position auto left and right

From Dev

A CSS absolute positioning mystery

From Dev

CSS Positioning -- Absolute Confusion

From Dev

CSS - absolute positioning issue

From Dev

CSS3 layout with position: absolute pushing down content

Related Related

  1. 1

    CSS Absolute Position Not Positioning a Button

  2. 2

    Drop down menu not visible at all when using position absolute

  3. 3

    Fluid CSS Product Grid with Full width Drop Down Panel (Without Absolute Positioning)

  4. 4

    CSS: Float left and position absolute

  5. 5

    How to switch position from left to bottom without using absolute positioning and negative margins?

  6. 6

    css positioning drop down under parent

  7. 7

    CSS Menu- Submenu drop down positioning?

  8. 8

    css positioning drop down under parent

  9. 9

    Changing drop down submenu positioning CSS only

  10. 10

    Positioning two blocks in absolute position for desktop and relative position for mobile using CSS or Jquery

  11. 11

    Positioning two blocks in absolute position for desktop and relative position for mobile using CSS or Jquery

  12. 12

    Position element without using absolute positioning

  13. 13

    Can't get css("left") of Stack Exchange help drop down - returns auto, wanted in px

  14. 14

    I can not figure out why my drop down menue is not hiding

  15. 15

    Css position corner absolute bottom left

  16. 16

    css position absolute off center to the left

  17. 17

    Drop down animation positioning

  18. 18

    How to align DIV right or left or center in CSS without absolute positioning?

  19. 19

    having an offset on the left using position absolute

  20. 20

    CSS positioning independently of other overlapping elements (without position: absolute)

  21. 21

    CSS list style drop-down menu positioning

  22. 22

    CSS list style drop-down menu positioning

  23. 23

    Why does the default left: auto; in absolute positioning not align to the left of the relative element unless set to 0?

  24. 24

    How to position a div to the bottom of the container, without using absolute positioning?

  25. 25

    css hover div position auto left and right

  26. 26

    A CSS absolute positioning mystery

  27. 27

    CSS Positioning -- Absolute Confusion

  28. 28

    CSS - absolute positioning issue

  29. 29

    CSS3 layout with position: absolute pushing down content

HotTag

Archive