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
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Β 2. ChapterΒ 7
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Suggested prompts:
Can you explain how to use the Alert component in my React app?
What should the index.css file contain for the Alert styles?
Can you clarify how to pass children to the Alert component?
Awesome!
Completion rate improved to 2.17
Challenge: Apply External CSS to a React App
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Β 2. ChapterΒ 7