3.8 KiB
3.8 KiB
id, title, challengeType, forumTopicId, localeTitle
id | title | challengeType | forumTopicId | localeTitle |
---|---|---|---|---|
587d7fa5367417b2b2512bbd | Extend One Set of CSS Styles to Another Element | 0 | 301456 | Расширение одного набора стилей CSS для другого элемента |
Description
extend
которая упрощает заимствование правил CSS из одного элемента и построение на них в другом. Например, .panel
блок правил CSS .panel
класс .panel
. Он имеет background-color
, height
и border
. .panel {Теперь вам нужна другая панель под названием
background-color: red;
высота: 70px;
граница: 2px сплошной зеленый;
}
.big-panel
. Он имеет те же базовые свойства, что и .panel
, но также требует width
и font-size
. Можно скопировать и вставить исходные правила CSS из .panel
, но код становится повторяющимся, когда вы добавляете больше типов панелей. Директива extend
- это простой способ повторного использования правил, написанных для одного элемента, а затем добавить другое для другого: .big панели {
@extend .panel;
ширина: 150 пикселей;
font-size: 2em;
}
.big-panel
будет иметь те же свойства, что и .panel
в дополнение к новым стилям.
Instructions
.info-important
который расширяет .info
а также имеет background-color
установленный на пурпурный.
Tests
tests:
- text: Your <code>info-important</code> class should have a <code>background-color</code> set to <code>magenta</code>.
testString: assert(code.match(/\.info-important\s*?{[\s\S]*background-color\s*?:\s*?magenta\s*?;[\s\S]*}/gi));
- text: Your <code>info-important</code> class should use <code>@extend</code> to inherit the styling from the <code>info</code> class.
testString: assert(code.match(/\.info-important\s*?{[\s\S]*@extend\s*?.info\s*?;[\s\S]*/gi));
Challenge Seed
<style type='text/sass'>
h3{
text-align: center;
}
.info{
width: 200px;
border: 1px solid black;
margin: 0 auto;
}
</style>
<h3>Posts</h3>
<div class="info-important">
<p>This is an important post. It should extend the class ".info" and have its own CSS styles.</p>
</div>
<div class="info">
<p>This is a simple post. It has basic styling and can be extended for other uses.</p>
</div>
Solution
<style type='text/sass'>
h3{
text-align: center;
}
.info{
width: 200px;
border: 1px solid black;
margin: 0 auto;
}
.info-important{
@extend .info;
background-color: magenta;
}
</style>
<h3>Posts</h3>
<div class="info-important">
<p>This is an important post. It should extend the class ".info" and have its own CSS styles.</p>
</div>
<div class="info">
<p>This is a simple post. It has basic styling and can be extended for other uses.</p>
</div>