I’m building a navigation with has a drop down unordered list within an unordered list. I’d like to make the list items as wide as at least the “head” list item so that the drop down menu looks right. Just now the drop down menu is thinner as the line items have a lower character count than the line item that contains the unordered list.
I’d like to make somehting of the order:
ul li ul {
{width: *as wide as ul li*;
}
Is it possible to do this without javascript and just within css alone?
Yes, it is. Technically, the
ulis already the same width, but it doesn’t appear to be due to margins and padding. To change this, use this CSS:You may also want to include the following CSS to change the padding/margin of the
lichild as well:Update
In your specific example (posted in comments), the issue is you’ve set
ul li ul‘spositionvalue toabsolute. This takes it out of it’s parent (in regards to handlingwidth), but can be fixed with the following CSS being added to your existing CSS:While this allows you to set the submenu to be the same width as the parent, it comes with the side effect of making the menu items wrap (see
sui generismenu). To overcome this, use the following CSS instead (in addition to your jsFiddle):