我正在使用Twitter Bootstrap构建一个站点,并在页面顶部有一个40px固定位置导航栏.我设置了一些锚点以跳转到整个页面中的各种H1,但锚点目标最终被导航栏部分遮挡.有没有办法将链接偏移到导航栏的帐户?我已经看到一个建议将每个锚放在它自己的偏移div中,但这似乎是很多重复的代码,我想知道是否还有另一种方法.
如果可能的话,我宁愿用CSS而不是jQuery来做这件事,但任何解决方案都是受欢迎的.
.topbar {
height: 40px;
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 10000;
overflow: visible;
}
body {
padding-top: 40px;
/* 40px to make the container go all the way to the bottom of the topbar */
font-family: 'Proxima', "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
line-height: 18px;
font-weight: normal;
color: #555;
background-color: #eee;
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
我是Javascript的新手(以及一般的编程),并且一直在努力掌握使用DOM的基本知识.如果这是一个非常基本的错误,请道歉,但我环顾四周,找不到答案.
我正在尝试使用appendChild方法将标题和一些段落文本添加到下面的基本HTML文件中.
<html>
<head>
<title>JS Practice</title>
</head>
<body>
<script src="script.js"></script>
<div id = "main">
<h1>Simple HTML Page</h1>
<p>This is a very simple HTML page.</p>
<p>It's about as basic as they come. It has: </p>
<ul>
<li>An H1 Tag</li>
<li>Two paragraphs</li>
<li>An unordered list</li>
</ul>
</div>
<div id="javascript">
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是js代码:
var newHeading = document.createElement("h1");
var newParagraph = document.createElement("p");
newHeading.innerHTML = "New Heading!";
newParagraph.innerHTML = "Some text for a paragraph.";
document.getElementById("javascript").appendChild(newHeading);
document.getElementById("javascript").appendChild(newParagraph);
Run Code Online (Sandbox Code Playgroud)
运行它会导致错误:"无法调用方法'appendChild'为null"
救命?我无法弄清楚为什么这不起作用......