Challenge: Style a React Application
Swipe to show menu
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
Alertthat has thedivelement inside. - The
divelement should have thealertclass name. - The
divelement should have thechildrenprop as the content. - The
divelement should have the following CSS.
padding: 20px;
border-radius: 10px;
background-color: lightgreen;
color: darkmagenta;
- 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.
Everything was clear?
Thanks for your feedback!
Sectionย 4. Chapterย 4
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Sectionย 4. Chapterย 4