Course Content
React Mastery
React Mastery
Challenge: Apply External CSS to a React App
Task
We will now proceed to create the Alert
component, which will render all the elements passed as children and apply some specific styles to it. The task is:
Create the component
Alert
that has thediv
element inside.The
div
element should have thealert
class name.The
div
element should have thechildren
prop as the content.The
div
element should have the following CSS.
css
To create aΒ
div
Β element in the component, useΒ<div>...</div>
.To passΒ
props.children
Β as the text content enclose it withinΒ{...}
Β and setΒprops.children
. Result:Β<div>{props.children}</div>
.To add a class name to theΒ
div
Β element, use theΒclassName
Β attribute and set it toΒalert
. Result:ΒclassName="alert"
.To import the file with styles in theΒ
index.js
Β file, useΒimport
Β statement and provide the correct path to the file. Result:Βimport './index.css'
.To apply styles to theΒ
div
Β element, use the class name selectorΒ.alert
Β and insert the styles from the task.
Thanks for your feedback!