div的位置问题

时间:2011-08-28 19:39:34

标签: jquery html css

我正在尝试在li中添加div并且似乎与mouseEnter事件相关联。问题是如果我将div附加到文档看起来很棒。喜欢这个

$(document.body).append('<div id="subMenu" class="ui-state-hover" style="width:150px;height:200px; float: left;">subCategory</div>');
$("#subMenu").css({
      position:'absolute',
      top: $(this).offset().top,
      left: ($(this).offset().left + $(this).width())
  }).show();

here's a video

现在,当我尝试追加相同的div但是li实际上并不起作用

$(document.body).append('<div id="subMenu" class="ui-state-hover" style="width:150px;height:200px; float: left;">subCategory</div>');
$("#subMenu").css({
      position:'absolute',
      top: $(this).offset().top,
      left: ($(this).offset().left + $(this).width())
  }).show();

here's a video

可能有什么问题???

这是html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link rel="stylesheet" type="text/css" media="screen" href="assets/themes/custom-theme/jquery-ui-1.8.13.custom.css" />
        <link rel="stylesheet" type="text/css" media="screen" href="assets/styles.css" />
        <link rel="stylesheet" type="text/css" media="screen" href="assets/jquery.rating.css" />
        <script type="text/javascript" src="js/jquery-1.6.1.min.js"> </script>
        <script type="text/javascript" src="js/jquery-ui-1.8.13.custom.min.js"> </script>
        <script type="text/javascript" src="js/jquery.MetaData.js"> </script>
        <script type="text/javascript" src="js/jquery.rating.js"> </script>
        <script type="text/javascript" src="js/functionScript.js"> </script>  
        <script type="text/javascript" src="https://apis.google.com/js/plusone.js">
          {lang: 'es-419'}
        </script>      
        <title>Prevista</title>
    </head>
    <body>
        <div class="header ui-state-hover">
            <div class="headerContainer">
                <table style="width:1024px" class="centerTable">
                    <tr>
                        <td>
                            <div class="logoContainer"></div>
                        </td>
                        <td>
                            <div class="fieldsContainer">
                                <table style="text-align:center">
                                    <tr>
                                        <td>
                                            <input id="txtEmail" class="txtInput ui-corner-all" type="text" value="Dirección de Correo"/>
                                        </td>
                                        <td>
                                            <input id="txtPassword" class="txtInput ui-corner-all" value="Contraseña" />
                                        </td>
                                        <td colspan="2">
                                            <input id="btnStartSession" type="button" value="Iniciar sesión"/>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <input id="chkRenember" type="checkbox" value=""  style="text-align:right"/> <label class="txtFooter"> Recuérdame en este equipo </label>
                                        </td>
                                        <td>
                                            <label class="txtFooter"> ¿Olvidaste tu contraseña? </label>
                                        </td>
                                         <td>
                                            <a href="http://www.facebook.com"><img src="assets/facebook-logo.png" width="40" height="40" /></a>
                                        </td>
                                        <td>
                                            <a href="http://www.twitter.com"><img src="assets/icon_twitter.png" width="40" height="40" /></a>
                                        </td>
                                    </tr>
                                </table>     
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div class="container">
            <div id="menuContainer" class="boxShadow">
                <ul id="menuPrincipal">
                    <li>
                        <a href="#tabs-1">Quiénes somos</a>
                    </li>
                    <li>
                        <a href="#tabs-2">Catálogo de repuestos</a>
                    </li>
                    <li>
                        <a href="#tabs-3">Cotización OnLine</a>
                    </li>
                    <li>
                        <a href="#tabs-4">Preguntas frecuentes</a>
                    </li>
                </ul>
                <div id="tabs-1">
                    <div id="textContainer">
                        <table class="tblText">
                            <tr>
                                <td colspan="2"> 
                                    <p> <a class="underLine">Repuestoenmano.com</a> Es todo lo que necesitas saber en cuanto a respuestos para vehículos</p>
                                    </td>
                                    </tr>
                                        <tr>
                                            <td>
                                                <div class="txtInformation"><p>
                                                    Somos una empresa innovadora dedicada a satisfacer la amplia demanda de repuestos y accesorios para vehículos del mercado venezolano, facilitándoles por medio de un servicio de calidad los mejores precios y la comodidad de recibir el producto en su casa, taller u oficina.
                                                    </p></div>
                                            </td>
                                            <td>
                                                <img src="assets/image/vision-de-futuro200x184.jpg" width="150" height="140" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="2">
                                                <div clas="txtInformation">
                                                    <p class="underLine">Misión</p>
                                                    <p style="font-style:italic">Ofrecer un servicio de calidad donde la rapidez y buenos precios sea nuestra marca.</p>
                                                </div>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <div class="txtInformation">
                                                    <p class="underLine">Visión</p>
                                                    <p>Ser reconocidos como la empresa líder en el mercado venezolano en la venta de repuestos y accesorios al mayor y al detal, a través del comercio electrónico ofreciendo un servicio de calidad.</p>
                                                    <p class="underLine"> Recuerda seguirnos en twitter y facebook</p>
                                                    <a href="http://www.facebook.com"><img src="assets/facebook-logo.png" width="40" height="40" /></a>
                                                    <a href="http://www.twitter.com"><img src="assets/icon_twitter.png" width="40" height="40" /></a>
                                                </div>
                                            </td>
                                            <td>
                                                <img src="assets/image/vision-de-futuro200x184.jpg" width="150" height="140" />
                                            </td>
                                        </tr>
                                    </table>
                                    </div>
                                    </div>
                                        <div id="tabs-2">
                                            <table id="tblButtonContainer" cellpadding="0" cellspacing="0" class="tblSearch">
                                                <tr>
                                                    <td>
                                                        <div id="topCatalog" class="ui-widget-content ui-corner-top">
                                                            <label style="float:left;color:#FFF;padding: 9px 9px 9px 28px; font-weight:bold">Categorias</label>
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="ui-accordion-header ui-helper-reset ui-state-default">
                                                            <label style="float:left;color:#FFF;padding:7px">Buscar</label>
                                                            <input id="txtFinder" class="txtInput ui-corner-all" type="text" value="Buscar" size="40"/>
                                                            <input id="btnFinder" type="button" value="Buscar"/>
                                                        </div>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <div class="ui-accordion-header ui-helper-reset ui-state-default">
                                                            <ul class="menuCat">
                                                                <li id="cat-1">
                                                                    <label class="formatText" style="font-weight:bold">Accesorios 4x4</label>
                                                                    <span class="ui-icon ui-icon-triangle-1-e" style="float:right"></span>
                                                                </li>
                                                                <li id="cat-2">
                                                                    <label class="formatText" style="font-weight:bold">Frenos y Pastillas</label>
                                                                    <span class="ui-icon ui-icon-triangle-1-e" style="float:right"></span>
                                                                </li>
                                                                <li id="cat-3">
                                                                    <label class="formatText" style="font-weight:bold">Tren Delantero</label>
                                                                    <span class="ui-icon ui-icon-triangle-1-e" style="float:right"></span>
                                                                </li>
                                                                <li id="cat-4">
                                                                    <label class="formatText" style="font-weight:bold">Repuestos usados</label>
                                                                    <span class="ui-icon ui-icon-triangle-1-e" style="float:right"></span>
                                                                </li>
                                                                <li id="cat-5">
                                                                    <label class="formatText" style="font-weight:bold">Lubricantes y Fluidos</label>
                                                                    <span class="ui-icon ui-icon-triangle-1-e" style="float:right"></span>
                                                                </li>
                                                            </ul>
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div id="catalogSearch" class="boxShadow">
                                                            <table id="tblCatalogSearch" class="centerTable" style="text-align:center;">
                                                                <tr>
                                                                    <td colspan="3">
                                                                        <div style="margin:0;width:490px" class="ui-state-hover">
                                                                            Elige el modelo de tu vehículo
                                                                        </div>
                                                                        <div style="height:20px"></div>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td>
                                                                        <label>Marca</label><select name="brand" id="brand"></select>
                                                                    </td>
                                                                    <td>
                                                                        <label>Modelo</label><select name="model" id="model"></select>
                                                                    </td>
                                                                    <td>
                                                                        <label>Año</label><select name="year" id="year"></select>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td>
                                                                        <div style="height:20px"></div>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td colspan="3">
                                                                        <input name="btnSearch" id="btnSearch" value="Buscar" type="button" />
                                                                    </td>
                                                                </tr>
                                                            </table>
                                                        </div>
                                                        <div class="boxShadow ui-widget-content topSales ui-corner-all">
                                                            <div style="margin:0;width:490px;" class="ui-state-hover ui-corner-all">
                                                                            Los mas Vendidos
                                                                        </div>
                                                                        probando
                                                        </div>
                                                        <div class="boxShadow ui-widget-content topSearch ui-corner-all">
                                                            <div style="margin:0;width:490px;" class="ui-state-hover ui-corner-all">
                                                                            Los mas Buscados
                                                                        </div>
                                                                        probando
                                                        </div>
                                                        <div id="results" class="ui-corner-all borders">
                                                            <table id="tblResult" class="centerTable">
                                                                <tr>
                                                                    <td>
                                                                        <div class="ui-accordion-header ui-helper-reset ui-state-default ui-corner-all">
                                                                            <span style="padding:0 0 0 15px">Resultados de la Busqueda: </span>
                                                                        </div>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td>
                                                                        <div style="height:30px"></div>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td>
                                                                        <div class="resuIItem">
                                                                            <div class="numero"> 1.</div>
                                                                            <div class="productImage"><a><img src="/prevista/assets/image/car-brakes-1.gif"   class="menuImage" alt="Frenos"  /> </a></div>
                                                                            <div class="data">
                                                                                <div class="titulo">
                                                                                <a class="tituloTexto">Frenos ABS con Ventilacion</a> <span class="marca">Mamusa</span>
                                                                                </div>
                                                                                <div class="precio"><span class="precioTag">Precio:</span> <span class="precioValue" style="text-decoration:line-through">250 BsF. </span><span class="ofertaTag">230 BsF.</span></div>
                                                                                <div class="calification">
                                                                                    <input name="adv1" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv1" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv1" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv1" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv1" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv1" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv1" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv1" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv1" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv1" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv1" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv1" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv1" type="radio" class="star {split:4}" disabled="disabled" checked="checked"/>
                                                                                    <input name="adv1" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv1" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv1" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv1" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv1" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv1" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv1" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                </div>
                                                                                <div class="socialMediaButtons">
                                                                                    <div class="facebookButton"><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=204758249585709&amp;xfbml=1"></script><fb:like href="" send="false" layout="button_count" width="55" show_faces="false" font=""></fb:like> </div>
                                                                                    <div class="twitterButton"><a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-via="justelnegro">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div>
                                                                                    <div class="googlePlusButton"><g:plusone></g:plusone></div>
                                                                                </div>
                                                                            </div>
                                                                        </div>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td>
                                                                        <div class="resuIItem">
                                                                            <div class="numero">2. </div>
                                                                            <div class="productImage"><a><img src="/prevista/assets/image/frenos.jpg"   class="menuImage" alt="Frenos"  /> </a></div>
                                                                            <div class="data">
                                                                                <div class="titulo">
                                                                                <a class="tituloTexto">Frenos para Sedan Italianos</a> <span class="marca">Mamusa</span>
                                                                                </div>
                                                                                <div class="precio"><span class="precioTag">Precio:</span> <span class="precioValue" style="text-decoration:line-through">560 BsF. </span><span class="ofertaTag">480 BsF.</span></div>
                                                                                <div class="calification">
                                                                                    <input name="adv2" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv2" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv2" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv2" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv2" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv2" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv2" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv2" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv2" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv2" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv2" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv2" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv2" type="radio" class="star {split:4}" disabled="disabled" checked="checked"/>
                                                                                    <input name="adv2" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv2" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv2" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv2" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv2" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv2" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv2" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                </div>
                                                                                <div class="socialMediaButtons">
                                                                                    <div class="facebookButton"><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=204758249585709&amp;xfbml=1"></script><fb:like href="" send="false" layout="button_count" width="55" show_faces="false" font=""></fb:like> </div>
                                                                                    <div class="twitterButton"><a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-via="justelnegro">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div>
                                                                                    <div class="googlePlusButton"><g:plusone></g:plusone></div>
                                                                                </div>
                                                                            </div>
                                                                        </div>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td>
                                                                        <div class="resuIItem">
                                                                            <div class="numero">3. </div>                                                                           <div class="productImage"><a><img src="/prevista/assets/image/frenos3.jpg"   class="menuImage" alt="Frenos"  /> </a></div>
                                                                            <div class="data">
                                                                                <div class="titulo">
                                                                                <a class="tituloTexto">Frenos para Sedan Chinos</a> <span class="marca">Mamusa</span>
                                                                                </div>
                                                                                <div class="precio"><span class="precioTag">Precio:</span> <span class="precioValue">200 BsF. </span></div>
                                                                                <div class="calification">
                                                                                    <input name="adv3" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv3" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv3" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv3" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv3" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv3" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv3" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv3" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv3" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv3" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv3" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv3" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv3" type="radio" class="star {split:4}" disabled="disabled" checked="checked"/>
                                                                                    <input name="adv3" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv3" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv3" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv3" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv3" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv3" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                    <input name="adv3" type="radio" class="star {split:4}" disabled="disabled"/>
                                                                                </div>
                                                                                <div class="socialMediaButtons">
                                                                                    <div class="facebookButton"><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=204758249585709&amp;xfbml=1"></script><fb:like href="" send="false" layout="button_count" width="55" show_faces="false" font=""></fb:like> </div>
                                                                                    <div class="twitterButton"><a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-via="justelnegro">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div>
                                                                                    <div class="googlePlusButton"><g:plusone></g:plusone></div>
                                                                                </div>
                                                                            </div>
                                                                        </div>
                                                                    </td>
                                                                </tr>
                                                            </table>
                                                        </div>
                                                    </td>
                                                </tr>
                                            </table>
                                        </div>
                                        <div id="tabs-3">
                                            Contenido para plugins jQuery
                                        </div>
                                        <div id="tabs-4">
                                            Contenido de prueba
                                        </div>
                                    </div> 
                                    </div>
                                    </body>
                                    </html>

这是我的css

@charset "utf-8";
/* CSS Document */

body{
    margin:0;
}

.txtFooter{
    color:black;
    font-family:Helvetica;
    font-size:12px;
    font-weight:bold;
}

.header{
    height:100px;
    margin:0;
    border:0;
}

.container{
    margin:0;
    width:100%;
}

.txtInput{
    color:black;
    font-family:Helvetica;
    font-weight:Bold;
}

.fieldsContainer{
    float:right;
    margin-right:70px;
}
.headerContainer{
    margin-left:auto;
    margin-right:auto;
    height:100px;
    width:1024px;
    display:block;
    position: relative;
    overflow: auto;
}

#menuContainer{
    margin-left:auto;
    margin-right:auto;
    height:600px;
    width: 820px;

}

#menuPrincipal li{
    margin:0;
    border:0;
    display: inline;
    list-style-type: none;
    padding-right: 10px;
    text-align:center
}

.logoContainer{
    margin-left:80px;
    height:90px;
    width:300px;
    float:left;
    background:url(../js/logo1.png) no-repeat;
}

#topCatalog{
    text-align:center;
    width:100%;
    height:42px;
    background:orange;
}

/*.catalog{
    margin:0;
    position:relative;
}*/

ul{
    margin:0px;
    padding:0px;
}

.menuCat li{
    list-style: none outside none;
    padding:0px 0px 10px 5px;
    font-size:12px;
    font-weight:bold;
}


#textContainer{
    border:0;
    height:500px;
    width:900px;
    margin:0;
    text-align:justify;
    color:#353735;
    font-size:16px
}

.underLine{
    font-weight:bold;
}

#catalogSearch{
    margin-top:20px;
    width:500px;
    /***round border right*****/
    -moz-border-radius-topright: 4px; 
    -webkit-border-top-right-radius: 4px; 
    border-top-right-radius: 4px; 
    -moz-border-radius-bottomright: 4px; 
    -webkit-border-bottom-right-radius: 4px;
    border-bottom-right-radius: 4px;
    /***round border left*****/ 
    -moz-border-radius-topleft: 4px; 
    -webkit-border-top-left-radius: 4px; 
    border-top-left-radius: 4px; 
    -moz-border-radius-bottomleft: 4px; 
    -webkit-border-bottom-left-radius: 4px; 
    border-bottom-left-radius: 4px;
    margin-left:auto;
    margin-right:auto;
    border:1px solid #072fc5;
}

.tblText tr td{
    border-bottom: 2px solid #072fc5;
}

.txtInformation{

    width:600px;
    height:180px;
    margin-top:40px 
}

.boxShadow{
    -webkit-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.5);  
    -moz-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.5);
    box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.5);
}

.boxShadow {
  behavior: url(ie-css3.htc);
}

.centerTable{
    margin-left:auto;
    margin-right:auto;  
}

.formatText{
    font-size:14px;
    font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
}

.tblSearch{
    margin:0px;
    border:0px; 
    border-collapse: collapse;
    border-spacing: 0;
    width:100%;
} 

#results
{
    margin-left:20px;
    margin-right:auto;
    margin-top:20px;    
}

#tblButtonContainer td 
{
    vertical-align: top;
}

.topSales
{
    margin-top:20px;
    margin-right:auto;
    margin-left:50px;   
    width:500px;
    min-height:200px
}

.topSearch
{
    margin-top:20px;
    margin-right:auto;
    margin-left:50px;   
    width:500px;
    min-height:200px
}

.resuIItem
{
    border-bottom: 1px solid #0072FF;
    width:560px;
    height:150px;
}

.numero
{
    width: 30px;
    float: left;
    height: 13px;
    display: block;
    font-size: 14px;    
}

.menuImage
{
    width: 100px;
    height: 100px;
    display: inline;
    padding-top: 10px;
}

.productImage
{
    float:left; 
}

.data
{
    display: table; 
    padding-left: 15px; 
    padding-top: 10px;  
}

.tituloTexto
{
    color: #465689;
    font-weight: bold;
}

.precioTag
{
    text-decoration: underline;
    color: #465689; 
}
.precioValue
{
    color: red;
    font-weight: bold;
    font-family: arial;
}
.calification
{
    position: absolute; 
}
.ofertaTag
{
    font-weight: bold;
    font-family: arial;
}
.socialMediaButtons div
{
    margin-top:20px;
    float: left;
}

这是我的js

$(document).ready(initialize);

function initialize(){

    $('.tituloTexto').css('color','#465689');

    $('.menuCat li').hover(showSubMenu, hideSubMenu);
    $(".txtInput").click(manageFinder);
    $("#model").attr("disabled", true);
    $("#year").attr("disabled", true);

    $("#menuContainer").tabs({selected : 1,create: function (event, ui){
        $(this).find('.ui-tabs-nav li').removeClass('ui-state-active');
        $(this).find('.ui-tabs-nav li').css('border','1px solid #072fc5');
        $(this).css('height','750px');
    }});

    //$(".catalog").hide();
    //$(".topCatalog").hide();
    $("#results").hide();
    $("#btnSearch").button();
    $("#btnFinder").button();
    $("#model").change(loadYears);
    $("#btnSearch").click(findProducts);
    $(".menuCat li").addClass('ui-widget-content ui-accordion-header ui-state-default');

    $("#menuContainer").bind('tabsshow',function (event,ui){
        $(ui.tab).parent().removeClass('ui-state-active');
        $(ui.tab).parent().css('border','1px solid #072fc5');
        if (ui.index == 0){
            $("#menuContainer").css('height','680px');
        }
        else if (ui.index == 1){
            $("#menuContainer").css('height','750px');
        }
        else
            $("#menuContainer").css('height','600px');
    });

    $.ajax({
            async: false,
            type: "POST",
            url: "services/BrandsService.php",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: addBrands  
        });

    $("#brand").change(ManageModels);
}

function manageFinder(event){
    event.stopPropagation();
    $(this).val('');
}

function addBrands(values){
    $("#brand").append('<option value="'+0 +'">Elige una Marca</option>');
    for(var id in values) {
        var name = values[id];
        $("#brand").append('<option value="'+id +'">'+name+'</option>');
    }
}

function ManageModels(){

    if($("#brand").val() != 0){
        $("#model").attr("disabled", false);
        $.ajax({
                async: false,
                type: "POST",
                url: "services/ModelsService.php",
                data: "IdModelo="+$("#brand").val(),
                dataType: "json",
                success: function(values){
                $("#model").append('<option value="'+0 +'">Elige un modelo</option>');
                    for(var id in values) {
                        var name = values[id];
                        $("#model").append('<option value="'+id +'">'+name+'</option>');
                    }   
                }   
        });
    }
    else{
        $("#model").attr("disabled", true);
        $("#model").html('');
        alert('Elige una opcion');
    }
}

function loadYears(){

    if($("#model").val() != 0){
        $("#year").attr("disabled", false);
        $.ajax({
                async: false,
                type: "POST",
                url: "services/YearsService.php",
                dataType: "json",
                success: function(values){
                $("#year").append('<option value="'+0 +'">Elige un año</option>');
                    for(var id in values) {
                        var name = values[id];
                        $("#year").append('<option value="'+id +'">'+name+'</option>');
                    }   
                }   
        });
    }
    else{
        $("#year").attr("disabled", true);
        $("#year").html('');
        alert('Elige una opcion');
    }
}

function findProducts(e){
    e.preventDefault();
    $('#catalogSearch').fadeOut('slow');
    $('.topSearch').fadeOut('slow');
    $('.topSales').fadeOut('slow');
    $("#results").fadeIn('slow');
}

function showSubMenu() {
    var liOption = $(this);
    var aux = liOption.attr('id');
    aux = aux.replace('cat-','');
    $(liOption).append('<div id="subMenu" class="ui-state-hover" style="width:150px;height:200px; float: left;">subCategory</div>');
    $("#subMenu").css({
          position:'absolute',
          top: $(this).offset().top,
          left: ($(this).offset().left + $(this).width())
      }).show();
}

function hideSubMenu() {
    $("#subMenu").remove();
}

3 个答案:

答案 0 :(得分:2)

<div>位置很可能是其父母之一的绝对位置。

尝试过.menuCat li position:relative;

不要忘记相应地修改topleft值。

答案 1 :(得分:2)

你正在以一种非常复杂的方式重新发明轮子 - 更糟糕的是 您只能使用HTML和CSS获取“悬停菜单”。 (加上最少量的假冒JS:悬停在旧的,不兼容的浏览器中......)

在HTMLDog中阅读the article以了解它,或者只看the working exampleVertical menus完全可能。)

如果您发现自己编写它很复杂(不是那么难,但是......),还有javascript库可以为您执行这些菜单,例如Suckerfish

我希望这会有所帮助 - 下次首先搜索! :)

答案 2 :(得分:0)

最后我解决了我的问题,非常简单只需要一点耐心,部分与@Ibrahim AshShohail的想法,但我还需要在div中添加以下样式,称为subMenu

#subMenu
{
    width:150px;
    height:200px; 
    float:left;
    display:none;
    position:absolute;
    left:100%;
    top:0px;
}

.menuCat li{
    position:relative;
    list-style: none outside none;
    padding:0px 0px 10px 5px;
    font-size:12px;
    font-weight:bold;
}