如何让 div 一直漂浮在同一个地方?
How to make a div float at the same place at all time?
我想要的
- 我想让我的 div 漂浮起来,并一直呆在那里 - 与此类似。
我有什么
我试过的
PHP
<div id="nav-bar">
<ul class="inline">
<?php
foreach(array_unique(array_values($continent)) as $continent_id){
if($continent_id == 1 ) $continent_name = "Europe" ;
elseif ($continent_id == 2 ) $continent_name = "Asia" ;
elseif ($continent_id == 3 ) $continent_name = "North America" ;
elseif ($continent_id == 4 ) $continent_name = "Oceania" ;
elseif ($continent_id == 5 ) $continent_name = "South America" ;
else $continent_name = "Africa" ;
?>
<li><a href="#<?php echo $continent_name ?>"><?php echo $continent_name ?></a></li>
<?php }?>
</ul>
</div>
- 备注
id="nav-bar"
CSS
#nav-bar {
width: 960px;
margin: 0 auto;
position: absolute;
top: 100;
left:200;
z-index: 10;
}
position:fixed;
将此添加到您的 div.and 上下滚动它也将是 float.add z-index..
假设您在浏览器中指的是同一位置 window,您需要 position: fixed;
而不是 position: absolute;
。
使用这些 css 样式:
#navbar {
position: fixed;
left: 0;
top: 0;
}
尝试position: fixed;
position: absolute;
将元素放在其最内层 positioned 父元素内的固定位置。它通常用于将元素放置在页面内的固定位置。
position: fixed;
将其保持在视口内的固定位置(浏览器的 window)。
请参阅 documentation 的 position
属性。
您忘记将 px(度量单位)添加到 top 和 left。
例如:
top:100px;
left:200px;
我想要的
- 我想让我的 div 漂浮起来,并一直呆在那里 - 与此类似。
我有什么
我试过的
PHP
<div id="nav-bar">
<ul class="inline">
<?php
foreach(array_unique(array_values($continent)) as $continent_id){
if($continent_id == 1 ) $continent_name = "Europe" ;
elseif ($continent_id == 2 ) $continent_name = "Asia" ;
elseif ($continent_id == 3 ) $continent_name = "North America" ;
elseif ($continent_id == 4 ) $continent_name = "Oceania" ;
elseif ($continent_id == 5 ) $continent_name = "South America" ;
else $continent_name = "Africa" ;
?>
<li><a href="#<?php echo $continent_name ?>"><?php echo $continent_name ?></a></li>
<?php }?>
</ul>
</div>
- 备注
id="nav-bar"
CSS
#nav-bar {
width: 960px;
margin: 0 auto;
position: absolute;
top: 100;
left:200;
z-index: 10;
}
position:fixed;
将此添加到您的 div.and 上下滚动它也将是 float.add z-index..
假设您在浏览器中指的是同一位置 window,您需要 position: fixed;
而不是 position: absolute;
。
使用这些 css 样式:
#navbar {
position: fixed;
left: 0;
top: 0;
}
尝试position: fixed;
position: absolute;
将元素放在其最内层 positioned 父元素内的固定位置。它通常用于将元素放置在页面内的固定位置。
position: fixed;
将其保持在视口内的固定位置(浏览器的 window)。
请参阅 documentation 的 position
属性。
您忘记将 px(度量单位)添加到 top 和 left。 例如:
top:100px;
left:200px;