【问题标题】:Header image overriding nav functionality标题图像覆盖导航功能
【发布时间】:2014-02-14 18:27:01
【问题描述】:

我的标题有一些问题。有两个图像。一个在 x 轴上重复的背景图块。居中的徽标图像和左右两个导航按钮。当我将徽标放置在中心时,徽标右侧的导航链接失去了功能。没有悬停或链接。为什么会发生这种情况?我该如何解决?

我是新手,所以如果我问了一个已经回答了数千次的问题,请保持温和。我用谷歌搜索了我的问题,无法弄清楚该怎么做。希望这里有人可以帮助我。

这是查看问题和代码的链接。

http://jsbin.com/iqoQuGAy/11/edit

这里是html:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>why?</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" />
</head>
<body>
<!--HEADER -->
<header>
<div id="pageHeader">
<a href="#" id="logo"></a>
<!--NAVIGATION -->
<nav id="mainNav">
<ul>
<li id="about-link"><a href="#about">about</a></li>
<li id="work-link"><a href="#work">work</a></li>
<li id="contact-link"><a href="#contact">contact</a></li>
<li id="resume-link"><a href="#resume">resume</a></li>
</ul>
</nav>
</div>
</header> <!-- end header -->
</body>
</html>

还有css:

/*Global styles*/

/*limited reset*/
html, body, div, section, article, aside, header, hgroup, footer, nav, h1, h2, h3, h4, h5, h6, p, blockquote, address, time, span, em, strong, img, ol, ul, li, figure, canvas, video, th, td, tr {
margin: 0;
padding: 0;
border: 0;
vertical-align:baseline;
font: inherit;
}

/*html5 display rule*/
address, article, aside, canvas, details, figcaption, figure, footer, header, hgroup, nav, menu, nav, section, summary {
display: block;}


html {
background-color: #E7E9D1;
background-image: url(http://s24.postimg.org/4rcaja0lh/image.png);
}

body
{
position: relative;
font-family: Arial, helvetica, sans-serif;
font-size: 14px;
}

/*header styles*/
header
{
background-image: url("http://s7.postimg.org/59ft4upyf/header_bg.png");
background-repeat: repeat-x;
left: 0;
position: fixed;
top: 0;
width: 100%;
z-index: 200;
}
#pageHeader
{
height: 128px;
margin: 0 auto;
position: relative;
width: 960px;
}
#pageHeader:after
{
content: '';
display: block;
position: absolute;
width: 100%;
height: 100%;
left: 425px;
top: 0;
background: url('http://s18.postimg.org/5ktpz4rid/logo.png') 0 0 no-repeat scroll;
}

/*nav styles*/
#mainNav {
font-size: 18px;
list-style: none outside none;
text-align: center;
padding-top: 20px;
}

#mainNav li {
display: inline;
}

#mainNav a {
text-decoration: none;
color: rgb(252,250,230);
display: inline-block;
padding: 10px;
}

#mainNav a:hover {
color: #9f9e8f;
}

#mainNav #about-link {
margin-right: 50px;
}
#mainNav #work-link {
margin-right: 0px;
}
#mainNav #contact-link {
margin-left: 160px;
}
#mainNav #resume-link {
margin-left: 20px;
}

【问题讨论】:

    标签: html css header positioning


    【解决方案1】:

    尝试从body 规则中删除position: relative;

    【讨论】:

      【解决方案2】:

      您的#pageHeader div waz 设置为width: 100%;,它覆盖了您的链接。给它一个宽度可以解决这个问题:

      #pageHeader:after {
          content: '';
          display: block;
          position: absolute; 
          width: 120px;
          height: 100%;
          left: 425px;
          top: 0;
          background: url('http://s18.postimg.org/5ktpz4rid/logo.png') 0 0 no-repeat scroll;
      }
      

      这里是固定链接:JS Bin

      【讨论】:

      • Enijar 和 badAdviceGuy - 你们太棒了,完全解决了我的问题!谢谢!
      • @oldbroad 不客气。记得接受我们的答案之一。
      • 只需点击检查。对吗?
      【解决方案3】:

      看起来徽标是通过宽度为100%:after 类添加的。由于它是一个 :after 类,它会显示在比元素的其余部分更高的 z-index 上(从而掩盖您的其他链接)。

      如果您将徽标的 CSS 条目更改为下方,则应该可以解决您的问题:

      #pageHeader:after {
       content: '';
       display: block;
       position: absolute;
       width: 120px;
       height: 120px;
       left: 425px;
       top: 0;
       background: url('http://s18.postimg.org/5ktpz4rid/logo.png') 0 0 no-repeat scroll;
      }
      

      【讨论】:

        猜你喜欢
        • 2018-08-02
        • 2019-09-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多