html - CSS dropdown submenu with dynamic width: how to align left? -


it's easy have li > ul submenu show css:

.menu ul { padding-left: 0px; } .menu li { list-style-type: none; display: inline-block; padding-left: 0px; margin: 1px; background: #ddd; width: 100px; } .menu li ul { display: none; } .menu li:hover > ul { display: block; position: absolute; background: #000; } .menu li:hover > ul li { display: block; background: #bbb; width: auto; } 

in case, size of submenu automatically adjusts width of content. submenu aligns left left of parent li element is.

let's want align submenu right, right should lign parent li's right side. can having fixed width of submenu, , use (assuming parent li 100px wide):

#menu-left li:hover > ul { width: 150px; margin-left: -50px; } 

but can't use flexible width submenu's anymore. also, need know width of parent li.

js fiddle explains question best: https://jsfiddle.net/ybc0uxq8/1/

anyone knows way have right side of sub ul lign right side of parent li without needing fixed submenu width, , allowing submenu width larger parent li?

according comments/request, here edited version of original css code reflect desired result:

/* apply both */ .menu ul { padding-left: 0px; } .menu li { list-style-type: none; display: inline-block; position: relative; padding-left: 0px; margin: 1px; background: #ddd; } .menu li ul { display: none; } .menu li:hover > ul { display: block; position: absolute; background: #000; right: 0; } .menu li:hover > ul li { background: #bbb; white-space: nowrap; } 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -