Question

I am working with a menu, which has awrapper with id "menu_unidades". I want this div to adjust its dimensions once the div expands on the mouse over.

here is the FIDDLE

I am working with superfish modified css

CSS

/*** ESSENTIAL STYLES ***/
body {
font-family: Arial,Helvetica,sans-serif;
font-size: 11px;
}

#menu_unidades {
    width: auto;
    height: auto;
    position: relative;
    float: left;
padding: 10px 15px 10px 10px;
box-shadow: 0px 2px 2px rgb(102, 102, 102);
    left: 50px;
    margin-top: 10px;
    margin-bottom: 20px;
background-color: rgba(0,53,146,0.7);
}

.sf-menu, .sf-menu * {
    margin: 0;
    padding: 0;
list-style: none;
}
.sf-menu li {
position: relative;
}
  .sf-menu ul {
    position: absolute;
    display: none;
    top: 100%;
    left: 0;
z-index: 99;
}
.sf-menu > li {
float: left;
}
.sf-menu li:hover > ul,
.sf-menu li.sfHover > ul {
display: block;
}

.sf-menu a {
display: block;
position: relative;
}
.sf-menu ul ul {
top: 0;
left: 100%;
}

.sf-menu li ul {
padding: 10px 15px 10px 10px;
background-color: rgba(0,53,146,0.7);
}

.sf-menu li li {
    padding-left:10px;
    padding-right:10px;
    padding-top:1px;
padding-bottom:1px;
}

.sf-menu li ul a{
    padding:2px;
    font-size: 12px;
text-transform:none;
}

/*** DEMO SKIN ***/
.sf-menu {
    /*float: left;*/
margin-bottom: 1em;
}
.sf-menu ul {
box-shadow: 2px 2px 6px rgba(0,43,146,0.7);
min-width: 12em; /* allow long menu items to determine submenu width */
*width: 12em; /* no auto sub width for IE7, see white-space comment below */
}

.sf-menu li {
border-bottom:1px solid #fff;
white-space: nowrap; /* no need for Supersubs plugin */
*white-space: normal; /* ...unless you support IE7 (let it wrap) */
-webkit-transition: background .2s;
transition: background .2s;
}
.sf-menu ul li {
}
.sf-menu ul ul li {
}
.sf-menu li:hover,
.sf-menu li.sfHover {
background-color: rgba(0,53,146,0.7);
/* only transition out, not in */
-webkit-transition: none;
transition: none;
}

/*** arrows (for all except IE7) **/
.sf-arrows .sf-with-ul {
padding-right: 2.5em;
*padding-right: 1em; /* no CSS arrows for IE7 (lack pseudo-elements) */
}
 /* styling for both css and generated arrows */
  .sf-arrows .sf-with-ul:after {
    content: '';
    position: absolute;
    top: 50%;
    right: 1em;
    margin-top: -3px;
    height: 0;
width: 0;
/* order of following 3 rules important for fallbacks to work */
border: 5px solid transparent;
border-top-color: #dFeEFF; /* edit this to suit design (no rgba in IE8) */
border-top-color: rgba(255,255,255,.5);
 }
.sf-arrows > li > .sf-with-ul:focus:after,
.sf-arrows > li:hover > .sf-with-ul:after,
.sf-arrows > .sfHover > .sf-with-ul:after {
border-top-color: white; /* IE8 fallback colour */
}
/* styling for right-facing arrows */
.sf-arrows ul .sf-with-ul:after {
margin-top: -5px;
margin-right: -3px;
border-color: transparent;
border-left-color: #dFeEFF; /* edit this to suit design (no rgba in IE8) */
border-left-color: rgba(255,255,255,.5);
}
.sf-arrows ul li > .sf-with-ul:focus:after,
.sf-arrows ul li:hover > .sf-with-ul:after,
.sf-arrows ul .sfHover > .sf-with-ul:after {
border-left-color: white;
}

HTML

Was it helpful?

Solution

You had this css selector, .sf-menu ul which at first I was under the impression that it was adding absolute to all of the uls.

I then changed it to, .sf-menu > ul so it is specifically targeting the uls inside of .sf-menu.

.sf-menu > ul {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 99;
}

After looking over all of the css I am not 100% sure why it fixed it exactly. You have some duplication of your classes and such in your css so I am not to sure.

One reason it was not expanding correctly is due to the fact of position: absolute. They are taken outside of the element as if it was not in there at all like floating but worse.

My best educated guess would be that without the > it was applying position: absolute to the class .sf-menu. This would take the entire nav out of the workflow and wouldn't make the parent expand to the content.

Now the absolute divs are relative to .sf-menu's lis and since the li are relatively positioned the parent can fill to them.

Here is the JSFIDDLE to see it in action.

OTHER TIPS

If I understand correctly you want to give a custom look to your wrapper based on mouseover? If so you can add a custom class to it on mouseenter and mouseleave:

$('div#menu_unidades').hover(function() {
    $(this).toggleClass('test-class');
});

Add whatever you want to the test-class css and presto! You've got JQuery awesomeness. You can see this in action here http://jsfiddle.net/qLu62/1/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top