* Bug with psoitioning Fixed bug with positioning of background-color` property for Selector `.heart::after` * Trying new changes * Update curriculum/challenges/english/01-responsive-web-design/applied-visual-design/create-a-more-complex-shape-using-css-and-html.md Co-authored-by: Nicholas Carrigan (he/him) <nhcarrigan@gmail.com> * Tests passing Check the regex matching at [Regex101](https://regex101.com/r/GU18ds/4) * fixed typo * applied suggestions Co-authored-by: Nicholas Carrigan (he/him) <nhcarrigan@gmail.com>
3.9 KiB
id, title, challengeType, videoUrl, forumTopicId, dashedName
id | title | challengeType | videoUrl | forumTopicId | dashedName |
---|---|---|---|---|---|
587d78a6367417b2b2512ade | Create a More Complex Shape Using CSS and HTML | 0 | https://scrimba.com/c/cPpz4fr | 301050 | create-a-more-complex-shape-using-css-and-html |
--description--
One of the most popular shapes in the world is the heart shape, and in this challenge you'll create one using pure CSS. But first, you need to understand the ::before
and ::after
pseudo-elements. These pseudo-elements are used to add something before or after a selected element. In the following example, a ::before
pseudo-element is used to add a rectangle to an element with the class heart
:
.heart::before {
content: "";
background-color: yellow;
border-radius: 25%;
position: absolute;
height: 50px;
width: 70px;
top: -50px;
left: 5px;
}
For the ::before
and ::after
pseudo-elements to function properly, they must have a defined content
property. This property is usually used to add things like a photo or text to the selected element. When the ::before
and ::after
pseudo-elements are used to make shapes, the content
property is still required, but it's set to an empty string. In the above example, the element with the class of heart
has a ::before
pseudo-element that produces a yellow rectangle with height
and width
of 50px and 70px, respectively. This rectangle has round corners due to its 25% border radius and is positioned absolutely at 5px from the left
and 50px above the top
of the element.
--instructions--
Transform the element on the screen to a heart. In the heart::after
selector, change the background-color
to pink and the border-radius
to 50%.
Next, target the element with the class heart
(just heart
) and fill in the transform
property. Use the rotate()
function with -45 degrees.
Finally, in the heart::before
selector, set its content
property to an empty string.
--hints--
The background-color
property of the heart::after
selector should be pink.
const heartAfter = code.match(/\.heart::after\s*{[\s\S]+?[^\}]}/g)[0];
assert(
/({|;)\s*background-color\s*:\s*pink\s*(;|})/g.test(heartAfter)
);
The border-radius
of the heart::after
selector should be 50%.
assert(code.match(/border-radius\s*?:\s*?50%/gi).length == 2);
The transform
property for the heart
class should use a rotate()
function set to -45 degrees.
assert(code.match(/transform\s*?:\s*?rotate\(\s*?-45deg\s*?\)/gi));
The content
of the heart::before
selector should be an empty string.
assert(code.match(/\.heart::before\s*?{\s*?content\s*?:\s*?("|')\1\s*?;/gi));
--seed--
--seed-contents--
<style>
.heart {
position: absolute;
margin: auto;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: pink;
height: 50px;
width: 50px;
transform: ;
}
.heart::after {
background-color: blue;
content: "";
border-radius: 25%;
position: absolute;
width: 50px;
height: 50px;
top: 0px;
left: 25px;
}
.heart::before {
content: ;
background-color: pink;
border-radius: 50%;
position: absolute;
width: 50px;
height: 50px;
top: -25px;
left: 0px;
}
</style>
<div class="heart"></div>
--solutions--
<style>
.heart {
position: absolute;
margin: auto;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: pink;
height: 50px;
width: 50px;
transform: rotate(-45deg);
}
.heart::after {
background-color: pink;
content: "";
border-radius: 50%;
position: absolute;
width: 50px;
height: 50px;
top: 0px;
left: 25px;
}
.heart::before {
content: "";
background-color: pink;
border-radius: 50%;
position: absolute;
width: 50px;
height: 50px;
top: -25px;
left: 0px;
}
</style>
<div class="heart"></div>