[英]Change border color of ul to siblings “a” background-color
我正在创建一个菜单,其中嵌套了子菜单。 每个ancor标签具有不同的背景颜色。 我想发生的是,每个嵌套ul的底部边框颜色与该特定组“ li”中的ancor标签的背景颜色相同。
我似乎已经到了一半,但是现在所有嵌套的ul都从第一个ancor标签背景颜色获得了相同的边框颜色。 不知道我要去哪里错了。
<nav id="nav-main">
<ul>
<li><a href="">Spa Menu</a>
<ul>
<li><a href="">Packages</a></li>
<li><a href="">Touch Therapy</a></li>
<li><a href="">Hands & Feet</a></li>
<li><a href="">Grooming</a></li>
<li><a href="">Specialised Treatments</a></li>
</ul>
</li>
<li><a href="">Bookings</a>
<ul>
<li><a href="">Packages</a></li>
<li><a href="">Touch Therapy</a></li>
<li><a href="">Hands & Feet</a></li>
<li><a href="">Grooming</a></li>
<li><a href="">Specialised Treatments</a></li>
</ul>
</li>
<li><a href="">Vouchers</a></li>
<li><a href="">Gallery</a></li>
</ul>
</nav><!-- END #nav-main -->
的CSS
#nav-main {
float: right;
position: relative;
top: 8em;
}
#nav-main > ul > li {
float: left;
position: relative;
}
#nav-main > ul > li a {
color: white;
text-transform: uppercase;
font-family: 'Brandon Grotesque', sans-serif;
font-weight: bold;
font-size: 18px;
padding-left: 2em;
padding-right: 2em;
}
#nav-main > ul > li ul {
position: absolute;
top: 100%;
left: 0;
z-index: 2;
border-bottom: 8px solid ;
}
#nav-main > ul > li ul li a {
white-space: nowrap;
text-align: left;
background: #fff;
color: #b0b0b0;
font-size: 16px;
}
#nav-main > ul > li:nth-child(1) > a {
background-color: #5ac6eb;
}
#nav-main > ul > li:nth-child(2) > a {
background-color: #bcd34d;
}
#nav-main > ul > li:nth-child(3) > a {
background-color: #5ac6eb;
}
#nav-main > ul > li:nth-child(4) > a {
background-color: #5ac6eb;
}
和js使其起作用
jQuery(document).ready(function($){
'use strict';
var child = $('#nav-main ul >li >ul');
child.css({
'border-color': child.siblings('a').css('background-color')
});
});
尝试这个:
$('#nav-main ul > li > ul').each(function() {
$(this).css('border-color', $(this).prev('a').css('background-color'));
});
我必须老实地说,它看起来非常混乱。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.