繁体   English   中英

UI下拉菜单和阴影不对齐

[英]Ul dropdown menus and shadow not aligning

我正在使用我找到的菜单: http//www.dynamicdrive.com/dynamicindex1/ddsmoothmenu.htm

我使用第四个答案中的css编辑将其修改为居中: 无法将div置于div中

问题是下拉菜单没有对齐自己,我无法弄清楚如何实现这一点。

这是代码:

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" />
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!DOCTYPE html>

<link rel="stylesheet" type="text/css" href="ddsmoothmenu.css" />

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script type="text/javascript" src="ddsmoothmenu.js">

/***********************************************
* Smooth Navigational Menu- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

</script>

<script type="text/javascript">

ddsmoothmenu.init({
    mainmenuid: "smoothmenu1", //menu DIV id
    orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
    classname: 'ddsmoothmenu', //class added to menu's outer DIV
    arrowswap: true,
    //customtheme: ["#1c5a80", "#18374a"],
    contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
})



</script>
<title>Untitled</title>
</head>

<body>
<div class="ddsmoothmenu" id="smoothmenu1">

<ul>
<li><a href="/index.html">Home</a></li>
<li><a href="/about.html">About Us</a>
  <ul>
  <li><a href="/history.html">History</a></li>
  <li><a href="/pc.html">Precepts and Credo</a></li>
  <li><a href="philan.html">Philanthropy</a></li>
  </ul>
</li>
<li><a>Recruitment</a>
  <ul>
  <li><a>Rush Schedule</a></li>
  <li><a href="/rpfaqs.html">Rush/Pledging FAQs</a></li>
    </ul>
</li>
<li><a>Calendar</a></li>
<li><a href="/forum/index.php">Forum</a></li>
</ul>
<br style="clear: left" />
</div>
</body>
</html>

CSS:

.ddsmoothmenu{
font: bold 12px Verdana;
background: #1c5a80; /*background of menu bar (default state)*/
width: 100%;
}

.ddsmoothmenu ul{
position: relative;
    float: left;
    left: 50%;
    list-style: none;
    padding: 0;
}

/*Top level list items*/
.ddsmoothmenu ul li{
position: relative;
display: inline;
float: left;
text-align:center;
    right: 50%;
    margin: 0 5px;
}

/*Top level menu link items style*/
.ddsmoothmenu ul li a{
display: block;
background: #1c5a80; /*background of menu items (default state)*/
padding: 8px 10px;
color: orange;
text-decoration: none;
}

* html .ddsmoothmenu ul li a{ /*IE6 hack to get sub menu links to behave correctly*/
display: inline-block;
}

.ddsmoothmenu ul li a:link, .ddsmoothmenu ul li a:visited{
color: orange;
}

.ddsmoothmenu ul li a.selected { /*CSS class that's dynamically added to the currently active menu items' LI A element*/
background: orange !important; 
color: #1c5a80;
}

.ddsmoothmenu ul li a:hover{
background: orange; /*background of menu items during onmouseover (hover state)*/
color: #1c5a80;
}

/* sub menus */
.ddsmoothmenu ul li ul{
position: absolute;
left: -3000px;
display: none; /*collapse all sub menus to begin with*/
visibility: hidden;
}

/*Sub level menu list items (alters style from Top level List Items)*/
.ddsmoothmenu ul li ul li{
display: inline;
float: none;
}

/*All subsequent sub menu levels vertical offset after 1st level sub menu */
.ddsmoothmenu ul li ul li ul{
top: 0;
}

/* Sub level menu links style */
.ddsmoothmenu ul li ul li a{
font: normal 13px Verdana;
width: 160px; /*width of sub menus*/
padding: 5px;
margin: 0;
border-top-width: 0;
border-bottom: 1px solid gray;
}

/* Holly Hack for IE \*/
* html .ddsmoothmenu{height: 1%;} /*Holly Hack for IE7 and below*/


/* ######### CSS classes applied to down and right arrow images  ######### */

.downarrowclass{
position: absolute;
top: 12px;
right: 7px;
}

.rightarrowclass{
position: absolute;
top: 6px;
right: 5px;
}

/* ######### CSS for shadow added to sub menus  ######### */

.ddshadow{ 
position: absolute;
left: 0;
top: 0;
width: 0;
height: 0;
background-color: #ccc; /* generally should be just a little lighter than the box-shadow color for CSS3 capable browsers */
}

.toplevelshadow{
margin: 5px 0 0 5px; /* in NON CSS3 capable browsers gives the offset of the shadow */
opacity: 0.8; /* shadow opacity mostly for NON CSS3 capable browsers. Doesn't work in IE */
}

.ddcss3support .ddshadow.toplevelshadow {
margin: 0; /* in CSS3 capable browsers overrides offset from NON CSS3 capable browsers, allowing the box-shadow values in the next selector to govern that */
/* opacity: 1; */ /* optionally uncomment this to remove partial opacity for browsers supporting a box-shadow property which has its own slight gradient opacity */
}

.ddcss3support .ddshadow {
background-color: transparent;
box-shadow: 5px 5px 5px #aaa; /* box-shadow color generally should be a little darker than that for the NON CSS3 capable browsers background-color */
-moz-box-shadow: 5px 5px 5px #aaa;
-webkit-box-shadow: 5px 5px 5px #aaa;
}

任何帮助,将不胜感激

编辑:实际问题是子菜单的内容显示在白色(和阴影)容器之外。 它需要在容器中显示。

看到你的html代码有两个<!DOCTYPE html>标签删除第二个doctype

然后尝试你的代码。

在这里我附上jsfiddle

http://fiddle.jshell.net/U34L5/

通过设置left: 0px可以克服子菜单定位的问题,如下所示:

.ddsmoothmenu ul li ul li {
    float: none;
    display: list-item; /* or display: inline as you have mentioned */
    left: 0px; /* added this line to position */
}

演示小提琴

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM