我有一个包含div的标题。在div中我已经使用CSS放置了一个背景图像。在这个div中我已经放了我的logo div。现在每件事都没问题。现在我要添加一个dropdownmenu 40px远离徽标,但问题是我想要添加的任何内容正在下降到标题..我无法追查..
这是我的HTML ..
<div class="header-wrapper">
<div class="header">
<div class="logo"> <img src="image/logo.png" alt="logo"/>
</div>
</div>
</div>
这是我的CSS ..
html, body {
color: #6F6F6F;
font-family: Trebuchet MS;
font-size: 0.75em;
margin: 0 auto;
width: 100%;
padding: 0px !important; }
.img {
border: 0 none; }
.header-wrapper {
background: url("../image/header_bg.png") repeat-x scroll 0 0 rgba(0, 0, 0, 0);
float: left;
height: 77px;
margin: 0 auto;
position: fixed;
width: 100%;
z-index: 60001; }
.header {
clear: both;
height: 77px;
margin: 0 auto;
padding: 0 20px;
width: 960px; }
.logo {
float: left;
height: 75px;
margin: 1px 49px 0 0;
width: 75px; }
这是我想要添加的HTML下拉代码..
<div class='menu'>
<a class='hover-link'>Hover on Menu</a>
<div class='sub'>
<ul class='sub-options'>
<li><a href='#'>Home</a></li>
<li><a href='#'>About</a></li>
<li><a href='#'>Services</a></li>
<li><a href='#'>Contact</a></li>
</ul>
</div>
</div>
这是我的CSS ..
<style type="text/css">
a{
text-decoration: none;
}
.menu{
font-family: Arial;
color: #515151;
width: 200px;
position: relative;
height: 40px;
text-align:left;
width: 202px;
margin: 0 auto;
}
.menu li a{
color: #515151;
display: block;
padding: 6px 15px;
cursor: pointer;
font-size: 14px;
}
.menu li a:hover{
background: #f44141;
color: #fff;
}
.sub{
background: #fff;
position: absolute;
z-index: 2;
width: 200px;
padding: 40px 0 3px;
border-radius: 3px;
box-shadow: 0 2px 4px #ddd;
border: 1px solid #ddd;
display: none;
}
a.hover-link{
width: 190px;
background: #fff;
font-size: 14px;
color: #515151;
position: absolute;
z-index: 110;
display: block;
padding: 10px 0 1px 10px;
height: 28px;
cursor:pointer;
border-radius: 5px 5px 0 0;
font-weight: bold;
border: 1px solid #ddd;
}
.sub-options{
list-style:none;
margin:0px;
padding:0px;
font-size: 11px;
}
</style>
这是小提琴i,我想在徽标图像旁边的下拉菜单,而不是它正在下方...
请帮帮我..
答案 0 :(得分:1)
你必须改变如下 在html页面
<div class="header-wrapper">
<div class="header">
<div class="logo">
<img src="image/logo.png" alt="logo" /></div>
<div class='menu'>
<a class='hover-link'>Hover on Menu</a>
<div class='sub'>
<ul class='sub-options'>
<li><a href='#'>Home</a>
</li>
<li><a href='#'>About</a>
</li>
<li><a href='#'>Services</a>
</li>
<li><a href='#'>Contact</a>
</li>
</ul>
</div>
</div>
</div>
</div>
在菜单css中添加float
float:left;
并将菜单css中的边距设置为
margin: 0 auto 0 -40px;
希望这会对你有所帮助。
答案 1 :(得分:0)
http://fiddle.jshell.net/T8snP/2/
您需要将菜单移出徽标div ... HTML:
<div class="header-wrapper">
<div class="header">
<div class="logo">
<img src="image/logo.png" alt="logo" />
</div>
<div class='menu'>
<a class='hover-link'>Hover on Menu</a>
<div class='sub'>
<ul class='sub-options'>
<li><a href='#'>Home</a>
</li>
<li><a href='#'>About</a>
</li>
<li><a href='#'>Services</a>
</li>
<li><a href='#'>Contact</a>
</li>
</ul>
</div>
</div>
</div>
</div>
然后按照评论中的建议使用此CSS浮动菜单div:
.menu {float: left;}
答案 2 :(得分:0)
HTML
<div class="header-wrapper">
<div class="header">
<div class="logo"> <img width="100%" height="100%" src="http://i.stack.imgur.com/3Gtg9.jpg" alt="logo"/></div>
<div class='menu'>
<a class='hover-link'>Hover on Menu</a>
<div class='sub'>
<ul class='sub-options'>
<li><a href='#'>Home</a></li>
<li><a href='#'>About</a></li>
<li><a href='#'>Services</a></li>
<li><a href='#'>Contact</a></li>
</ul>
</div>
</div>
</div>
</div>
要更改的CSS ......
.menu{
font-family: Arial;
color: #515151;
width: 200px;
position: relative;
height: 40px;
text-align:left;
width: 202px;
margin-left:40px;
}
这是A DEMO
答案 3 :(得分:0)
margin-left:40px;
<div class="header-wrapper">
<div class="header">
<div class="logo">
<img src="image/logo.png" alt="logo" />
</div>
<div class='menu'>
<a class='hover-link'>Hover on Menu</a>
<div class='sub'>
<ul class='sub-options'>
<li><a href='#'>Home</a>
</li>
<li><a href='#'>About</a>
</li>
<li><a href='#'>Services</a>
</li>
<li><a href='#'>Contact</a>
</li>
</ul>
</div>
</div>
</div>
你的菜单不起作用?你有菜单代码吗?检查我的代码:http://fiddle.jshell.net/T8snP/5/
$('.menu').click(function(){
var curDd = $(".sub");
var dur = 350;
if(curDd.hasClass('shown')){
curDd.fadeOut(dur/2);
curDd.removeClass('shown');
} else {
curDd.css({ opacity: 0.01, marginTop: 20 }).show().animate({ opacity: 1, marginTop: 0 }, { duration: 250, easing: "easeOutQuad" });
curDd.addClass('shown');
}
return false;
});
$('body, html').click(function(){
$('.shown').fadeOut(250).removeClass('shown');
});