-1

我的水平菜单有这个 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/

4

2 回答 2

0

I got both elements working for you.

I used a position: absolute; to get it over there.

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")
    });    
});

To make the MagicLine work you needed to add the jquery they used for that as well as making sure you had jQuery working on the fiddle.

You had a width: 960px; on the ul which was causing it to not align right.

JSFIDDLE

于 2013-10-03T20:02:36.273 回答
0

您的浮动需要在 lis 以及包装器上。像这样:

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

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

希望这可以帮助。

于 2013-10-03T19:42:22.933 回答