当前位置: 动力学知识库 > 问答 > 编程问答 >

html - How can I orient a list item to the right side of its parent unordered list/div?

问题描述:

So basically, I have a menu at the top of my page:

| Menu 1 | Menu 2 | Menu 3 | Menu 4 |

Menu 4 Item 1

Menu 4 Item 2

Menu 4 Item 3

But I want to orient the last menu so that the menu items do not extend pass the screen, but instead expand backwards, such as:

| Menu 1 | Menu 2 | Menu 3 | Menu 4 |

Menu 4 Item 1

Menu 4 Item 2

Menu 4 Item 3

Maybe I'm just not searching the right keywords, but I can't figure out how to do this. Here is the code:

<div style="background: none repeat scroll 0 0 #383aff; clear: both; font-size: 13px; height: 36px; margin: auto; width: 100%;">

<ul style="margin: 0px; padding: 0px;">

<li>Menu Item 4 <ul style="display:none; position:absolute; z-index: 100;">

<li><a style="margin: 0px; padding: 0px;">Submenu Item 1</a></li>

<li><a style="margin: 0px; padding: 0px;">Submenu Item 2</a></li>

<li><a style="margin: 0px; padding: 0px;">Long Submenu Item ASDFASDFASDFASDFASDFASDFASDFASDF</a></li></ul></li>

<li>Menu Item 2</li>

<li>Menu Item 2</li>

<li>Menu Item 1</li>

</ul>

</div>

These two questions are similar, but not solutions.

网友答案:

Something like this might work:

http://jsfiddle.net/mn6pj79L/

This only changes the last child of the mainmenu items

ul {
    width: 400px;
    display: inline;
    list-style-type: none;
    position: relative;
    padding-left: 1px;
    margin-left: -3px;
}

ul li { 
    float: left;
    width: 100px;
    border: 1px solid black;
    background-color: silver;
}

ul li ul {
    width: 150px;
    display: none;
    position: absolute;
    text-indent: 0px;
    margin: 0px;
    padding: 0px;
}

ul li ul li {
    width: 150px;
}

ul li:last-child ul {
    position: absolute;
    right: 0px;
}

ul li:hover ul {
    display: block;
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: