固定标题导航链接滚出标题问题

时间:2015-10-01 13:21:19

标签: html css hyperlink header fixed

我很难找到问题的答案,也许我不是很好解释。

我有一个带有导航的固定标题,这里是HTML;

<header>
<nav>
    <ul>
        <li><a href="home.html">HOME</a></li>
        <li><a href="about.html">ABOUT</a></li>
        <li><a href="ourpassion.html">OUR PASSION</a></li>
        <li><a HREF="whatwedo.html">WHAT WE DO</a></li>
        <li><a href="blog.html">BLOG</a></li>
        <li><a href="contact.html">CONTACT</a></li>
    </ul>
</nav>

当我向下滚动正文(查看更多内容)时,链接本身会滚动出视口,同时标题及其内容仍然存在。换句话说,标题视觉效果(如链接文本,例如HOME,ABOUT,CONTACTS等)仍然保留并给人留下链接的印象,但我不能再将鼠标悬停在它们上面,因为标签似乎已经消失了。

我不明白如何解决这个问题。业余程序员在这里。 下面是整个html文件供参考。

非常有责任! 内特

<!DOCTYPE html>
<html lamg="en">

<head>
	<link href='https://fonts.googleapis.com/css?family=Bitter|Abril+Fatface|Quattrocento+Sans|Cantarell' rel='stylesheet' type='text/css'>
	<style>
	* {
		overflow-x: hidden; 
		margin: 0;
		padding: 0;
	}

	h1 {
		font-family: "Bitter", serif;
		font-size: 5vw;
	}

	h2 {
		font-family: "Quattrocento Sans", sans-serif;
		font-size: 2vw;
	}

	h3 {
		font-family: "Cantarell", sans-serif;
		font-size: 1.5vw;
	}

	header {
		position: fixed;
		overflow: hidden;
		height: 100px;
		width: 100%;
		background-color: rgba(255, 255, 255, 0.5);
	}

	nav {
		text-align: center;
		position: relative;
	}

	ul {
		line-height: 100px;
		position: relative;
	}

	li {
		position: relative;
		display: inline-block;
		background-color: rgba(200, 200, 200, 0);
		-webkit-transition: width 2s; /*safari */
		transition: background-color 0.2s;
	}

	li:hover {
		position: relative;
		background-color: rgba(200, 200, 200, 0.8);
	}

	a {
		position: relative;
		text-decoration: none;
		text-align: center;
		font-size: 2vw;
		display: block;
		padding-left: 2vw;
		padding-right: 2vw;
		font-family: "Abril Fatface", cursive;
		color: rgba(216, 216, 216, 1); 
		text-shadow: 0px 0px 1px #A0A0A0;
	}

	body {
		background-color: rgba(121, 184, 255, 0.5);
		color: white;
		background-image: url(http://wallpaperspal.com/wp-content/uploads/Blue-Gradient-Abstract-Wallpaper.jpg);
	}

	div.headerspace {
		height: 100px;
	}

	div.mainmedia {
		background-image: url("nate pic.jpg");
		width: 500px;
		height: 500px;
		float: right;
	}

	div.content {
		position: absolute;
		padding-right: 300px;
		padding-left: 100px;
		padding-top: 100px;
	}


	</style>
</head>
<header>
	<nav>
		<ul>
			<li><a href="home.html">HOME</a></li>
			<li><a href="about.html">ABOUT</a></li>
			<li><a href="ourpassion.html">OUR PASSION</a></li>
			<li><a HREF="whatwedo.html">WHAT WE DO</a></li>
			<li><a href="blog.html">BLOG</a></li>
			<li><a href="contact.html">CONTACT</a></li>
		</ul>
	</nav>
</header>

<body>
	<div class="headerspace">
	</div>
	<div class="mainmedia">
	</div>
	<div class="content">
		<h1>Nat and Abs</h1>
		<h2>A.K.A Nabs</h2>
		<h3>Nate and Abs got hitched on the 18th April 2015 and since the honeymoon have been pursuing creativity like it's going out of business! Abs is a professional actor, studied at UWTSD in Carmarthenshire and Nate has trained as a Sound & Lighting engineer. Abs enjoys creative writing and Nate enjoys writing and singing his own songs. They are both extremely passionate people; give them the opportunity and they'll get passionate about something!</h3>
		<h1>Nat and Abs</h1>
		<h2>A.K.A Nabs</h2>
		<h3>Nate and Abs got hitched on the 18th April 2015 and since the honeymoon have been pursuing creativity like it's going out of business! Abs is a professional actor, studied at UWTSD in Carmarthenshire and Nate has trained as a Sound & Lighting engineer. Abs enjoys creative writing and Nate enjoys writing and singing his own songs. They are both extremely passionate people; give them the opportunity and they'll get passionate about something!</h3>
		<h1>Nat and Abs</h1>
		<h2>A.K.A Nabs</h2>
		<h3>Nate and Abs got hitched on the 18th April 2015 and since the honeymoon have been pursuing creativity like it's going out of business! Abs is a professional actor, studied at UWTSD in Carmarthenshire and Nate has trained as a Sound & Lighting engineer. Abs enjoys creative writing and Nate enjoys writing and singing his own songs. They are both extremely passionate people; give them the opportunity and they'll get passionate about something!</h3>
		<h1>Nat and Abs</h1>
		<h2>A.K.A Nabs</h2>
		<h3>Nate and Abs got hitched on the 18th April 2015 and since the honeymoon have been pursuing creativity like it's going out of business! Abs is a professional actor, studied at UWTSD in Carmarthenshire and Nate has trained as a Sound & Lighting engineer. Abs enjoys creative writing and Nate enjoys writing and singing his own songs. They are both extremely passionate people; give them the opportunity and they'll get passionate about something!</h3>
		<h1>Nat and Abs</h1>
		<h2>A.K.A Nabs</h2>
		<h3>Nate and Abs got hitched on the 18th April 2015 and since the honeymoon have been pursuing creativity like it's going out of business! Abs is a professional actor, studied at UWTSD in Carmarthenshire and Nate has trained as a Sound & Lighting engineer. Abs enjoys creative writing and Nate enjoys writing and singing his own songs. They are both extremely passionate people; give them the opportunity and they'll get passionate about something!</h3>
		<h1>Nat and Abs</h1>
		<h2>A.K.A Nabs</h2>
		<h3>Nate and Abs got hitched on the 18th April 2015 and since the honeymoon have been pursuing creativity like it's going out of business! Abs is a professional actor, studied at UWTSD in Carmarthenshire and Nate has trained as a Sound & Lighting engineer. Abs enjoys creative writing and Nate enjoys writing and singing his own songs. They are both extremely passionate people; give them the opportunity and they'll get passionate about something!</h3>
		<h1>Nat and Abs</h1>
		<h2>A.K.A Nabs</h2>
		<h3>Nate and Abs got hitched on the 18th April 2015 and since the honeymoon have been pursuing creativity like it's going out of business! Abs is a professional actor, studied at UWTSD in Carmarthenshire and Nate has trained as a Sound & Lighting engineer. Abs enjoys creative writing and Nate enjoys writing and singing his own songs. They are both extremely passionate people; give them the opportunity and they'll get passionate about something!</h3>
		<h1>Nat and Abs</h1>
		<h2>A.K.A Nabs</h2>
		<h3>Nate and Abs got hitched on the 18th April 2015 and since the honeymoon have been pursuing creativity like it's going out of business! Abs is a professional actor, studied at UWTSD in Carmarthenshire and Nate has trained as a Sound & Lighting engineer. Abs enjoys creative writing and Nate enjoys writing and singing his own songs. They are both extremely passionate people; give them the opportunity and they'll get passionate about something!</h3>
	</div>
</body>

2 个答案:

答案 0 :(得分:2)

您需要为标题设置z-index。

&#13;
&#13;
<!DOCTYPE html>
<html lamg="en">

<head>
	<link href='https://fonts.googleapis.com/css?family=Bitter|Abril+Fatface|Quattrocento+Sans|Cantarell' rel='stylesheet' type='text/css'>
	<style>
	* {
		overflow-x: hidden; 
		margin: 0;
		padding: 0;
	}

	h1 {
		font-family: "Bitter", serif;
		font-size: 5vw;
	}

	h2 {
		font-family: "Quattrocento Sans", sans-serif;
		font-size: 2vw;
	}

	h3 {
		font-family: "Cantarell", sans-serif;
		font-size: 1.5vw;
	}

	header {
		position: fixed;
        z-index: 1;
		overflow: hidden;
		height: 100px;
		width: 100%;
		background-color: rgba(255, 255, 255, 0.5);
	}

	nav {
		text-align: center;
		position: relative;
	}

	ul {
		line-height: 100px;
		position: relative;
	}

	li {
		position: relative;
		display: inline-block;
		background-color: rgba(200, 200, 200, 0);
		-webkit-transition: width 2s; /*safari */
		transition: background-color 0.2s;
	}

	li:hover {
		position: relative;
		background-color: rgba(200, 200, 200, 0.8);
	}

	a {
		position: relative;
		text-decoration: none;
		text-align: center;
		font-size: 2vw;
		display: block;
		padding-left: 2vw;
		padding-right: 2vw;
		font-family: "Abril Fatface", cursive;
		color: rgba(216, 216, 216, 1); 
		text-shadow: 0px 0px 1px #A0A0A0;
	}

	body {
		background-color: rgba(121, 184, 255, 0.5);
		color: white;
		background-image: url(http://wallpaperspal.com/wp-content/uploads/Blue-Gradient-Abstract-Wallpaper.jpg);
	}

	div.headerspace {
		height: 100px;
	}

	div.mainmedia {
		background-image: url("nate pic.jpg");
		width: 500px;
		height: 500px;
		float: right;
	}

	div.content {
		position: absolute;
		padding-right: 300px;
		padding-left: 100px;
		padding-top: 100px;
	}


	</style>
</head>
<header>
	<nav>
		<ul>
			<li><a href="home.html">HOME</a></li>
			<li><a href="about.html">ABOUT</a></li>
			<li><a href="ourpassion.html">OUR PASSION</a></li>
			<li><a HREF="whatwedo.html">WHAT WE DO</a></li>
			<li><a href="blog.html">BLOG</a></li>
			<li><a href="contact.html">CONTACT</a></li>
		</ul>
	</nav>
</header>

<body>
	<div class="headerspace">
	</div>
	<div class="mainmedia">
	</div>
	<div class="content">
		<h1>Nat and Abs</h1>
		<h2>A.K.A Nabs</h2>
		<h3>Nate and Abs got hitched on the 18th April 2015 and since the honeymoon have been pursuing creativity like it's going out of business! Abs is a professional actor, studied at UWTSD in Carmarthenshire and Nate has trained as a Sound & Lighting engineer. Abs enjoys creative writing and Nate enjoys writing and singing his own songs. They are both extremely passionate people; give them the opportunity and they'll get passionate about something!</h3>
		<h1>Nat and Abs</h1>
		<h2>A.K.A Nabs</h2>
		<h3>Nate and Abs got hitched on the 18th April 2015 and since the honeymoon have been pursuing creativity like it's going out of business! Abs is a professional actor, studied at UWTSD in Carmarthenshire and Nate has trained as a Sound & Lighting engineer. Abs enjoys creative writing and Nate enjoys writing and singing his own songs. They are both extremely passionate people; give them the opportunity and they'll get passionate about something!</h3>
		<h1>Nat and Abs</h1>
		<h2>A.K.A Nabs</h2>
		<h3>Nate and Abs got hitched on the 18th April 2015 and since the honeymoon have been pursuing creativity like it's going out of business! Abs is a professional actor, studied at UWTSD in Carmarthenshire and Nate has trained as a Sound & Lighting engineer. Abs enjoys creative writing and Nate enjoys writing and singing his own songs. They are both extremely passionate people; give them the opportunity and they'll get passionate about something!</h3>
		<h1>Nat and Abs</h1>
		<h2>A.K.A Nabs</h2>
		<h3>Nate and Abs got hitched on the 18th April 2015 and since the honeymoon have been pursuing creativity like it's going out of business! Abs is a professional actor, studied at UWTSD in Carmarthenshire and Nate has trained as a Sound & Lighting engineer. Abs enjoys creative writing and Nate enjoys writing and singing his own songs. They are both extremely passionate people; give them the opportunity and they'll get passionate about something!</h3>
		<h1>Nat and Abs</h1>
		<h2>A.K.A Nabs</h2>
		<h3>Nate and Abs got hitched on the 18th April 2015 and since the honeymoon have been pursuing creativity like it's going out of business! Abs is a professional actor, studied at UWTSD in Carmarthenshire and Nate has trained as a Sound & Lighting engineer. Abs enjoys creative writing and Nate enjoys writing and singing his own songs. They are both extremely passionate people; give them the opportunity and they'll get passionate about something!</h3>
		<h1>Nat and Abs</h1>
		<h2>A.K.A Nabs</h2>
		<h3>Nate and Abs got hitched on the 18th April 2015 and since the honeymoon have been pursuing creativity like it's going out of business! Abs is a professional actor, studied at UWTSD in Carmarthenshire and Nate has trained as a Sound & Lighting engineer. Abs enjoys creative writing and Nate enjoys writing and singing his own songs. They are both extremely passionate people; give them the opportunity and they'll get passionate about something!</h3>
		<h1>Nat and Abs</h1>
		<h2>A.K.A Nabs</h2>
		<h3>Nate and Abs got hitched on the 18th April 2015 and since the honeymoon have been pursuing creativity like it's going out of business! Abs is a professional actor, studied at UWTSD in Carmarthenshire and Nate has trained as a Sound & Lighting engineer. Abs enjoys creative writing and Nate enjoys writing and singing his own songs. They are both extremely passionate people; give them the opportunity and they'll get passionate about something!</h3>
		<h1>Nat and Abs</h1>
		<h2>A.K.A Nabs</h2>
		<h3>Nate and Abs got hitched on the 18th April 2015 and since the honeymoon have been pursuing creativity like it's going out of business! Abs is a professional actor, studied at UWTSD in Carmarthenshire and Nate has trained as a Sound & Lighting engineer. Abs enjoys creative writing and Nate enjoys writing and singing his own songs. They are both extremely passionate people; give them the opportunity and they'll get passionate about something!</h3>
	</div>
</body>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

只需为标头设置z-index属性,使其大于内容的z-index。而且,我添加了一些jQuery代码,使标题更加明显。

&#13;
&#13;
$(document).ready(function(){
	
	$(window).scroll(function(){
		var topOffset = $(window).scrollTop();
		if(topOffset>130){
			$("header").css({"background-color":"rgba(255, 255, 255, 1)"});
		}else{
			$("header").css({"background-color":"rgba(255, 255, 255, .5)"});
			}
	
	
	});
	
	
});
&#13;
* {
		overflow-x: hidden; 
		margin: 0;
		padding: 0;
	}

	h1 {
		font-family: "Bitter", serif;
		font-size: 5vw;
	}

	h2 {
		font-family: "Quattrocento Sans", sans-serif;
		font-size: 2vw;
	}

	h3 {
		font-family: "Cantarell", sans-serif;
		font-size: 1.5vw;
	}

	header {
		position: fixed;
		overflow: hidden;
		height: 100px;
		width: 100%;
		background-color: rgba(255, 255, 255, 0.5);
		z-index:999;
	}

	nav {
		text-align: center;
		position: relative;
	}

	ul {
		line-height: 100px;
		position: relative;
	}

	li {
		position: relative;
		display: inline-block;
		background-color: rgba(200, 200, 200, 0);
		-webkit-transition: width 2s; /*safari */
		transition: background-color 0.2s;
	}

	li:hover {
		position: relative;
		background-color: rgba(200, 200, 200, 0.8);
	}

	a {
		position: relative;
		text-decoration: none;
		text-align: center;
		font-size: 2vw;
		display: block;
		padding-left: 2vw;
		padding-right: 2vw;
		font-family: "Abril Fatface", cursive;
		color: rgba(216, 216, 216, 1); 
		text-shadow: 0px 0px 1px #A0A0A0;
	}

	body {
		background-color: rgba(121, 184, 255, 0.5);
		color: white;
		background-image: url(http://wallpaperspal.com/wp-content/uploads/Blue-Gradient-Abstract-Wallpaper.jpg);
	}

	div.headerspace {
		height: 100px;
	}

	div.mainmedia {
		background-image: url("nate pic.jpg");
		width: 500px;
		height: 500px;
		float: right;
	}

	div.content {
		position: absolute;
		padding-right: 300px;
		padding-left: 100px;
		padding-top: 100px;
		z-index:500;
	}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href='https://fonts.googleapis.com/css?family=Bitter|Abril+Fatface|Quattrocento+Sans|Cantarell' rel='stylesheet' type='text/css'>


<header>
	<nav>
		<ul>
			<li><a href="home.html">HOME</a></li>
			<li><a href="about.html">ABOUT</a></li>
			<li><a href="ourpassion.html">OUR PASSION</a></li>
			<li><a HREF="whatwedo.html">WHAT WE DO</a></li>
			<li><a href="blog.html">BLOG</a></li>
			<li><a href="contact.html">CONTACT</a></li>
		</ul>
	</nav>
</header>
	<div class="headerspace">
	</div>
	<div class="mainmedia">
	</div>
	<div class="content">
		<h1>Nat and Abs</h1>
		<h2>A.K.A Nabs</h2>
		<h3>Nate and Abs got hitched on the 18th April 2015 and since the honeymoon have been pursuing creativity like it's going out of business! Abs is a professional actor, studied at UWTSD in Carmarthenshire and Nate has trained as a Sound & Lighting engineer. Abs enjoys creative writing and Nate enjoys writing and singing his own songs. They are both extremely passionate people; give them the opportunity and they'll get passionate about something!</h3>
		<h1>Nat and Abs</h1>
		<h2>A.K.A Nabs</h2>
		<h3>Nate and Abs got hitched on the 18th April 2015 and since the honeymoon have been pursuing creativity like it's going out of business! Abs is a professional actor, studied at UWTSD in Carmarthenshire and Nate has trained as a Sound & Lighting engineer. Abs enjoys creative writing and Nate enjoys writing and singing his own songs. They are both extremely passionate people; give them the opportunity and they'll get passionate about something!</h3>
		<h1>Nat and Abs</h1>
		<h2>A.K.A Nabs</h2>
		<h3>Nate and Abs got hitched on the 18th April 2015 and since the honeymoon have been pursuing creativity like it's going out of business! Abs is a professional actor, studied at UWTSD in Carmarthenshire and Nate has trained as a Sound & Lighting engineer. Abs enjoys creative writing and Nate enjoys writing and singing his own songs. They are both extremely passionate people; give them the opportunity and they'll get passionate about something!</h3>
		<h1>Nat and Abs</h1>
		<h2>A.K.A Nabs</h2>
		<h3>Nate and Abs got hitched on the 18th April 2015 and since the honeymoon have been pursuing creativity like it's going out of business! Abs is a professional actor, studied at UWTSD in Carmarthenshire and Nate has trained as a Sound & Lighting engineer. Abs enjoys creative writing and Nate enjoys writing and singing his own songs. They are both extremely passionate people; give them the opportunity and they'll get passionate about something!</h3>
		<h1>Nat and Abs</h1>
		<h2>A.K.A Nabs</h2>
		<h3>Nate and Abs got hitched on the 18th April 2015 and since the honeymoon have been pursuing creativity like it's going out of business! Abs is a professional actor, studied at UWTSD in Carmarthenshire and Nate has trained as a Sound & Lighting engineer. Abs enjoys creative writing and Nate enjoys writing and singing his own songs. They are both extremely passionate people; give them the opportunity and they'll get passionate about something!</h3>
		<h1>Nat and Abs</h1>
		<h2>A.K.A Nabs</h2>
		<h3>Nate and Abs got hitched on the 18th April 2015 and since the honeymoon have been pursuing creativity like it's going out of business! Abs is a professional actor, studied at UWTSD in Carmarthenshire and Nate has trained as a Sound & Lighting engineer. Abs enjoys creative writing and Nate enjoys writing and singing his own songs. They are both extremely passionate people; give them the opportunity and they'll get passionate about something!</h3>
		<h1>Nat and Abs</h1>
		<h2>A.K.A Nabs</h2>
		<h3>Nate and Abs got hitched on the 18th April 2015 and since the honeymoon have been pursuing creativity like it's going out of business! Abs is a professional actor, studied at UWTSD in Carmarthenshire and Nate has trained as a Sound & Lighting engineer. Abs enjoys creative writing and Nate enjoys writing and singing his own songs. They are both extremely passionate people; give them the opportunity and they'll get passionate about something!</h3>
		<h1>Nat and Abs</h1>
		<h2>A.K.A Nabs</h2>
		<h3>Nate and Abs got hitched on the 18th April 2015 and since the honeymoon have been pursuing creativity like it's going out of business! Abs is a professional actor, studied at UWTSD in Carmarthenshire and Nate has trained as a Sound & Lighting engineer. Abs enjoys creative writing and Nate enjoys writing and singing his own songs. They are both extremely passionate people; give them the opportunity and they'll get passionate about something!</h3>
	</div>
&#13;
&#13;
&#13;