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
divelement in the component, use<div>...</div>. - To pass
props.childrenas the text content enclose it within{...}and setprops.children. Result:<div>{props.children}</div>. - To add a class name to the
divelement, use theclassNameattribute and set it toalert. Result:className="alert". - To import the file with styles in the
index.jsfile, useimportstatement and provide the correct path to the file. Result:import './index.css'. - To apply styles to the
divelement, use the class name selector.alertand 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
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
divelement in the component, use<div>...</div>. - To pass
props.childrenas the text content enclose it within{...}and setprops.children. Result:<div>{props.children}</div>. - To add a class name to the
divelement, use theclassNameattribute and set it toalert. Result:className="alert". - To import the file with styles in the
index.jsfile, useimportstatement and provide the correct path to the file. Result:import './index.css'. - To apply styles to the
divelement, use the class name selector.alertand insert the styles from the task.
Everything was clear?
Thanks for your feedback!
Section 2. Chapter 7