我正在 build 这个网站作为大学元素的一部分,我已经建立了我的导航下拉菜单,但是列表项的左侧有一种我似乎无法摆脱的溢出。我试过调整宽度和溢出,但我似乎无法在不破坏下拉菜单功能的情况下摆脱它,我们将不胜感激任何帮助。
不会让我张贴图片,但这里有一个链接:http://postimg.org/image/q4uo0sjfp/
这是CSS
@charset "UTF-8";
html {background:none;}
table{
width:100%;
}
table, th, td {
height:auto;
width:auto;
padding: none;
align: center;
}
.cf:before,
.cf:after {
content:"";
display:table;
}
.cf:after {
clear:both;
}
.cf {
zoom:1;
}
body {
font: 100% Arial, Helvetica, sans-serif;
line-height: 1.4;
width: 100%;
padding-bottom: 0;
background: 8BA0BB;
}
.wrapper{
min-height:100%;
height:100%;
height:auto;
width:auto;
}
h1, h2, h3 {
font-weight: normal;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.75);
color: #174D92;
}
h2 {
font-size: 4.4em;
font:100% Arial, Helvetica, sans-serif;
color:#174D92;
font-weight: bold;
}
header{
position:fixed;
width:100%;
height:206px;
max-width:100%;
max-height:100%;
float:left;
top:0;
left:0;
background:#ffffff;
z-index:999;
}
header img{
height:auto;
width:auto;
max-width:100%;
max-height:100%;
float:left;
}
nav {
height: 3.1em;
width:100%;
background:#174D92;
text-align:center;
position:fixed;
top:200px;
z-index:999;
}
div {
background:#7FB7FF;
margin: 2px;
border: 1px solid #174D92;
Border-radius:25px;
Padding: 2px 2px 2px 2px;
}
.insurers a img{
border: 1px solid #174D92;}
.insurers a:hover img{
border: 3px solid #174D92;
opacity:0.4;
}
div.textsmall{font-size: 85%}
ul, li {
float:left;
padding:none;
margin: 0;
list-style:none;
width: 20%;
height: auto;
text-align:center;
font-weight: bold;
}
ul {
background: #7FB7FF;
width:97.6%;
height:2.9em;
text-align: center;
vertical-align:central;
margin-top:.1em;
}
li {
position:relative;
}
li a {
display:block;
width: auto;
padding:none;
line-height:2.9em;
text-decoration:none;
color: #174D92;
}
li a:hover, .topmenu > li:hover > a{
background:#174D92;
color: #7FB7FF;
border-left: 1px solid black;
border-right: 1px solid black;
}
ul.topmenu{text-align:center;
}
ul.submenu {
background:#7FB7FF;
width: 100%;
height: auto;
float:none;
position:absolute;
top:2.9em;
left:10000em;
max-height: 0;
transition:max-height 1s ease-in-out;
-webkit-transition: max-height 1s ease-in-out;
-moz-transition: max-height 1s ease-in-out;
-o-transition: max-height 1s ease-in-out;
overflow:hidden;
z-index:999;
}
ul.submenu li {
padding: none;
float: none;
color: #174D92;
width: 100%;
height: auto;
z-index:999;
}
ul.topmenu li:hover ul{
Left:-40px;
max-height: 30em;
width: 100%;
}
ul.submenu li a {
border-bottom: 1px solid #8D8F92;
border-right: 0;
line-height:3em;
padding: none;
white-space: nowrap;
}
ul.submenu li a:hover {
background:#174D92;
color:#7FB7FF;
border-bottom: 1px solid #FFFFFF;
}
ul.submenu li:last-child a {
border-bottom: none;
}
ul.submenu li:first-child a {
padding: none;
}
.fadein { position:relative; width: auto; height: 545px; margin-top: 1em;}
.fadein img { position:absolute; left:0; top:0; border-radius:25px; border: 4px solid #174D92;}
iframe{
margin: 2px;
border: 1px solid #174D92;
}
.divtext{
width:60%;
text-align:center;
}
.aligncent{
align-content:center;
text-align:center;
}
.blank{
background:none;
border:none;
}
HTML
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<link href="index.css" rel="stylesheet" type="text/css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<title>Physio Central Dublin</title>
</head>
<div class="wrapper blank" style="height:auto; width:100%">
<header><img src="headerimg.png"></header>
</div>
<body>
<nav class="cf">
<ul class="topmenu">
<li><a href="index.html">Home</a></li>
<li><a href="Treatments.html" title="Treatments" class="current">Treatments</a>
<ul class="submenu">
<li><a href="Treatments.html#physio" title="Physiotherapy" class="current">Physiotherapy</a></li>
<li><a href="Treatments.html#acupuncture" title="Acupuncture" class="current">Acupuncture</a></li>
<li><a href="Treatments.html#sports" title="Sports Injury" class="current">Sports Injury</a></li>
<li><a href="Treatments.html#osteopathy" title="Osteopathy" class="current">Osteopathy</a></li>
<li><a href="Treatments.html#exercise" title="Exercise Therapy" class="current">Exercise Therapy</a></li>
<li><a href="Treatments.html#massage" title="Massage Therapy" class="current">Massage Therapy</a></li>
<li><a href="Treatments.html#orthotics" title="Orthotics" class="current">Orthotics</a></li>
<li><a href="Treatments.html#dryneed" title="Dry Needling" class="current">Dry Needling</a></li>
</ul>
</li>
<li><a href="Pricing.html" title="Pricing" class="current">Pricing</a>
<ul class="submenu">
<li><a href="Pricing.html" title="Pricing For Sessions" class="current">Pricing for sessions</a></li>
<li><a href="Pricing.html" title="Are you covered" class="current">Are you covered</a></li>
</ul>
</li>
<li><a href="About Us.html" title="Physiotherapy" class="current">About Us</a>
<ul class="submenu">
<li><a href="About Us.html" title="About Physio Central" class="current">About Physio Central</a></li>
<li><a href="Contact us.html" title="Opening Times" class="current">Opening Times</a></li>
<li><a href="Contact us.html" title="Location" class="current">Location</a></li>
<li><a href="About Us.html" title="Our People" class="current">Our People</a></li>
<li><a href="Contact us.html" title="Contact Us" class="current">Contact Us</a></li>
<li><a href="Testimonies.htm" title="Testimonies" class="current">Testimonies</a></li>
</ul>
</li>
<li><a href="FAQ.html" title="FAQ" class="current">FAQ</a>
<ul class="submenu">
<li><a href="FAQ.html" title="FAQ" class="current">FAQ</a></li>
</ul>
</li>
</ul>
</nav>
最佳答案
你只需要告诉 ul
有零填充。
ul.submenu {
background:#7FB7FF;
width: 100%;
height: auto;
max-height: 0;
transition:max-height 1s ease-in-out;
-webkit-transition: max-height 1s ease-in-out;
-moz-transition: max-height 1s ease-in-out;
-o-transition: max-height 1s ease-in-out;
overflow:hidden;
z-index:999;
padding: 0px;
}
如果您也删除绝对定位,那么它将直接放在您的菜单项下方,我想这也是您所追求的。
关于css - 下拉菜单上的 HTML5/CSS 溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29104346/