2.7 KiB
2.7 KiB
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
bad82fee1322bd9aedf08721 | Understand Absolute versus Relative Units | 0 | 了解绝对与相对单位 |
Description
px
)。像素是一种长度单位,它告诉浏览器如何调整项目的大小或空间。除了px
,CSS还有许多不同的长度单位选项供您使用。两种主要类型的长度单位是绝对的和相对的。绝对单位与长度的物理单位相关联。例如, in
和mm
表示英寸和毫米。绝对长度单位接近屏幕上的实际测量值,但根据屏幕的分辨率存在一些差异。相对单位,例如em
或rem
,相对于另一个长度值。例如, em
基于元素字体的大小。如果您使用它来设置font-size
属性本身,则它相对于父级的font-size
。 注意 有几个相对单位选项与视口的大小相关联。它们包含在响应式Web设计原则部分中。
Instructions
red-box
向元素添加padding
属性并将其设置为1.5em
。 Tests
tests:
- text: 你的<code>red-box</code>类应该有一个<code>padding</code>属性。
testString: 'assert($(".red-box").css("padding-top") != "0px" && $(".red-box").css("padding-right") != "0px" && $(".red-box").css("padding-bottom") != "0px" && $(".red-box").css("padding-left") != "0px", "Your <code>red-box</code> class should have a <code>padding</code> property.");'
- text: 你的<code>red-box</code>类应该给出1.5em的<code>padding</code>元素。
testString: 'assert(code.match(/\.red-box\s*?{\s*?.*?\s*?.*?\s*?padding:\s*?1\.5em/gi), "Your <code>red-box</code> class should give elements 1.5em of <code>padding</code>.");'
Challenge Seed
<style>
.injected-text {
margin-bottom: -25px;
text-align: center;
}
.box {
border-style: solid;
border-color: black;
border-width: 5px;
text-align: center;
}
.yellow-box {
background-color: yellow;
padding: 20px 40px 20px 40px;
}
.red-box {
background-color: red;
margin: 20px 40px 20px 40px;
}
.green-box {
background-color: green;
margin: 20px 40px 20px 40px;
}
</style>
<h5 class="injected-text">margin</h5>
<div class="box yellow-box">
<h5 class="box red-box">padding</h5>
<h5 class="box green-box">padding</h5>
</div>
Solution
// solution required