我正在使用具有子菜单的水平下拉菜单。 这个子菜单应该是垂直的,但它是水平的。 我在这个论坛上试过类似问题的解决方案,但他们不适合我。
* {
margin: 0;
padding: 0;
}
body{
font-family: 'Francois One', Arial, Helvetica, sans-serif;
color: white;
text-align:center;
}
.corpo{
margin-top: 5px;
margin-left: 20%;
margin-right: 15%;
float:middle;
}
header{
margin: 40px 0;
}
.menu li{
display: block;
float: left;
clear: right;
width: 10%;
height: 50px;
line-height: 50px;
text-align: center;
color: #2C3E50;
border-right: 1px solid #2C3E50;
background: -webkit-linear-gradient(top, #FFFF00 50%, #FFFF00 51%, #f6f6f6 100%);
background: -moz-linear-gradient(top, #FFFF00 50%, #FFFF00 51%, #f6f6f6 100%);
background: -o-linear-gradient(top, #FFFF00 50%, #FFFF00 51%, #f6f6f6 100%);
background: -ms-linear-gradient(top, #FFFF00 50%, #FFFF00 51%, #f6f6f6 100%);
border-color:black;
opacity:1;
position:relative;
}
.menu li:hover{
cursor: pointer;
background: -webkit-radial-gradient(center, ellipse cover, #ffffff 0%, #e5e5e5 100%);
background: -moz-radial-gradient(center, ellipse cover, #ffffff 0%, #e5e5e5 100%);
background: -o-radial-gradient(center, ellipse cover, #ffffff 0%, #e5e5e5 100%);
background: -ms-radial-gradient(center, ellipse cover, #ffffff 0%, #e5e5e5 100%);
color: slateGrey;
border-color:black;
position:relative;
}
.primo{
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
}
.ultimo{
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
}
.sub-menu{
visibility: hidden;
width: 1000%;
float:center;
}
.menu li:hover .sub-menu{
visibility: visible;
}
.menu li:hover .sub-menu li{
visibility: visible;
display:inline;
clear:left;
clear:right;
}
.sub-menu li{
border-top: 1px dotted #2C3E50;
}
.sub-menu li:hover{
width: 145px;
background: -webkit-radial-gradient(center, ellipse cover, #f7fbfc 10%, #add9e4 100%);
background: -moz-radial-gradient(center, ellipse cover, #f7fbfc 10%, #add9e4 100%);
background: -o-radial-gradient(center, ellipse cover, #f7fbfc 10%, #add9e4 100%);
background: -ms-radial-gradient(center, ellipse cover, #f7fbfc 10%, #add9e4 100%);
transition: all 0.1s ease 0s;
-webkit-transition: all 0.1s ease 0s;
-moz-transition: all 0.1s ease 0s;
-o-transition: all 0.1s ease 0s;
-ms-transition: all 0.1s ease 0s;
}
.ultimo-sub{
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
}
.menu li a:link{
color:black;
text-decoration:none;
}
.menu li a:hover{
color:black;
text-decoration:none;
}
.menu li a:active{
color:black;
text-decoration:none;
}
.menu ul li:hover ul{
position:relative;
display:block;
}
.menu li a:visited{
color:black;
text-decoration:none;
}
p{
color: #FFFF00;
margin: 0px 380px 0px 400px;
font-size:150%;
text-shadow: 2px 0 0 #000, 0 -1px 0 #000, 0 2px 0 #000, -1px 0 0 #000; //text-shadow: 2px 0 0 #000, 0 -1px 0 #000, 0 2px 0 #000, -1px 0 0 #000;
}
.Paragrafo{
text-shadow:1px 0 0 #000, 0 -1px 0 #000, 0 1px 0 #000, -1px 0 0 #000;
size:25px;
}
.Paragrafo a:link{
color:yellow;
}
.Paragrafo a:hover{
color:yellow;
}
.Paragrafo a:active{
color:yellow;
}
.Paragrafo a:visited{
color:yellow;
}
h1{
color:blue;
}
span{
color: #FFFF00;
margin: 0px 380px 0px 400px;
font-size:150%;
text-shadow: 2px 0 0 #000, 0 -1px 0 #000, 0 2px 0 #000, -1px 0 0 #000; //text-shadow: 2px 0 0 #000, 0 -1px 0 #000, 0 2px 0 #000, -1px 0 0 #000;
}
.video{
position: 404 532;
}

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Menù a tendina in HTML e CSS</title>
<link rel="stylesheet" type="text/css" href="new 1(!).css">
<style> h1 {color:yellow;
float:center;
} </style>
</head>
<body background="ww1.png" class="1">
<header>
<h1>La Grande Guerra</h1>
</header>
<div class="corpo">
<ul class="menu">
<li class="primo"><a href="SitoHome2(!).html">Home</a></li>
<li><a href="1914.html">1914</a>
</li>
<li><a href="1915.html">1915</a>
<ul class="sub-menu">
<li><a href="1915-1.html">Da 01 a 04</a></li>
<li><a href="1915-2.html">Da 05 a 08</a></li>
<li class="ultimo-sub"><a href="1915-3.html">Da 09 a 12</a></li>
</ul>
</li>
<li><a href="1916.html">1916</a>
<ul class="sub-menu">
<li><a href="1916-1.html">Da 01 a 04</a></li>
<li><a href="1916-2.html">Da 05 a 08</a></li>
<li class="ultimo-sub"><a href="1916-3.html">Da 09 a 12</a></li>
</ul>
</li>
<li><a href="1917.html">1917</a>
<ul class="sub-menu">
<li><a href="1917-1.html">Da 01 a 04</a></li>
<li><a href="1917-2.html">Da 05 a 08</a></li>
<li class="ultimo-sub"><a href="1917-3.html">Da 09 a 12</a></li>
</ul>
</li>
<li><a href="1918.html">1918</a>
<ul class="sub-menu">
<li class="ultimo-sub"><a href="1918-1.html">Eventi</a></li>
</ul>
</li>
<li><a href="#">Armistizio</a>
<ul class="sub-menu">
<li class="ultimo-sub"><a href="#">Conseguenze</a></li>
</ul>
</li>
<li><a href="Galleria.html">Galleria</a>
<ul class="sub-menu">
</ul>
</li>
<li class="ultimo"><a href="Fonti.html">Fonti</A></li>
</ul>
</div> <BR> <br> <br> <br> <br> <br> <br>
<div class=Paragrafi>
<p>
TEXT
<object class=video width="420" height="315"data="https://www.youtube.com/embed/6FgaL0xIazk?list=PLB2vhKMBjSxOb_127vxjaRRC7yu2TJlJX"
float=left align=right>
</object>
</p>
<p align=left>
Text
</p>
</body>
</html>
&#13;
答案 0 :(得分:0)
问题在于您的清晰财产。您正在使用clear:left;
覆盖clear:right;
。您应该使用clear: both;
代替
.menu li:hover .sub-menu li{
visibility: visible;
display:inline;
clear:left; /* this property gets overwritten by clear: right */
clear:right;
}
修复
.menu li:hover .sub-menu li{
visibility: visible;
display:inline;
clear:both;
}
* {
margin: 0;
padding: 0;
}
body {
font-family: 'Francois One', Arial, Helvetica, sans-serif;
color: white;
text-align: center;
}
.corpo {
margin-top: 5px;
margin-left: 20%;
margin-right: 15%;
float: middle;
}
header {
margin: 40px 0;
}
.menu li {
display: block;
float: left;
clear: right;
width: 10%;
height: 50px;
line-height: 50px;
text-align: center;
color: #2C3E50;
border-right: 1px solid #2C3E50;
background: -webkit-linear-gradient(top, #FFFF00 50%, #FFFF00 51%, #f6f6f6 100%);
background: -moz-linear-gradient(top, #FFFF00 50%, #FFFF00 51%, #f6f6f6 100%);
background: -o-linear-gradient(top, #FFFF00 50%, #FFFF00 51%, #f6f6f6 100%);
background: -ms-linear-gradient(top, #FFFF00 50%, #FFFF00 51%, #f6f6f6 100%);
border-color: black;
opacity: 1;
position: relative;
}
.menu li:hover {
cursor: pointer;
background: -webkit-radial-gradient(center, ellipse cover, #ffffff 0%, #e5e5e5 100%);
background: -moz-radial-gradient(center, ellipse cover, #ffffff 0%, #e5e5e5 100%);
background: -o-radial-gradient(center, ellipse cover, #ffffff 0%, #e5e5e5 100%);
background: -ms-radial-gradient(center, ellipse cover, #ffffff 0%, #e5e5e5 100%);
color: slateGrey;
border-color: black;
position: relative;
}
.primo {
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
}
.ultimo {
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
}
.sub-menu {
visibility: hidden;
width: 1000%;
float: center;
}
.menu li:hover .sub-menu {
visibility: visible;
}
.menu li:hover .sub-menu li {
visibility: visible;
display: inline;
clear: both;
}
.sub-menu li {
border-top: 1px dotted #2C3E50;
}
.sub-menu li:hover {
width: 145px;
background: -webkit-radial-gradient(center, ellipse cover, #f7fbfc 10%, #add9e4 100%);
background: -moz-radial-gradient(center, ellipse cover, #f7fbfc 10%, #add9e4 100%);
background: -o-radial-gradient(center, ellipse cover, #f7fbfc 10%, #add9e4 100%);
background: -ms-radial-gradient(center, ellipse cover, #f7fbfc 10%, #add9e4 100%);
transition: all 0.1s ease 0s;
-webkit-transition: all 0.1s ease 0s;
-moz-transition: all 0.1s ease 0s;
-o-transition: all 0.1s ease 0s;
-ms-transition: all 0.1s ease 0s;
}
.ultimo-sub {
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
}
.menu li a:link {
color: black;
text-decoration: none;
}
.menu li a:hover {
color: black;
text-decoration: none;
}
.menu li a:active {
color: black;
text-decoration: none;
}
.menu ul li:hover ul {
position: relative;
display: block;
}
.menu li a:visited {
color: black;
text-decoration: none;
}
p {
color: #FFFF00;
margin: 0px 380px 0px 400px;
font-size: 150%;
text-shadow: 2px 0 0 #000, 0 -1px 0 #000, 0 2px 0 #000, -1px 0 0 #000; //text-shadow: 2px 0 0 #000, 0 -1px 0 #000, 0 2px 0 #000, -1px 0 0 #000;
}
.Paragrafo {
text-shadow: 1px 0 0 #000, 0 -1px 0 #000, 0 1px 0 #000, -1px 0 0 #000;
size: 25px;
}
.Paragrafo a:link {
color: yellow;
}
.Paragrafo a:hover {
color: yellow;
}
.Paragrafo a:active {
color: yellow;
}
.Paragrafo a:visited {
color: yellow;
}
h1 {
color: blue;
}
span {
color: #FFFF00;
margin: 0px 380px 0px 400px;
font-size: 150%;
text-shadow: 2px 0 0 #000, 0 -1px 0 #000, 0 2px 0 #000, -1px 0 0 #000; //text-shadow: 2px 0 0 #000, 0 -1px 0 #000, 0 2px 0 #000, -1px 0 0 #000;
}
.video {
position: 404 532;
}
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Menù a tendina in HTML e CSS</title>
<link rel="stylesheet" type="text/css" href="new 1(!).css">
<style>
h1 {
color: yellow;
float: center;
}
</style>
</head>
<body background="ww1.png" class="1">
<header>
<h1>La Grande Guerra</h1>
</header>
<div class="corpo">
<ul class="menu">
<li class="primo"><a href="SitoHome2(!).html">Home</a>
</li>
<li><a href="1914.html">1914</a>
</li>
<li><a href="1915.html">1915</a>
<ul class="sub-menu">
<li><a href="1915-1.html">Da 01 a 04</a>
</li>
<li><a href="1915-2.html">Da 05 a 08</a>
</li>
<li class="ultimo-sub"><a href="1915-3.html">Da 09 a 12</a>
</li>
</ul>
</li>
<li><a href="1916.html">1916</a>
<ul class="sub-menu">
<li><a href="1916-1.html">Da 01 a 04</a>
</li>
<li><a href="1916-2.html">Da 05 a 08</a>
</li>
<li class="ultimo-sub"><a href="1916-3.html">Da 09 a 12</a>
</li>
</ul>
</li>
<li><a href="1917.html">1917</a>
<ul class="sub-menu">
<li><a href="1917-1.html">Da 01 a 04</a>
</li>
<li><a href="1917-2.html">Da 05 a 08</a>
</li>
<li class="ultimo-sub"><a href="1917-3.html">Da 09 a 12</a>
</li>
</ul>
</li>
<li><a href="1918.html">1918</a>
<ul class="sub-menu">
<li class="ultimo-sub"><a href="1918-1.html">Eventi</a>
</li>
</ul>
</li>
<li><a href="#">Armistizio</a>
<ul class="sub-menu">
<li class="ultimo-sub"><a href="#">Conseguenze</a>
</li>
</ul>
</li>
<li><a href="Galleria.html">Galleria</a>
<ul class="sub-menu">
</ul>
</li>
<li class="ultimo"><a href="Fonti.html">Fonti</A>
</li>
</ul>
</div>
<BR>
<br>
<br>
<br>
<br>
<br>
<br>
<div class=Paragrafi>
<p>
TEXT
<object class=video width="420" height="315" data="https://www.youtube.com/embed/6FgaL0xIazk?list=PLB2vhKMBjSxOb_127vxjaRRC7yu2TJlJX" float=left align=right>
</object>
</p>
<p align=left>
Text
</p>
</body>
</html>
额外备注:没有float: center;
或float: middle;
这样的内容,请参阅float docs on mdn
您还没有正确使用position
,请参阅position docs on mdn