【发布时间】: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