我正在尝试自定义CSS3 Mega下拉菜单,似乎我无法弄明白。我想要的只是从主页面左侧显示的超级下拉菜单,如从主页按钮区域开始一直到结束。目前它显示父菜单所在的位置,并且一直显示在页面右边框之外。请帮忙。这是我的代码:
body,
ul,
li {
font-size: 14px;
font-family: Arial, Helvetica, sans-serif;
line-height: 21px;
text-align: left;
}
#menu {
list-style: none;
width: 940px;
margin: 30px auto 0px auto;
height: 43px;
padding: 0px 20px 0px 20px;
/* Rounded Corners */
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
/* Background color and gradients */
background: #014464;
background: -moz-linear-gradient(top, #0272a7, #013953);
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#0272a7), to(#013953));
/* Borders */
border: 1px solid #002232;
-moz-box-shadow: inset 0px 0px 1px #edf9ff;
-webkit-box-shadow: inset 0px 0px 1px #edf9ff;
box-shadow: inset 0px 0px 1px #edf9ff;
}
#menu li {
float: left;
display: inline-block;
text-align: center;
position: relative;
padding: 4px 10px 4px 10px;
margin-right: 30px;
margin-top: 7px;
border: none;
}
#menu li:hover {
border: 1px solid #777777;
padding: 4px 9px 4px 9px;
/* Background color and gradients */
background: #F4F4F4;
background: -moz-linear-gradient(top, #F4F4F4, #EEEEEE);
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#F4F4F4), to(#EEEEEE));
/* Rounded corners */
-moz-border-radius: 5px 5px 0px 0px;
-webkit-border-radius: 5px 5px 0px 0px;
border-radius: 5px 5px 0px 0px;
}
#menu li a {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
color: #EEEEEE;
display: block;
outline: 0;
text-decoration: none;
text-shadow: 1px 1px 1px #000;
}
#menu li:hover a {
color: #161616;
text-shadow: 1px 1px 1px #ffffff;
}
#menu li .drop {
padding-right: 21px;
background: url("img/drop.png") no-repeat right 8px;
}
#menu li:hover .drop {
background: url("img/drop.png") no-repeat right 7px;
}
.dropdown_1column,
.dropdown_2columns,
.dropdown_3columns,
.dropdown_4columns,
.dropdown_5columns,
.dropdown_6columns {
margin: 4px auto;
float: left;
position: absolute;
left: -999em;
/* Hides the drop down */
text-align: left;
padding: 10px 5px 10px 5px;
border: 1px solid #777777;
border-top: none;
/* Gradient background */
background: #F4F4F4;
background: -moz-linear-gradient(top, #EEEEEE, #BBBBBB);
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#EEEEEE), to(#BBBBBB));
/* Rounded Corners */
-moz-border-radius: 0px 5px 5px 5px;
-webkit-border-radius: 0px 5px 5px 5px;
border-radius: 0px 5px 5px 5px;
}
.dropdown_1column {
width: 140px;
}
.dropdown_2columns {
width: 280px;
}
.dropdown_3columns {
width: 420px;
}
.dropdown_4columns {
width: 560px;
}
.dropdown_5columns {
width: 700px;
}
.dropdown_6columns {
width: 900px;
}
#menu li:hover .dropdown_1column,
#menu li:hover .dropdown_2columns,
#menu li:hover .dropdown_3columns,
#menu li:hover .dropdown_4columns,
#menu li:hover .dropdown_5columns,
#menu li:hover .dropdown_6columns {
left: -1px;
top: auto;
}
.col_1,
.col_2,
.col_3,
.col_4,
.col_5,
.col_6 {
display: inline;
float: left;
position: relative;
margin-left: 5px;
margin-right: 5px;
}
.col_1 {
width: 130px;
}
.col_2 {
width: 270px;
}
.col_3 {
width: 410px;
}
.col_4 {
width: 550px;
}
.col_5 {
width: 690px;
}
.col_6 {
width: 890px;
}
#menu .menu_right {
float: right;
margin-right: 0px;
}
#menu li .align_right {
/* Rounded Corners */
-moz-border-radius: 5px 0px 5px 5px;
-webkit-border-radius: 5px 0px 5px 5px;
border-radius: 5px 0px 5px 5px;
}
#menu li:hover .align_right {
left: auto;
right: -1px;
top: auto;
}
#menu p,
#menu h2,
#menu h3,
#menu ul li {
font-family: Arial, Helvetica, sans-serif;
line-height: 21px;
font-size: 12px;
text-align: left;
text-shadow: 1px 1px 1px #FFFFFF;
}
#menu h2 {
font-size: 21px;
font-weight: 400;
letter-spacing: -1px;
margin: 7px 0 14px 0;
padding-bottom: 14px;
border-bottom: 1px solid #666666;
}
#menu h3 {
font-size: 14px;
margin: 7px 0 14px 0;
padding-bottom: 7px;
border-bottom: 1px solid #888888;
}
#menu p {
line-height: 18px;
margin: 0 0 10px 0;
}
#menu li:hover div a {
font-size: 12px;
color: #015b86;
}
#menu li:hover div a:hover {
color: #029feb;
}
.strong {
font-weight: bold;
}
.italic {
font-style: italic;
}
.imgshadow {
/* Better style on light background */
background: #FFFFFF;
padding: 4px;
border: 1px solid #777777;
margin-top: 5px;
-moz-box-shadow: 0px 0px 5px #666666;
-webkit-box-shadow: 0px 0px 5px #666666;
box-shadow: 0px 0px 5px #666666;
}
.img_left {
/* Image sticks to the left */
width: auto;
float: left;
margin: 5px 15px 5px 5px;
}
#menu li .black_box {
background-color: #333333;
color: #eeeeee;
text-shadow: 1px 1px 1px #000;
padding: 4px 6px 4px 6px;
/* Rounded Corners */
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
/* Shadow */
-webkit-box-shadow: inset 0 0 3px #000000;
-moz-box-shadow: inset 0 0 3px #000000;
box-shadow: inset 0 0 3px #000000;
}
#menu li ul {
list-style: none;
padding: 0;
margin: 0 0 12px 0;
}
#menu li ul li {
font-size: 12px;
line-height: 24px;
position: relative;
text-shadow: 1px 1px 1px #ffffff;
padding: 0;
margin: 0;
float: none;
text-align: left;
width: 130px;
}
#menu li ul li:hover {
background: none;
border: none;
padding: 0;
margin: 0;
}
#menu li .greybox li {
background: #F4F4F4;
border: 1px solid #bbbbbb;
margin: 0px 0px 4px 0px;
padding: 4px 6px 4px 6px;
width: 116px;
/* Rounded Corners */
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
-khtml-border-radius: 5px;
border-radius: 5px;
}
#menu li .greybox li:hover {
background: #ffffff;
border: 1px solid #aaaaaa;
padding: 4px 6px 4px 6px;
margin: 0px 0px 4px 0px;
}

<div style=" background-color:#C80BE0; height:95px; border-bottom:#999 1px solid;">
<table width="950" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="95">
<a href="http://<?php echo $dyn_www; ?>">
<img src="images/logo2.png" alt="edu connex" width="90" height="90" border="0" />
</a>
</td>
<td width="180">
<div align="right" style="margin-bottom:12px;">
<?php echo $logOptions; ?>
</div>
</td>
</tr>
</table>
</div>
<div style=" margin-top: -25px;">
<td width="638">
<link rel="stylesheet" href="menu.css" type="text/css" media="screen" />
<!--[if IE 6]>
<style>
body {behavior: url("csshover3.htc");}
</style>
<![endif]-->
<ul id="menu">
<li><a href="http://www.educonx.net" class="drop">Home</a>
<!-- Begin Home Item -->
<div class="dropdown_2columns">
<!-- Begin 2 columns container -->
<div class="col_2">
<h2>Hello!</h2>
</div>
<div class="col_2">
<p>Welcome to Edu Connex Website! Here you can explore all the information you need for admission to a foreign university. You can upload your profile and make yourself visible to hundreds of institutions.</p>
<p>Once you are registered, you can choose to receive information periodically regarding offers and discounts from various institutions all over the world. Once you decide where and what you want to study, we will help you go through the admission
process free of charge. Our unique online tool makes the admission process faster and smoother.</p>
</div>
<div class="col_2">
<h2>Edu Connex @ Social Media</h2>
</div>
<div class="col_1">
<a href="http://www.facebook.com/Educonx" target="_blank">
<img src="img/browsers.png" width="125" height="48" alt="" border="0px" />
</a>
</div>
<div class="col_1">
<a href="https://twitter.com/educonnex" target="_blank">
<img src="img/twitter.png" width="125" height="48" alt="" border="0px" />
</a>
</div>
</div>
<!-- End 2 columns container -->
</li>
<!-- End Home Item -->
<li><a href="http://www.educonx.net/about.php" class="drop">About EC</a>
<!-- Begin 5 columns Item -->
<div class="dropdown_5columns">
<!-- Begin 5 columns container -->
<div class="col_5">
<h2> Edu Connex For Students</h2>
</div>
<div class="col_1">
<p class="black_box">Edu Connex is a global company specializing in foreign student placement services including, but not limited to, higher education and language studies.</p>
</div>
<div class="col_1">
<p>Edu Connex assists every student uniquely depending upon his/her needs and aspiration to find a perfect match of institute and desired courses within the limit of his/her budget.</p>
</div>
<div class="col_1">
<p class="italic">The Edu Connex portal is designed in such a way that eliminates the time-consuming paperwork by having a student's profile readily available to the school system.</p>
</div>
<div class="col_1">
<p>No Service Charge For Student ! Yes, you heard it right. We do not charge our students for services.Just register, and complete your profile.We will help you with the rest.</p>
</div>
<div class="col_1">
<p class="strong">Why Us? Well, we do not just get you admitted to a foreign institute, we make sure you are in the right place. We evaluate every client we deal with, whether you are a student or an institute.</p>
</div>
<div class="col_5">
<h2>Edu Connex For Institutions</h2>
</div>
<div class="col_3">
<img src="img/01.jpg" width="70" height="70" class="img_left imgshadow" alt="" />
<p>Edu Connex provides customized services to institutions. Our unique method of selecting qualified students gives an extra advantage to institutions for faster admission process..<a href="http://www.educonx.net/about.php">Read more...</a>
</p>
<img src="img/02.jpg" width="70" height="70" class="img_left imgshadow" alt="" />
<p>Edu Connex provides customized services to institutions. Our unique method of selecting qualified students gives an extra advantage to institutions for faster admission process.<a href="http://www.educonx.net/about.php">Read more...</a>
</p>
</div>
<div class="col_2">
<p class="black_box"><span class="italic">Edu Connex also provides services to institutions, representing them in various education fairs and seminars, cutting the expense almost in half. Check out our express representation packages</span>
</p>
</div>
</div>
<!-- End 5 columns container -->
</li>
<!-- End 5 columns Item -->
<li><a href="#" class="drop">Tests</a>
<!-- Begin 4 columns Item -->
<div class="dropdown_6columns">
<!-- Begin 4 columns container -->
<div class="col_6">
<h2>Information Portal For Student</h2>
</div>
<div class="col_1">
<h3>Check your level</h3>
<ul>
<li><a href="#">Schools</a>
</li>
<li><a href="#">Language Schools</a>
</li>
<li><a href="#">General</a>
</li>
</ul>
</div>
<div class="col_1">
<h3>IELTS</h3>
<ul>
<li><a href="#">Academic Reading</a>
</li>
<li><a href="#">Academic Writing</a>
</li>
<li><a href="#">General Reading</a>
</li>
<li><a href="#">General Writing</a>
</li>
<li><a href="#">Listening</a>
</li>
</ul>
</div>
<div class="col_1">
<h3>End of Lesson Test</h3>
<ul>
<li><a href="#">a</a>
</li>
<li><a href="#">b</a>
</li>
<li><a href="#">C</a>
</li>
<li><a href="#">d</a>
</li>
<li><a href="#">e</a>
</li>
</ul>
</div>
<div class="col_1">
<h3>Young Learners</h3>
<ul>
<li><a href="#">a</a>
</li>
<li><a href="#">b</a>
</li>
<li><a href="#">c</a>
</li>
<li><a href="#">d</a>
</li>
<li><a href="#">e</a>
</li>
</ul>
</div>
</div>
<!-- End 4 columns container -->
</li>
<!-- End 4 columns Item -->
<li><a href="#" class="drop">Resources</a>
<!-- Begin 6 columns Item -->
<div class="dropdown_6columns">
<!-- Begin 6 columns container -->
<div class="col_6">
<h2>Information For Institution</h2>
</div>
<div class="col_1">
<h3>Schools</h3>
<ul>
<li><a href="#">English Medium</a>
</li>
<li><a href="#">English Version</a>
</li>
<li><a href="#">Bengali Medium</a>
</li>
<li><a href="#">International</a>
</li>
<li><a href="#">Other</a>
</li>
</ul>
</div>
<div class="col_1">
<h3>Language Schools</h3>
<ul>
<li><a href="#">A1</a>
</li>
<li><a href="#">A2</a>
</li>
<li><a href="#">B1</a>
</li>
<li><a href="#">B2</a>
</li>
<li><a href="#">C1</a>
</li>
<li><a href="#">C2</a>
</li>
</ul>
</div>
<div class="col_1">
<h3>IELTS</h3>
<ul>
<li><a href="#">Academic Reading</a>
</li>
<li><a href="#">Academic Writing</a>
</li>
<li><a href="#">General Reading</a>
</li>
<li><a href="#">General Writing</a>
</li>
<li><a href="#">Listening</a>
</li>
<li><a href="#">Speaking</a>
</li>
</ul>
</div>
<div class="col_1">
<h3>Business</h3>
<ul>
<li><a href="#">Writing</a>
</li>
<li><a href="#">Speaking</a>
</li>
<li><a href="#">Other</a>
</li>
<li><a href="#">Other</a>
</li>
<li><a href="#">Other</a>
</li>
</ul>
</div>
<div class="col_1">
<h3>Skills</h3>
<ul>
<li><a href="#">Speaking</a>
</li>
<li><a href="#">Reading</a>
</li>
<li><a href="#">Writing</a>
</li>
<li><a href="#">Listening</a>
</li>
<li><a href="#">Vocabulary</a>
</li>
<li><a href="#">Grammar</a>
</li>
<li><a href="#">Pronunciation</a>
</li>
</ul>
</div>
<div class="col_1">
<h3>CLIL</h3>
<ul>
<li><a href="#">Arts and Crafts</a>
</li>
<li><a href="#">Science</a>
</li>
<li><a href="#">Geography</a>
</li>
<li><a href="#">Moral Science</a>
</li>
<li><a href="#">History</a>
</li>
<li><a href="#">Mathematics</a>
</li>
</ul>
</div>
<div class="col_1">
<h3>Tools</h3>
<ul>
<li><a href="#">Flashcard</a>
</li>
<li><a href="#">Dictionary</a>
</li>
<li><a href="#">Word Search Puzzle</a>
</li>
<li><a href="#">Cross Word Puzzle</a>
</li>
<li><a href="#">Worksheet</a>
</li>
<li><a href="#">Coloring Page</a>
</li>
<li><a href="#">Stories</a>
</li>
</ul>
</div>
</div>
<!-- End 4 columns container -->
</li>
<!-- End 4 columns Item -->
<li class="menu_right"><a href="#" class="drop">Contact</a>
<div class="dropdown_1column align_right">
<div class="col_1">
<ul class="simple">
<li><a href="http://www.educonx.net/contact.php">Cotact US</a>
</li>
<li><a href="http://www.educonx.net/requestinfo.php">Request Info</a>
</li>
</ul>
</div>
</div>
</li>
<li class="menu_right"><a href="#" class="drop">Corporate</a>
<div class="dropdown_1column align_right">
<div class="col_1">
<ul class="simple">
<li><a href="#">GRZ Global</a>
</li>
<li><a href="#">EC Partners</a>
</li>
<li><a href="#">EC Franchise</a>
</li>
<li><a href="#">Be Part of US</a>
</li>
<li><a href="#">More...</a>
</li>
</ul>
</div>
</div>
</li>
<li class="menu_right"><a href="#" class="drop">Visa</a>
<!-- Begin 3 columns Item -->
<div class="dropdown_3columns align_right">
<!-- Begin 3 columns container -->
<div class="col_3">
<h2>Visa Information For Students</h2>
</div>
<div class="col_1">
<ul class="greybox">
<li><a href="#">USA</a>
</li>
<li><a href="#">UK</a>
</li>
<li><a href="http://www.educonx.net/canada.php">Canada</a>
</li>
<li><a href="#">Australia</a>
</li>
<li><a href="#">Switzerland</a>
</li>
</ul>
</div>
<div class="col_1">
<ul class="greybox">
<li><a href="#">Malaysia</a>
</li>
<li><a href="#">Singapore</a>
</li>
<li><a href="#">Philippine</a>
</li>
<li><a href="#">China</a>
</li>
<li><a href="#">Japan</a>
</li>
</ul>
</div>
<div class="col_1">
<ul class="greybox">
<li><a href="#">India</a>
</li>
<li><a href="#">Ireland</a>
</li>
<li><a href="#">Sweeden</a>
</li>
<li><a href="#">Russia</a>
</li>
<li><a href="#">More...</a>
</li>
</ul>
</div>
<div class="col_3">
<h2>Student Visa Process</h2>
</div>
<div class="col_3">
<img src="img/02.jpg" width="70" height="70" class="img_left imgshadow" alt="" />
<p>Maecenas eget eros lorem, nec pellentesque lacus. Aenean dui orci, rhoncus sit amet tristique eu, tristique sed odio. Praesent ut interdum elit. Maecenas imperdiet, nibh vitae rutrum vulputate, lorem sem condimentum.<a href="#">Read more...</a>
</p>
<img src="img/01.jpg" width="70" height="70" class="img_left imgshadow" alt="" />
<p>Aliquam elementum felis quis felis consequat scelerisque. Fusce sed lectus at arcu mollis accumsan at nec nisi. Aliquam pretium mollis fringilla. Vestibulum tempor facilisis malesuada. <a href="#">Read more...</a>
</p>
</div>
</div>
<!-- End 3 columns container -->
</li>
<!-- End 3 columns Item -->
</ul>
</td>
</div>
&#13;
答案 0 :(得分:1)
您希望在#menu亲戚身上进行定位,而不是在父菜单项上进行定位。
#menu {
position:relative;
}
#menu > li {
position:static;
}
#menu > li:hover > div {
width: 100%;
box-sizing: border-box; // so that your defined padding eats into the 100% width and doesn't add to it.
}
所以你应该采用上面的样式并使用它来更新你当前的css选择器,而不是仅仅将它添加到css的底部,就像我在这里用于演示目的。
此外,如果您希望所有下拉列表都是全宽的,我不会看到您当前命名约定的重点,例如; .dropdown_1column, .dropdown_2columns, .dropdown_3columns, .dropdown_4columns, .dropdown_5columns, .dropdown_6columns
。所以你可能也想更新它们。