【问题标题】:Overlaying Nav bar on background image在背景图像上叠加导航栏
【发布时间】:2016-01-23 22:12:30
【问题描述】:

我正在以一种奇怪的方式建立一个网站,

该站点的设计者创建了一个背景图像,其中包含内置到图像中的导航栏的标题和按钮,并希望我使用 HTML 使它们可点击。

当我可以为特定分辨率构建它时,这实际上不是问题,如下所示。 Nav bar overlaying an image

但是,当网站的分辨率发生变化时,导航栏的位置会移动到不同的区域,使其无用。

nav bar position changes, making it useless

我需要一种方法让我的导航栏对齐并缩放到背景图像。

HTML:

<!DOCTYPE html>
<head>
    <title>
        Patrick Walsh 3D
    </title>
    <link rel="stylesheet" type="text/css" href="theme.css">
</head>
<body>
    <div id="nav">
        <a href="index.html">
            <div id="homeButton">
                <!--This is an empty div, used to define a portion of the screen that is clickable-->
            </div>
        </a>
        <a href="resume.html">
            <div id="resumeButton">
                <!--This is an empty div, used to define a portion of the screen that is clickable-->
            </div>
        </a>
        <a href="tutorial.html">
            <div id="tutorialButton">
                <!--This is an empty div, used to define a portion of the screen that is clickable-->
            </div>
        </a>
        <a href="contact.html">
            <div id="contactButton">
                <!--This is an empty div, used to define a portion of the screen that is clickable-->
            </div>
        </a>
    </div>
</body>

CSS:

<style>

#buffer{}


body{
    background-image:url(Background.png);
    background-size: cover;
    background-repeat: no-repeat;
}

#nav{
    background-color:white;
    opacity:.5;
    width:58%;
    height:50px;
    position:absolute;
    top:25%;
    left:21%;
}

#nav a{
    clear:left;
    float:left;
}

/*Divs that overlay buttons on background image*/
#homeButton{
    background-color:green;
    width:13%;
    height:80%;
    position: absolute;
    left:1%;
    top:2px;
}

#resumeButton{
    background-color:red;
    width:16%;
    height:80%;
    position: absolute;
    left:26%;
    top:2px;
}

#tutorialButton{
    background-color:blue;
    width:17%;
    height:80%;
    position: absolute;
    left:52%;
    top:2px;
}

#contactButton{
    background-color:orange;
    width:17%;
    height:80%;
    position: absolute;
    left:78%;
    top:2px;
}

</style>

【问题讨论】:

  • 你看错了。按钮不应是图像的一部分,而应是图像顶部的单独元素。我建议您回到 所谓的 设计器并获取新的背景图像。任何称职的设计师都应该知道这一点。
  • 什么样的视觉效果可以证明让菜单链接部分背景图像是合理的?只需将恐龙作为身体背景,将“徽标”作为 PNG,菜单应该是具有 RGBA 颜色以实现透明度或 PNG 背景的容器,如果您真的想要渐变文本,链接将作为文本或图像存在。您可以检查这也是css-tricks.com/snippets/css/gradient-text

标签: html css nav


【解决方案1】:

不知道这是否有助于将 Maybe 而不是将图像作为背景..您可以使用标签吗? 这将创建一个可点击的映射图像。 http://www.image-maps.com/ http://www.w3schools.com/tags/tag_map.asp

【讨论】:

  • 我试试看,谢谢。我目前的做法是告诉设计师不要做白痴,并正确地重新制作背景图像。
  • 效果很好,我学会了一个新标签。非常感谢。
  • 没问题..我一直在使用它..确实是一个非常棒的标签。
  • 图像映射?哇,你为什么要把事情复杂化?如果您想添加或删除菜单项,您会怎么做?祝你好运!
【解决方案2】:

您是否尝试过将条形图的位置设置为固定或从顶部固定操作的像素位置。

【讨论】:

  • 我有,页面必须是可滚动的,所以固定是不可能的,像素定位只会让问题变得更糟,因为背景图像会缩放以适应没有导航的设备分辨率栏进行相同的更改。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多