CSS/Menu: How to position element right below/beside elements


Tags: css

Problem :

Suppose I have markup as setup

http://jsfiddle.net/ADxne/

Currently drop downs look like

To solve the 1st problem, I could add a margin-top to child ul's to compensate for padding in list items http://jsfiddle.net/ADxne/1/

.horMenu > li > ul {
    margin-top: 10px;  
}

but for the 2nd problem without a fixed width list or list items, is there a way to position the sub menu to the right of the list item? Or is the only way to set a fixed width? http://jsfiddle.net/ADxne/2/



Solution :

you can use absolute positioning for .horMenu ul ul and then move it to right. Also add a fixed width. So with the above the .horMenu ul ul will be modified to the following:

.horMenu ul ul {
    left: 80px;
    position: absolute;
    top: 0;
    width: 80px;
}

check a live example: http://jsfiddle.net/ADxne/3/


    CSS Howto..

    How to make a box with arrow in CSS?

    css - I've got a nested floating div, how do I get it to fill the entire 100%?

    How to select that has no “type” with CSS

    How to select a group of elements after every nth-element in CSS?

    How to make HTML design of a website extensible, reusable and flexible?

    How to have a DIV appear after you hover over an image/link/another div?

    How to scrape a live java script webpage in R?

    How can I write CSS with jQuery (or JS) to apply to current and future matches?

    JavaScript: How to get a dynamically created element's width?

    How to fix cloud rising?

    How to disable CSS style relatively to a certain parent tag?

    How find all elements with a specific css property in a div and add a class to div

    How to select an item that is into another item using CSS?

    How to overlap a border in CSS in order to create tabs?

    How can I force an outer div to expand to height of inner div?

    How to apply CSS to td of particular table using Classname? [duplicate]

    CSS: how to vertically and horizontally align an image?

    How to display another div when clicked on a div using CSS only

    How to combine components in HTML header

    How do I add the date a blog post was created in place of a bullet point under list-style-type?

    How to force Twitter Bootstrap .dl-horizontal DT content to wrap instead of truncate?

    How to manipulate SVG element style with javascript?

    How to color my sidebars after centering my website

    How to make fonts display on web cross-platform?

    In Jsoup, how do I parse the CSS query by the attribute, instead of the data?

    How can I archive this responsive design?

    How or where to add javascript settimeout function to CSS vertical drop down menu

    How to wrap text in first div but use the available space where the second div's width should be adjusted to the content?

    How to structure elements in jQuery Mobile

    How can I make my CSS code compatible with all browsers? [closed]