嘿伙计们我正在网站上工作,该网站有一些链接,如家,关于我们,联系我们,制药,兽医。现在,如果用户在产品链接上悬停,我希望它显示一个项目的下拉列表,其中选择将转到相应的页面。
这是我的html部分:
<ul id="menu">
<li><a href="index.html" class="current"><span></span>Home</a></li>
<li><a href="" target=""><span></span>CPPL Pharma</a>
<ul id="templatemo_menu"><li><a href=""><span></span>Category 1</a><ul><li><a href=""><span></span>Product 1</a></li><li><a href=""><span></span>Product 2</a></li><li><a href=""><span></span>Product 3</a></li></ul></li>
<li><a href=""><span></span>Category 2</a><ul><li><a href=""><span></span>Product 4</a></li><li><a href=""><span></span>Product 5</a></li><li><a href=""><span></span>Product 6</a></li></ul></li>
</ul></li>
<li><a href="" target=""><span></span>CPPL Vets</a></li>
<li><a href="aboutus.html"><span></span>About Us</a></li>
<li><a href="contactus.html"><span></span>Contact Us</a></li>
</ul>
这是我的css部分:
body {
margin: 0;
padding: 0;
line-height: 1.5em;
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
font-size: 11px;
color: #333333;
background: #ffffff;
}
a:link, a:visited { color: #0066CC; text-decoration: none; font-weight: normal; }
a:active, a:hover { color: #990000; text-decoration: underline; }
p { margin: 0px; padding: 0px; }
img { margin: 0px; padding: 0px; border: none; }
.cleaner { clear: both; width: 100%; height: 0px; font-size: 0px; }
.cleaner_h10 { clear: both; width:100%; height: 10px; }
.cleaner_h20 { clear: both; width:100%; height: 20px; }
.cleaner_h30 { clear: both; width:100%; height: 30px; }
.cleaner_h40 { clear: both; width:100%; height: 40px; }
.cleaner_h50 { clear: both; width:100%; height: 50px; }
.cleaner_h60 { clear: both; width:100%; height: 60px; }
.margin_r_20 { margin-right: 20px; }
.margin_r_40 { margin-right: 40px; }
.button_01 a {
clear: both;
display: block;
width: 57px;
height: 23px;
padding: 2px 5px 0 22px;
color: #333333;
font-size: 13px;
font-weight: bold;
text-align: center;
text-decoration: none;
background: url(images/button_01.jpg) no-repeat;
}
.button_01 a:hover {
color: #ffffff;
background: url(images/button_01_hover.jpg) no-repeat;
}
ul > li {
display:block;
float:left;
margin-right:10px;
position:relative;
padding:0.5em;
line-height:1em
}
ul ul {
display:none;
width:150px;
position:absolute;
top:2em;
left:0;
}
ul ul > li {
float:left;
}
ul > li:hover > ul,
ul > a:hover + ul {
display:block;
}
h1 {
margin: 0px;
padding: 2px 0;
font-size: 30px;
font-weight: bold;
}
h2 {
margin: 0 0 10px 0;
padding: 2px 0;
font-size: 24px;
line-height: 24px;
font-weight: bold;
color: #ba0808;
}
h3 {
margin: 0 0 5px 0;
padding: 5px 0;
font-size: 18px;
font-weight: normal;
color: #000000;
}
.image_wrapper {
margin-top: 3px;
margin-bottom: 5px;
border: 5px solid #e8e8e8;
padding: 1px;
background: #fff;
}
.fl_image {
float: left;
margin-right: 30px
}
.fr_image {
float: right;
margin-left: 20px
}
#site_title_bar_wrapper {
width: 100%;
height: 100px;
margin: 0 auto;
background: url(images/site_title_bg_wrapper.jpg) repeat-x top;
}
#site_title_bar {
width: 940px;
height: 100px;
margin: 0 auto;
padding: 0 20px;
background: url(images/site_title_bg.jpg) no-repeat top;
}
#site_title {
float: left;
width: 280px;
margin: 0px;
text-align: center;
padding: 30px 0 0 0;
}
#site_title h1 a {
margin: 0px;
padding: 0px;
font-size: 28px;
color: #ba0808;
font-weight: bold;
text-decoration: none;
}
#site_title h1 a:hover {
font-weight: bold;
text-decoration: none;
}
#site_title h1 a span {
display: block;
font-size: 13px;
color: #204567;
font-weight: bold;
margin-top: 10px;
margin-left: 5px;
letter-spacing: 2px;
}
#site_title_bar #menu {
float: right;
width: 540px;
height: 40px;
margin: 0;
padding: 10px 0 0 0;
list-style: none;
}
#menu li {
padding: 0px;
margin: 0px;
display: inline;
}
#menu li a {
position: relative;
float: left;
display: block;
width: 80px;
height: 24px;
padding: 6px 0 0 0;
margin: 0 0 0 10px;
font-size: 12px;
text-align: center;
font-weight: bold;
text-decoration: none;
color: #666666;
outline: none;
background: url(images/menu_bg_right.jpg) center right no-repeat;
}
#menu li a span {
position: absolute;
top: 0;
left: 0;
width: 5px;
height: 30px;
background: url(images/menu_bg_left.jpg) no-repeat;
}
#menu li a:hover, #menu li .current {
position: relative;
color: #ffffff;
background: url(images/menu_bg_right_hover.jpg) center right;
}
#menu li a:hover span, #menu li .current span {
position: absolute;
top: 0;
left: 0;
width: 5px;
height: 30px;
background: url(images/menu_bg_left_hover.jpg) no-repeat;
}
#site_title_bar #search_box {
float: right;
width: 280px;
height: 30px;
margin: 0 10px 0 0;
padding: 10px 0 0 0;
}
#search_box form {
float: left;
width: 280px;
height: 30px;
margin: 0;
padding: 0;
}
#searchfield {
height: 20px;
width: 195px;
padding: 3px 5px 3px 5px;
margin: 0px;
color: #666666;
font-size: 12px;
font-variant: normal;
line-height: normal;
background: #ffffff;
border: 1px solid #666666;
}
#searchbutton {
height: 30px;
width: 70px;
margin: 0px;
padding: 3px 0 9px 0;
cursor: pointer;
font-size: 12px;
font-weight: bold;
text-align: center;
vertical-align: bottom;
white-space: pre;
color: #2b3844;
}
#banner_wrapper_outter {
clear: both;
width: 100%;
height: 420px;
margin: 0 auto;
background: url(images/banner_bg_wrapper_outter.jpg) top repeat-x;
}
#banner_wrapper {
width: 100%;
height: 420px;
margin: 0 auto;
background: url(images/banner_bg_wrapper.jpg) no-repeat center top;
}
#banner {
width: 960px;
height: 410px;
padding: 0 10px;
margin: 0 auto;
background: url(images/banner_bg.jpg) no-repeat center top;
}
#banner_slider {
clear: both;
width: 960px;
height: 380px;
overflow: hidden;
margin-bottom: 10px;
padding: 70px 0 0 0;
background: none;
}
#content {
width: 940px;
margin: 0 auto;
padding: 30px 20px;
background: url(images/content_bg_middle.png) repeat-y center;
}
#content #twitter_section {
clear: both;
margin-bottom: 20px;
}
#content #twitter_section p {
float: left;
width: 800px;
font-size: 26px;
line-height: 34px;
color: #2a90c1;
}
#content #twitter_section .followme a {
display: block;
float: right;
width: 128px;
height: 128px;
background: url(images/twitter.png) no-repeat;
}
#content p {
margin-bottom: 10px;
}
.box {
float: left;
width: 270px;
padding: 0 29px 0 0;
}
.box_border {
border-right: 1px dotted #999;
}
.box h2 {
color: #9b1919;
font-size: 20px;
margin-bottom: 20px;
}
.box .box_image_wrapper {
float: left;
text-align: center;
margin-right: 20px;
}
.em_text {
font-size: 14px;
color: #000;
}
.section_w940 {
clear: both;
width: 940px;
}
.section_w450 {
float: left;
width: 450px;
}
.news_box{
margin-bottom: 10px;
border-bottom: 1px dashed #ccc;
color: #2f5e9e;
}
.news_box .post_info {
color: #666;
}
.news_box .post_info a {
color: #000000;
font-weight: bold;
}
.news_box .post_info strong {
color: #000000;
}
.news_box a {
color: #2f5e9e;
}
.testimonial {
font-style: italic;
}
#footer_wrapper {
width: 100%;
margin: 0 auto;
background: #677684 url(images/footer_bg.jpg) repeat-x top;
}
#footer {
width: 960px;
margin: 0 auto;
padding: 60px 10px 20px 10px;
color: #ffffff;
}
#footer a {
color: #ffffff;
}
#footer .section_w240 {
float: left;
width: 200px;
padding-right: 40px;
}
#footer .section_w240 h3 {
font-size:14px;
font-weight: bold;
color: #ffffff;
}
#footer .footer_list {
margin: 0px;
padding: 0px;
list-style: none;
}
#footer .footer_list li {
margin: 0px;
padding: 3px 0;
}
#footer .footer_list li a {
color: #ffffff;
}
#footer .footer_list li a:hover {
color: #FFFF00;
text-decoration: none;
}
这是我的问题截图:http://imageshack.com/a/img268/8717/3fsb.png
我希望类别2低于类别1,依此类推!该怎么做??
答案 0 :(得分:0)
查看此示例网站:http://csswizardry.com/demos/css-dropdown/
CSS:
/*------------------------------------*\
RESET
\*------------------------------------*/
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td{
margin:0;
padding:0;
}
table{
border-collapse:collapse;
border-spacing:0;
}
fieldset,img{
border:0;
}
address,caption,cite,code,dfn,th,var{
font-style:normal;
font-weight:normal;
}
caption,th{
text-align:left;
}
h1,h2,h3,h4,h5,h6{
font-size:100%;
font-weight:normal;
}
q:before,q:after{
content:'';
}
abbr,acronym{
border:0;
}
/*------------------------------------*\
MAIN
\*------------------------------------*/
html{
height:101%;
background:#fff url(/img/css/bg.gif) top left repeat-x;
}
body{
font-family:Arial,Verdana,sans-serif;
font-size:0.75em;
color:#333;
width:960px;
margin:0 auto;
padding:10px;
}
/*------------------------------------*\
NAV
\*------------------------------------*/
#nav{
list-style:none;
font-weight:bold;
margin-bottom:10px;
/* Clear floats */
float:left;
width:100%;
/* Bring the nav above everything else--uncomment if needed.
position:relative;
z-index:5;
*/
}
#nav li{
float:left;
margin-right:10px;
position:relative;
}
#nav a{
display:block;
padding:5px;
color:#fff;
background:#333;
text-decoration:none;
}
#nav a:hover{
color:#fff;
background:#6b0c36;
text-decoration:underline;
}
/*--- DROPDOWN ---*/
#nav ul{
background:#fff; /* Adding a background makes the dropdown work properly in IE7+. Make this as close to your page's background as possible (i.e. white page == white background). */
background:rgba(255,255,255,0); /* But! Let's make the background fully transparent where we can, we don't actually want to see it if we can help it... */
list-style:none;
position:absolute;
left:-9999px; /* Hide off-screen when not needed (this is more accessible than display:none;) */
}
#nav ul li{
padding-top:1px; /* Introducing a padding between the li and the a give the illusion spaced items */
float:none;
}
#nav ul a{
white-space:nowrap; /* Stop text wrapping and creating multi-line dropdown items */
}
#nav li:hover ul{ /* Display the dropdown on hover */
left:0; /* Bring back on-screen when needed */
}
#nav li:hover a{ /* These create persistent hover states, meaning the top-most link stays 'hovered' even when your cursor has moved down the list. */
background:#6b0c36;
text-decoration:underline;
}
#nav li:hover ul a{ /* The persistent hover state does however create a global style for links even before they're hovered. Here we undo these effects. */
text-decoration:none;
}
#nav li:hover ul li a:hover{ /* Here we define the most explicit hover states--what happens when you hover each individual link. */
background:#333;
}
h1{
font-family:Calibri, Arial, Verdana, sans-serif;
font-size:2em;
width:520px;
}
HTML:
<html><head><link href="css.css" rel="stylesheet" />
<body>
<ul id="nav">
<li>
<a href="#">Home</a>
</li>
<li>
<a href="#">About</a>
<ul>
<li><a href="#">The product</a></li>
<li><a href="#">Meet the team</a></li>
</ul>
</li>
<li>
<a href="#">Services</a>
<ul>
<li><a href="#">Sevice one</a></li>
<li><a href="#">Sevice two</a></li>
<li><a href="#">Sevice three</a></li>
<li><a href="#">Sevice four</a></li>
</ul>
</li>
<li>
<a href="#">Product</a>
<ul>
<li><a href="#">Small product (one)</a></li>
<li><a href="#">Small product (two)</a></li>
<li><a href="#">Small product (three)</a></li>
<li><a href="#">Small product (four)</a></li>
<li><a href="#">Big product (five)</a></li>
<li><a href="#">Big product (six)</a></li>
<li><a href="#">Big product (seven)</a></li>
<li><a href="#">Big product (eight)</a></li>
<li><a href="#">Enormous product (nine)</a></li>
<li><a href="#">Enormous product (ten)</a></li>
<li><a href="#">Enormous product (eleven)</a></li>
</ul>
</li>
<li>
<a href="#">Contact</a>
<ul>
<li><a href="#">Out-of-hours</a></li>
<li><a href="#">Directions</a></li>
</ul>
</li>
</ul></body></html>
答案 1 :(得分:0)
嗯,那家伙无论如何都回答了......这是完整的代码 (有几个标签要测试,保存为.html并亲自看看。祝你好运!):
<!--language:HTML -->
<html>
<head>
<style>
body {
margin: 0;
padding: 0;
line-height: 1.5em;
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
font-size: 11px;
color: #333333;
background: #000; /*CHANGE THIS BACKGROUND VALUE BACK TO: #FFF; */
}
a:link, a:visited { color: #0066CC; text-decoration: none; font-weight: normal; }
a:active, a:hover { color: #990000; text-decoration: underline; }
p { margin: 0px; padding: 0px; }
img { margin: 0px; padding: 0px; border: none; }
.cleaner { clear: both; width: 100%; height: 0px; font-size: 0px; }
.cleaner_h10 { clear: both; width:100%; height: 10px; }
.cleaner_h20 { clear: both; width:100%; height: 20px; }
.cleaner_h30 { clear: both; width:100%; height: 30px; }
.cleaner_h40 { clear: both; width:100%; height: 40px; }
.cleaner_h50 { clear: both; width:100%; height: 50px; }
.cleaner_h60 { clear: both; width:100%; height: 60px; }
.margin_r_20 { margin-right: 20px; }
.margin_r_40 { margin-right: 40px; }
.button_01 a {
clear: both;
display: block;
width: 57px;
height: 23px;
padding: 2px 5px 0 22px;
color: #333333;
font-size: 13px;
font-weight: bold;
text-align: center;
text-decoration: none;
background: url(images/button_01.jpg) no-repeat;
}
.button_01 a:hover {
color: #ffffff;
background: url(images/button_01_hover.jpg) no-repeat;
}
ul > li {
display:block;
float:left;
margin-right:10px;
position:relative;
padding:0.5em;
line-height:1em
}
ul ul {
display:none;
width:150px;
position:absolute;
top:2em;
left:0;
}
ul ul > li {
/* float:none; is pointless, just remove the float property, Add display: block; */
display:block;
}
ul > li:hover > ul,
ul > a:hover + ul {
display:block;
}
h1 {
margin: 0px;
padding: 2px 0;
font-size: 30px;
font-weight: bold;
}
h2 {
margin: 0 0 10px 0;
padding: 2px 0;
font-size: 24px;
line-height: 24px;
font-weight: bold;
color: #ba0808;
}
h3 {
margin: 0 0 5px 0;
padding: 5px 0;
font-size: 18px;
font-weight: normal;
color: #000000;
}
.image_wrapper {
margin-top: 3px;
margin-bottom: 5px;
border: 5px solid #e8e8e8;
padding: 1px;
background: #fff;
}
.fl_image {
float: left;
margin-right: 30px
}
.fr_image {
float: right;
margin-left: 20px
}
#site_title_bar_wrapper {
width: 100%;
height: 100px;
margin: 0 auto;
background: url(images/site_title_bg_wrapper.jpg) repeat-x top;
}
#site_title_bar {
width: 940px;
height: 100px;
margin: 0 auto;
padding: 0 20px;
background: url(images/site_title_bg.jpg) no-repeat top;
}
#site_title {
float: left;
width: 280px;
margin: 0px;
text-align: center;
padding: 30px 0 0 0;
}
#site_title h1 a {
margin: 0px;
padding: 0px;
font-size: 28px;
color: #ba0808;
font-weight: bold;
text-decoration: none;
}
#site_title h1 a:hover {
font-weight: bold;
text-decoration: none;
}
#site_title h1 a span {
display: block;
font-size: 13px;
color: #204567;
font-weight: bold;
margin-top: 10px;
margin-left: 5px;
letter-spacing: 2px;
}
#site_title_bar #menu {
float: right;
width: 540px;
height: 40px;
margin: 0;
padding: 10px 0 0 0;
list-style: none;
}
/* Added the > greater-than symbol to this CSS decleration below, as suggested by @chadocat */
#menu > li {
padding: 0px;
margin: 0px;
display: inline;
}
#menu li a {
position: relative;
float: left;
display: block;
width: 80px;
height: 24px;
padding: 6px 0 0 0;
margin: 0 0 0 10px;
font-size: 12px;
text-align: center;
font-weight: bold;
text-decoration: none;
color: #666666;
outline: none;
background: url(images/menu_bg_right.jpg) center right no-repeat;
}
#menu li a span {
position: absolute;
top: 0;
left: 0;
width: 5px;
height: 30px;
background: url(images/menu_bg_left.jpg) no-repeat;
}
#menu li a:hover, #menu li .current {
position: relative;
color: #ffffff;
background: url(images/menu_bg_right_hover.jpg) center right;
}
#menu li a:hover span, #menu li .current span {
position: absolute;
top: 0;
left: 0;
width: 5px;
height: 30px;
background: url(images/menu_bg_left_hover.jpg) no-repeat;
}
#site_title_bar #search_box {
float: right;
width: 280px;
height: 30px;
margin: 0 10px 0 0;
padding: 10px 0 0 0;
}
#search_box form {
float: left;
width: 280px;
height: 30px;
margin: 0;
padding: 0;
}
#searchfield {
height: 20px;
width: 195px;
padding: 3px 5px 3px 5px;
margin: 0px;
color: #666666;
font-size: 12px;
font-variant: normal;
line-height: normal;
background: #ffffff;
border: 1px solid #666666;
}
#searchbutton {
height: 30px;
width: 70px;
margin: 0px;
padding: 3px 0 9px 0;
cursor: pointer;
font-size: 12px;
font-weight: bold;
text-align: center;
vertical-align: bottom;
white-space: pre;
color: #2b3844;
}
#banner_wrapper_outter {
clear: both;
width: 100%;
height: 420px;
margin: 0 auto;
background: url(images/banner_bg_wrapper_outter.jpg) top repeat-x;
}
#banner_wrapper {
width: 100%;
height: 420px;
margin: 0 auto;
background: url(images/banner_bg_wrapper.jpg) no-repeat center top;
}
#banner {
width: 960px;
height: 410px;
padding: 0 10px;
margin: 0 auto;
background: url(images/banner_bg.jpg) no-repeat center top;
}
#banner_slider {
clear: both;
width: 960px;
height: 380px;
overflow: hidden;
margin-bottom: 10px;
padding: 70px 0 0 0;
background: none;
}
#content {
width: 940px;
margin: 0 auto;
padding: 30px 20px;
background: url(images/content_bg_middle.png) repeat-y center;
}
#content #twitter_section {
clear: both;
margin-bottom: 20px;
}
#content #twitter_section p {
float: left;
width: 800px;
font-size: 26px;
line-height: 34px;
color: #2a90c1;
}
#content #twitter_section .followme a {
display: block;
float: right;
width: 128px;
height: 128px;
background: url(images/twitter.png) no-repeat;
}
#content p {
margin-bottom: 10px;
}
.box {
float: left;
width: 270px;
padding: 0 29px 0 0;
}
.box_border {
border-right: 1px dotted #999;
}
.box h2 {
color: #9b1919;
font-size: 20px;
margin-bottom: 20px;
}
.box .box_image_wrapper {
float: left;
text-align: center;
margin-right: 20px;
}
.em_text {
font-size: 14px;
color: #000;
}
.section_w940 {
clear: both;
width: 940px;
}
.section_w450 {
float: left;
width: 450px;
}
.news_box{
margin-bottom: 10px;
border-bottom: 1px dashed #ccc;
color: #2f5e9e;
}
.news_box .post_info {
color: #666;
}
.news_box .post_info a {
color: #000000;
font-weight: bold;
}
.news_box .post_info strong {
color: #000000;
}
.news_box a {
color: #2f5e9e;
}
.testimonial {
font-style: italic;
}
#footer_wrapper {
width: 100%;
margin: 0 auto;
background: #677684 url(images/footer_bg.jpg) repeat-x top;
}
#footer {
width: 960px;
margin: 0 auto;
padding: 60px 10px 20px 10px;
color: #ffffff;
}
#footer a {
color: #ffffff;
}
#footer .section_w240 {
float: left;
width: 200px;
padding-right: 40px;
}
#footer .section_w240 h3 {
font-size:14px;
font-weight: bold;
color: #ffffff;
}
#footer .footer_list {
margin: 0px;
padding: 0px;
list-style: none;
}
#footer .footer_list li {
margin: 0px;
padding: 3px 0;
}
#footer .footer_list li a {
color: #ffffff;
}
#footer .footer_list li a:hover {
color: #FFFF00;
text-decoration: none;
}
</style>
</head>
<body>
<ul id="menu">
<li><a href="index.html" class="current"><span></span>Home</a></li>
<li><a href="" target=""><span></span>CPPL Pharma</a>
<ul id="templatemo_menu"><li><a href=""><span></span>Category 1</a><ul><li><a href=""><span></span>Product 1</a></li><li><a href=""><span></span>Product 2</a></li><li><a href=""><span></span>Product 3</a></li></ul></li>
<li><a href=""><span></span>Category 2</a><ul><li><a href=""><span></span>Product 4</a></li><li><a href=""><span></span>Product 5</a></li><li><a href=""><span></span>Product 6</a></li></ul></li>
</ul></li>
<li><a href="" target=""><span></span>CPPL Vets</a></li>
<li><a href="aboutus.html"><span></span>About Us</a></li>
<li><a href="contactus.html"><span></span>Contact Us</a></li>
</ul>
</body>
</html>