Menubar下拉抓住背景的文本

时间:2016-04-09 20:01:28

标签: jquery html css

最近我为菜单栏添加了响应式下拉菜单以支持触摸设备,但我遇到了一个有趣的问题,无法找出根本原因。基本上,下拉列表似乎是透明的,并且受到内容部分中背景提要帖子的文本的影响。似乎该下拉列表会读取背景文本标题,因为如果我将鼠标悬停在该文本上,则下拉列表会关闭,就像它认为我正在尝试将焦点放在标题上一样。

Click to see the image and it will all make sense.



#nav {
	display: block;
	cursor: pointer;
	background-color: #4085C6;
	padding: 6px;
	color: #000;
	text-decoration: none;
	border-top-color: #4085C6;
	border-right-color: #4085C6;
	border-bottom-color: #4085C6;
	border-left-color: #4085C6;
	margin: 0px;
	width: 960px;
}
#nav > a {
    display: none;
}	
#nav li {
    position: relative;
}
#nav li a
{
	color: #fff;
	display: block;
}
#nav li a:active
{
	background-color: #c00 !important;
}
#nav span:after
{
	width: 0;
	height: 0;
	border: 0.313em solid transparent; /* 5 */
	border-bottom: none;
	border-top-color: #4086C4;
	content: '';
	vertical-align: middle;
	display: inline-block;
	position: relative;
	right: -0.313em; /* 5 */
}
/* first level */
#nav > ul {
	height: 3.75em;
	background-color: #4086C4;
	list-style-type: none;
}
#nav > ul > li {
	width: 157px;
	float: left;
}
#nav > ul > li > a {
	height: 100%;
	font-size: 1.5em;
	line-height: 2.5em;
	text-align: center;
	text-decoration: none;
}
#nav > ul > li:not( :last-child ) > a {
	border-right-width: 8px;
	border-right-color: #3779b3;
	border-right-style: solid;
}
#nav > ul > li:hover > a,
#nav > ul:not( :hover ) > li.active > a {
	background-color: #3779b3;
	color: #FFF;
	list-style-type: none;
}
/* second level */
#nav li ul {
	background-color: #3779b3;
	display: none;
	position: absolute;
	top: 100%;
	width: 20em;
	list-style-type: none;
}
#nav li:hover ul {
    display: block;
	left: 0;
	right: 0;
}
#nav li:not( :first-child ):hover ul {
	left: -1px;
}
#nav li ul a {
	font-size: 1.25em;
	border-top: 1px solid #4086C4;
	padding: 0.75em;
	text-decoration: none;
}
#nav li ul li a:hover,
#nav li ul:not( :hover ) li.active a {
	background-color: #4086C4;
	list-style-type: none;
}

@media only screen and ( max-width: 62.5em ) /* 1000 */
{
	#nav {
	width: 100%;
	position: static;
	box-shadow: 6px 6px #4785C6;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	margin-left: 0px;
	outline-color: #4086C4;
	outline-style: solid;
	background-color: #4086C4;
	color: #4086C4;
	padding: 0px;
	border-top-color: #4086C4;
	border-right-color: #4086C4;
	border-bottom-color: #4086C4;
	border-left-color: #4086C4;
	}
}

@media only screen and ( max-width: 40em ) /* 640 */
{
	html {
		font-size: 75%; /* 12 */
	}
    #nav {
        position: relative;
		top: auto;
		left: auto;
    }
	#nav > a {
		width: 3.125em; 
		height: 3.125em; 
		text-align: left;
		text-indent: -9999px;
		background-color: #4086C4;
		position: relative;
	}
	#nav > a:before,
	#nav > a:after {
		position: absolute;
		border: 2px solid #fff;
		top: 35%;
		left: 25%;
		right: 25%;
		content: '';
	}
	#nav > a:after {
		top: 60%;
	}
    #nav:not( :target ) > a:first-of-type,
    #nav:target > a:last-of-type {
		display: block;
    }
	/* first level */
    #nav > ul {
        height: auto;
        display: none;
        position: absolute;
        left: 0;
        right: 0;
    }
    #nav:target > ul {
        display: block;
    }
    #nav > ul > li {
        width: 100%;
        float: none;
    }
	#nav > ul > li > a {
		height: auto;
		text-align: left;
		padding: 0 0.833em;
	}
	#nav > ul > li:not( :last-child ) > a {
		border-right: none;
		border-bottom: 1px solid #3779b3;
	}
	/* second level */
    #nav li ul {
        position: static;
		padding: 1.25em;
		padding-top: 0;
    }
}

        <nav id="nav" role="navigation">
            <a href="#nav" title="Show navigation">Show navigation</a>
            <a href="#" title="Hide navigation">Hide navigation</a>
            <ul>
                <li><a href="home.html">Home</a></li>
                <li>
                    <a href="#" aria-haspopup="true"><span>Adult</span></a>
                    <ul>
                        <li><a href="adult/indoor_soccer.html">Indoor</a></li>
                        <li><a href="adult/indoor_league.html">Indoor League</a></li>
                        <li><a href="adult/outdoor_soccer.html">Outdoor</a></li>
                        <li><a href="adult/wsl_schedules.html">WSL Schedule</a></li>
                        <li><a href="adult/srbijada2014.html">Srbijada 2014</a></li>
<li><a href="adult/contact_us.html">Contact</a></li>
                    </ul>
                </li>
                <li>
                    <a href="#" aria-haspopup="true"><span>Youth</span></a>
                    <ul>
                        <li><a href="youth/code_of_ethics.html">Code of Ethics</a></li>
                        <li><a href="youth/team_tryouts.html">Team Tryouts</a></li>
                        <li><a href="youth/team_camp.html">Team Camp</a></li>
                        <li><a href="youth/team_registration.html">Team Registration and Payments</a></li>
                        <li><a href="youth/mikro_soccer.html">MiKro Soccer</a></li>
                        <li><a href="youth/tournaments.html">Tournaments</a></li>
                        <li><a href="youth/contact_us.html">Contact</a></li>
                    </ul>
                </li>
                <li><a href="about_us.html">About Us</a></li>
                <li><a href="board_members.html">Board</a></li>
                <li><a href="links.html">Links</a></li>
            </ul>
        </nav>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

您应该在CSS中使用z-index属性。

#nav li ul {
    background-color: #3779b3;
    display: none;
    position: absolute;
    top: 100%;
    width: 20em;
    list-style-type: none;
    z-index: 1;
}