CSS 定位在代码编辑器中不起作用

CSS positioning not working in the code editor

我有这个简单的问题。我希望我的导航保持在顶部。我知道代码应该是:

position: fixed;
top: 0;
left: 0;

但问题是,无论何时我将它插入开发模式(我编写代码的地方),它都不会改变,但在检查元素中,它可以正常工作。问题是我应该使用什么(class 名称或 ID 或您建议的任何内容)以便我可以编辑代码。

好吧,我想说在使用 css 时位置非常重要,无论如何你可以选择很多不同的位置,比如我为我的示例选择的 fixed ,此外你还有绝对的,相对的等等。 有关更多信息,请查看此示例并转到 http://www.w3schools.com 并查找 css positioning

p.pos_fixed {
    position: fixed;
    top: 30px;
    right: 5px;
    color: red;
}
<!DOCTYPE html>
<html>
<body>

<p><b>Note:</b> IE7 and IE8 supports the fixed value only if a !DOCTYPE is specified.</p>
<p>Some text</p><p>Some text</p><p>Some text</p><p>Some text</p><p>Some text</p><p>Some text</p><p>Some text</p><p>Some text</p><p>Some text</p><p>Some text</p><p>Some text</p><p>Some text</p><p>Some text</p><p>Some text</p><p>Some text</p><p>Some text</p>
<p class="pos_fixed">Some positioned text.</p>
</body>
</html>

虽然你的问题对我来说不是很清楚,但我认为这回答了你的问题:

在 HTML 中给你的导航栏一个 id:

<div id='nav-bar'></div> <!-- or <navigation> or <header> or whatever -->

在CSS

#nav-bar {
  position: fixed;
  top: 0;
  left: 0;
}