gpt4 book ai didi

jquery - css水平下拉定位

转载 作者:太空宇宙 更新时间:2023-11-04 12:32:11 25 4
gpt4 key购买 nike

大家好,我正在尝试制作一个水平下拉菜单,我已经制作了一个关于我的问题的 JS Fiddle 以及一张我想要它的样子的图片。

我的问题是我无法让子菜单位于我想要的位置(在容器的右侧)当我将我的子 UL 设置为绝对定位时,它不会比它的父级更宽,并且被迫垂直。我从来没有做过水平下拉,只有垂直。

    <div id="head">
<div class="container">
<a href="#"><strong class="logo pull-left"><h1>CAVO</h1>
</strong></a> <!-- end logo !-->
<ul class="nav pull-right">
<li><a href="#">Menu</a>
<ul>
<li><a href="#">Starters</a></li>
<li><a href="#">Breakfast and Brunch</a></li>
<li><a href="#">Salads</a></li>
<li><a href="#">Sandwiches and Wraps</a></li>
<li><a href="#">Pasta</a></li>
<li><a href="#">Mains</a></li>
<li><a href="#">Pizza</a></li>
</ul>
</li>
<li><a href="#">About Us</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div><!-- end container !-->
</div> <!-- end header !-->

CSS

    body, html {
height: 5000px;
font-size: 18px;
font-family: Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif;
color: #fff;
background-color: #222;
}

a {
text-decoration: none;
color: inherit;
}

#head {
height: 76px;
width: 100%;
background-color: #472626;
position: fixed;
z-index: 10000;
-webkit-transition: all 300ms ease-out;
-moz-transition: all 300ms ease-out;
-ms-transition: all 300ms ease-out;
-o-transition: all 300ms ease-out;
transition: all 300ms ease-out;
}

.container {
max-width: 1400px;
padding-left: 20px;
padding-right: 20px;
margin-left: auto;
margin-right: auto;
}

.logo {
line-height: 75px;
text-align:left;
-webkit-transition: font-size 2s ease , line-height 0.5s ease;
-moz-transition: font 0.3s ease , line-height 0.5s ease;
-o-transition: font 0.3s ease , line-height 0.5s ease;
-ms-transition: font 0.3s ease , line-height 0.5s ease;


}

.logo h1 {
font-size: 2.8em;
font: "Segoe UI Semibold";
display:block;
}

.pull-left {
float: left;
}

.pull-right {
float:right;
}

.nav {
font-size: 1.3em;
font-family: "wf_SegoeUILight","wf_SegoeUI","Segoe UI Light","Segoe WP Light","Segoe UI","Segoe","Segoe WP","Tahoma","Verdana","Arial","sans-serif";
font-weight: 100;
}

.nav li {
float:left;
padding-left: 15px;
line-height: 80px;
-webkit-transition: line-height 0.5s ease;
-moz-transition: line-height 0.3s ease;
-o-transition: line-height 0.3s ease;
-ms-transition: line-height 0.3s ease;
position: relative;
}

.nav li a {
opacity: 1;
-webkit-transition: opacity .2s ease-in-out;
-moz-transition: opacity .2s ease-in-out;
-ms-transition: opacity .2s ease-in-out;
-o-transition: opacity .2s ease-in-out;
transition: opacity .2s ease-in-out;
}

.nav li a:hover {
opacity: .6;
}

.nav li ul {
background-color: #2B0909;

}

.nav li ul li a , .nav li ul li{
display: block;
float: left;
line-height:none;
}

想要的结果:

Picture

这是我的 fiddle :

JSFIDDLE

最佳答案

在您现有的 CSS 中,添加以下内容:

ul ul{
position:relative;
right:-194px;
}
ul li:first-child{
text-align:right;
}

这是一个 demo .

关于jquery - css水平下拉定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27563574/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com