我有一个矩阵背景的东西功能齐全,但我只想让我的标题随滚动一起移动,每次我将.content部分更改为不同的位置时它会完全取消矩阵(矩阵实际上并不是一个背景,它更像是一个背后的区域。
<style type="text/css">
body{
margin:0px;
background:#000;
}
.header-cont {
width:100%;
position:fixed;
top:0px;
}
.header {
height:50px;
background:#000;
border:1px solid #0F0;
width:960px;
margin:0px auto;
}
.content {
overflow: hidden;
width:960px;
background: #000;
border: 1px solid #0F0;
height: 4000px;
margin: 70px auto;
}
&#13;
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Tech Time</title>
<link href="../CSS/something.css" rel="stylesheet" type="text/css">
<link href="../CSS/canvas.css" rel="stylesheet" type="text/css">
<link href=".noscroll.css" rel="stylesheet" type="text/css">
<head>
<style type="text/css">
body{
margin:0px;
background:#000;
}
.header-cont {
width:100%;
position:fixed;
top:0px;
}
.header {
height:50px;
background:#000;
border:1px solid #0F0;
width:960px;
margin:0px auto;
}
.content {
overflow: hidden;
width:960px;
background: #000;
border: 1px solid #0F0;
height: 4000px;
margin: 70px auto;
}
</style>
</head>
<body>
<div class="header-cont">
<div class="header"></div>
<div class="content">
<table width="960" border="1">
<tbody>
<tr>
<td width="338" height="180"><img src="file:///home/146971/Desktop/bigstock-128312288-1024x794.jpg" width="338" height="180" alt=""/></td>
<td width="311" align="left" valign="top" style="color: #00FF00"><p style="font-family: Cambria, 'Hoefler Text', 'Liberation Serif', Times, 'Times New Roman', serif; font-weight: bold;">Juicero - Silicon Valleys Failure</p>
<p>By: <span style="font-style: italic">Alex Diaz</span> / <span style="font-family: Cambria, 'Hoefler Text', 'Liberation Serif', Times, 'Times New Roman', serif">April 24</span></p>
<p> </p>
<p style="font-family: Cambria, 'Hoefler Text', 'Liberation Serif', Times, 'Times New Roman', serif">Juice — yes, the beverage — has experienced a renaissance of late: Juice bars. Juice cleanses. Juices for enlightenment, juices for energy, juices that might just cure cancer...</p>
<p style="font-family: Cambria, 'Hoefler Text', 'Liberation Serif', Times, 'Times New Roman', serif; font-size: 10px;"> </p>
<p style="font-family: Cambria, 'Hoefler Text', 'Liberation Serif', Times, 'Times New Roman', serif; font-size: 10px;"> </p></td>
<td width="289" rowspan="3"> </td>
</tr>
<tr>
<td height="180"><img src="file:///home/146971/Desktop/watch.jpg" width="338" height="180" alt=""/></td>
<td align="left" valign="top" style="color: #00FF00; font-family: Cambria, 'Hoefler Text', 'Liberation Serif', Times, 'Times New Roman', serif; font-weight: bold;"><p>Fitbit's upcoming smartwatch has reportedly been a giant mess!</p>
<p style="font-weight: normal">By: <span style="font-style: italic">Michael Esch</span> / May 2</p>
<p style="font-weight: normal"> </p>
<p style="font-weight: normal">Yahoo Finance has nabbed a couple of photos. Reported to show Fitbit’s upcoming smartwatch, along with a handful of reports that make the whole undertaking sound like one big fiasco...</p>
<p> </p></td>
</tr>
<tr>
<td height="180"><img src="file:///home/146971/Desktop/jive.jpg" width="338" height="180" alt=""/></td>
<td align="left" valign="top" style="font-family: Cambria, 'Hoefler Text', 'Liberation Serif', Times, 'Times New Roman', serif; font-weight: bold; color: #00FF00;"><p>Collaboration software company Jive to be aquired by Aurea for 462 million</p>
<p style="font-weight: normal; font-style: normal;">By: <span style="font-style: italic">Ivan Diaz</span> / May 2</p>
<p style="font-weight: normal; font-style: normal;"> </p>
<p style="font-weight: normal; font-style: normal;"> Jive, a community collaboration software company that was one of the biggest Enterprise 2.0-era success stories, going public in 2011, announced today it had agreed to be acquired by ESW...</p></td>
</tr>
<tr>
<td height="180"> </td>
<td align="left" valign="top" style="font-family: Cambria, 'Hoefler Text', 'Liberation Serif', Times, 'Times New Roman', serif; font-weight: bold; color: #00FF00;"> </td>
<td> </td>
</tr>
</tbody>
</table>
<p> </p>
</div>
</div>
<br><br><br>
<body>
<ul class="menu1">
<li></li>
<li><a href="HOME.html"> Home </a></li>
<li><a href="#">News</a>
<ul>
<li><a href="Tech.html" class="documents">Tech</a></li>
<li><a href="Political.html" class="documents">World</a></li>
<li><a href="Science.html" class="documents">Science</a></li>
</ul>
</li>
<li><a href="#">Store</a>
<ul>
<li><a href="scom.html" class="documents">Computer</a></li>
<li><a href="sgad.html" class="messages">Gadget</a></li>
<li><a href="sran.html" class="signout">Random</a></li>
</ul>
</li>
<li><a href="#" class="menu2">Tutorials</a>
<ul>
<li><a href="java.html" class="Java">Java</a></li>
<li><a href="css.html" class="Css">CSS</a></li>
<li><a href="html.html" class="HTML">HTML</a></li>
<li><a href="javascript.html" class="HTML">JavaScript</a></li>
<li><a href="elixer.html" class="HTML">Elixer</a></li>
<li><a href="swift.html" class="HTML">Swift</a></li>
</ul>
</li>
<li><a href="#">Videos</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
</body>
<head>
<canvas id="c"></canvas>
</head>
<body>
<script type="text/javascript" src="../JS/tech.js"></script>
</body>
</head>
</head>
</html>
&#13;
答案 0 :(得分:2)
你的问题有点难以理解,请原谅我,如果这不是你想要的,但这里有一个小提琴,你可以看到如何修改你的标题到顶部/左边,以防止它滚动内容:
.header {
height: 200px;
width: 100%;
background: red;
position: fixed;
top: 0;
left: 0;
}
.content {
height: 1000px;
margin-top: 200px;
background: green;
}
答案 1 :(得分:1)
我不确定你在这里究竟是什么意思,但是如果你想要的是在滚动页面顶部停留的固定标题,那么你应该试试这个。
.header {
height:50px;
background:#000;
border:1px solid #0F0;
width:960px;
position: fixed;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
top:0;
}
在codepen上测试它保持固定并在滚动页面顶部居中。