2013-10-03 47 views
-1

我有这个CSS代码为我horiontal菜单:化妆的CSS菜单浮动权

.nav-wrap { 
    float:right; 
} 

/* Clearfix */ 
.group:after { visibility: hidden; display: block; content: ""; clear: both; height: 0; } 
*:first-child+html .group { zoom: 1; } /* IE7 */ 

/* Example One */ 
#example-one { 
    margin: 0 auto; 
    list-style: none; 
    position: relative; 
    width: 960px; 
} 
#example-one li { 
    display: inline-block; 
} 
#example-one a { 
    color: #ffffff; 
    font-size: 14px; 
    float: left; 
    padding: 6px 10px 4px 10px; 
    text-decoration: none; 
    text-transform: uppercase; 
} 
#example-one a:hover { 
    color: #000000; 
} 
#magic-line { 
    position: absolute; 
    bottom: -2px; 
    left: 0; 
    width: 100px; 
    height: 4px; 
    background: #000000; 
} 
.current_page_item a { 
    color: #000000 !important; 
} 
.ie6 #example-one li, .ie7 #example-one li { 
    display: inline; 
} 
.ie6 #magic-line { 
    bottom: -3px; 
} 

我怎样才能使菜单浮动在页面右侧的头部DIV(宽960像素)和一个标志,内浮动离开旁边的菜单

这里是我有:http://jsfiddle.net/Mqs22/1/

和这里是我曾尝试:http://jsfiddle.net/ccZFs/

回答

0

你浮法必须在lis上,以及包装。就像这样:

#example-one li { 
    display: inline-block; 
    float: right; 
} 

小提琴:http://jsfiddle.net/KyleMuir/Mqs22/2/

希望这有助于。

+0

多数民众赞成它,但链接现在是错误的方式。还有一条线,当你将鼠标悬停在它们上方时,它会滑入链接下(我无法在小提琴中工作) - (这里是链接http://css-tricks.com/examples/MagicLine/ ... top例如),有一个完整地显示在左边,然后它在右边的菜单是 – charlie

+0

确实有意义吗? – charlie

+0

@charlie如果你需要更多的帮助,那么请让我知道。 –

0

我得到了这两个元素为你工作。

我用position: absolute;在那里。

HTML

<div class="nav-wrap"> 
    <ul class="group" id="example-one"> 
    <li class="current_page_item"><a href="#">Home</a></li> 
    <li><a href="#">Buy Tickets</a></li> 
    <li><a href="#">Group Sales</a></li> 
    <li><a href="#">Reviews</a></li> 
    <li><a href="#">The Show</a></li> 
    </ul> 
</div> 

jQuery的

var $el, leftPos, newWidth; 
    $mainNav2 = $("#example-two"); 

/* 
    EXAMPLE ONE 
*/ 

/* Add Magic Line markup via JavaScript, because it ain't gonna work without */ 
$("#example-one").append("<li id='magic-line'></li>"); 

/* Cache it */ 
var $magicLine = $("#magic-line"); 

$magicLine 
    .width($(".current_page_item").width()) 
    .css("left", $(".current_page_item a").position().left) 
    .data("origLeft", $magicLine.position().left) 
    .data("origWidth", $magicLine.width()); 

$("#example-one li").find("a").hover(function() { 
    $el = $(this); 
    leftPos = $el.position().left; 
    newWidth = $el.parent().width(); 

    $magicLine.stop().animate({ 
     left: leftPos, 
     width: newWidth 
    }); 
}, function() { 
    $magicLine.stop().animate({ 
     left: $magicLine.data("origLeft"), 
     width: $magicLine.data("origWidth") 
    });  
}); 

为了使MagicLine工作,你需要增加他们使用的是jQuery的,以及确保你已经jQuery的有关工作小提琴。

您在ul上有一个width: 960px;,导致它不能正确对齐。

JSFIDDLE

+0

我也试图把它放在一个标题div(960px宽度)和在标题div中的菜单左侧的标志? – charlie

+0

我已经尝试过,但菜单显示在容器外 - http://jsfiddle.net/Mqs22/4/embedded/result/ – charlie

+0

在这里你去找伙伴,http://jsfiddle.net/Josh_Powell/Mqs22/5/ 。我将'top:0;'添加到'nav-wrap',然后将'position:relative;'添加到'lh_header'。 –