[英]Header/Content alignment/positioning
I am trying to create a website with a header that is fixed at top but always centered (unless the screen is too small I want it to sit on the left side and crop at the right), and then I want my content to scroll up underneath the header so that the header stays as is, but you can scroll through the bottom of the page. 我正在尝试创建一个标题固定在顶部但始终居中的网站(除非屏幕太小,我希望它坐在左侧并在右侧裁剪),然后我希望内容向上滚动在标题下方,以便标题保持原样,但是您可以滚动浏览页面底部。 Here is the code I have now:
这是我现在拥有的代码:
<body>
<div id="header_img">
<span class="class1">
<a href="index.html"><h2>HEATHER</h2></a></span>
<p class="style5">
419.953.5098<br>
<span class="class2">
<a href ="mailto:obringhm@mail.uc.edu">obringhm@mail.uc.edu</a></span></p>
<table>
<tr>
<td><a href="b5_photo_portrait.html">portraits</a></td>
<td><a href="b5_photo_object.html">objects</a></td>
<td>records
</td>
</tr>
</table>
</div>
<div id="header_img2" style="scroll:auto">
<img class="project14"src="images/image17.jpg">
<img class="project15" src="images/image16.jpg">
<img class="project16" src="images/image20.jpg">
<h3>Portrait Series</h3>
<p>This project is an exploration of composition within a photograph and
the studying of correct value tones in a picture.
<br><br>
Completed: December 2011<br>
Tools: Film Photography
<br></p>
</div>
</body>
and the css: 和CSS:
#header_img {
height: 180px;
background: #E2E2E2;
width: 998px;
position: fixed;
top: -25px;
margin: 0 auto;
z-index: 11;
box-shadow: 0 6px 10px -10px #888;
}
#header_img2 {
height: 800px;
background: E2E2E2;
width: 998px;
position: relative;
top: 200;
z-index: 10;
}
Right now, I have the content scrolling underneath the header, but the header is fixed to the left! 现在,内容在标题下方滚动,但是标题固定在左侧!
Honestly your code is a bit of a mess. 老实说,您的代码有些混乱。 Your problem is arising because your div is inside a container with no width set.
因为您的div位于未设置宽度的容器内,所以出现了您的问题。 Setting a width and margin on the body or putting your code inside a container with a width and margin will fix your issue.
在主体上设置宽度和边距或将代码放入具有宽度和边距的容器中将解决您的问题。
body{width:960px; margin:0 auto;}
Now the other issues. 现在其他问题。
See this fiddle: http://jsfiddle.net/calder12/r43me/2/ 看到这个小提琴: http : //jsfiddle.net/calder12/r43me/2/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.