gpt4 book ai didi

html - 标题图片位置固定

转载 作者:行者123 更新时间:2023-11-28 08:49:54 26 4
gpt4 key购买 nike

我正在为某人开发一个网站,我需要在网站的左上角添加一个标题图片。但是发生的事情是图像似乎处于固定位置,因此每当我将网页移动到不同的分辨率时,它似乎停留在原处,而其他一切都在移动。最重要的是,我需要图像重叠导航,但每当我改变图像的高度时,它只会改变标题本身的高度,从而使导航更远......

The Image I am referring to is in the html <img src="newImage/papaPic.jpg">  with the CSS being #header img{...}

CSS

body {
background: url(../newImages/headerBackground.jpg) repeat;
font-family: Arial, Helvetica, sans-serif;
//font-size: 14px;
margin: 0;
padding: 0;
}
#header {
background: url(../images/bg-header.png) repeat-x bottom center;
margin: 0;
text-align: center;
display: block;
}
#header img {
display: block;
margin: 0 auto;
width: 230px;
margin-left:0px;
height:250px;
}

#header ul {
background: url(../images/menu-border.gif) no-repeat bottom left;
margin: 0 auto;
overflow: hidden;
padding: 0 0 0 1px;
width: 970px;
position:relative;
left:5%;


}

#header ul li {
background: url(../images/bg-menu.gif) repeat-x bottom center;
border-top: 2px solid #4f5342;
float: left;
list-style: none;
margin: 0;
padding: 0;
}

HTML

<html>
<head>
<meta charset="UTF-8">
<title>Jay Cousins</title>
<link rel="stylesheet" href="css/site.css" type="text/css">
</head>
<body>
<div id="header">
<img src="newImages/papaPic.jpg">
<ul>
<li class="selected">
<a href="index.html">home</a>
</li>
<li>
<a href="about.html">Opportunities</a>
</li>
<li>
<a href="admission.html">Project Management</a>
</li>
<li>
<a href="programs.html">About Jay</a>
</li>
<li>
<a href="calendar.html">Community</a>
</li>
<li>
<a href="blog.html">Contact</a>
</li>

</ul>
</div>

最佳答案

这是你需要的吗?

body {
background: url(../newImages/headerBackground.jpg) repeat;
font-family: Arial, Helvetica, sans-serif;
//font-size: 14px;
margin: 0;
padding: 0;
}
#header {
background: url(../images/bg-header.png) repeat-x bottom center;
display: block;
margin: 0;
position: relative;
text-align: center;
}
#header img {
display: block;
height:250px;
position: absolute;
width: 230px;
}

#header ul {
background: url(../images/menu-border.gif) no-repeat bottom left;
margin: 0 auto;
overflow: hidden;
padding: 20px 5px 0 5px;
position: relative;
width: 970px;
z-index: 10;
}

#header ul li {
background: url(../images/bg-menu.gif) repeat-x bottom center;
border-top: 2px solid #4f5342;
float: left;
list-style: none;
margin: 0;
padding: 0;
}

最重要的变化是 img 上的 position: absolute、#header 上的 position: relativeposition: relative和 ul 上的 z-index

关于html - 标题图片位置固定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27411332/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com