* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2.5 KiB
2.5 KiB
id, title, challengeType, videoUrl, forumTopicId, dashedName
id | title | challengeType | videoUrl | forumTopicId | dashedName |
---|---|---|---|---|---|
587d781e367417b2b2512acc | 固定定位的参照物是浏览器的窗口 | 0 | https://scrimba.com/c/c2MDNUR | 301061 | lock-an-element-to-the-browser-window-with-fixed-positioning |
--description--
接下来要介绍的是 fixed
定位,它是一种特殊的绝对(absolute)定位,区别是其包含块是浏览器窗口。和绝对定位类似,在 fixed
定位的元素中,我们也可以使用 top、bottom、left、right 属性来调整元素的位置,并且也会将元素从当前的文档流里面移除,其它元素会忽略它的存在。
但 fixed
和 absolute
的最明显的区别在于,fixed
定位元素不会随着屏幕滚动而移动。
--instructions--
我们已经将代码里导航栏的 id 设置为了 navbar
。请把它的 position
设置成 fixed
,同时分别设定其 top
和 left
属性值为 0 像素。修改后,你可以滑动预览窗口,观察导航栏的位置。
--hints--
#navbar
元素的 position
属性值应为 fixed
。
assert($('#navbar').css('position') == 'fixed');
#navbar
元素的 top
属性值应为 0px
。
assert($('#navbar').css('top') == '0px');
#navbar
元素的 left
属性值应为 0px
。
assert($('#navbar').css('left') == '0px');
--seed--
--seed-contents--
<style>
body {
min-height: 150vh;
}
#navbar {
width: 100%;
background-color: #767676;
}
nav ul {
margin: 0px;
padding: 5px 0px 5px 30px;
}
nav li {
display: inline;
margin-right: 20px;
}
a {
text-decoration: none;
}
</style>
<body>
<header>
<h1>Welcome!</h1>
<nav id="navbar">
<ul>
<li><a href="">Home</a></li>
<li><a href="">Contact</a></li>
</ul>
</nav>
</header>
<p>I shift up when the #navbar is fixed to the browser window.</p>
</body>
--solutions--
<style>
body {
min-height: 150vh;
}
#navbar {
position: fixed;
top: 0;
left: 0;
width: 100%;
background-color: #767676;
}
nav ul {
margin: 0px;
padding: 5px 0px 5px 30px;
}
nav li {
display: inline;
margin-right: 20px;
}
a {
text-decoration: none;
}
</style>
<body>
<header>
<h1>Welcome!</h1>
<nav id="navbar">
<ul>
<li><a href="">Home</a></li>
<li><a href="">Contact</a></li>
</ul>
</nav>
</header>
<p>I shift up when the #navbar is fixed to the browser window.</p>
</body>