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.
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 setprops.children
. Result:<div>{props.children}</div>
. - To add a class name to the
div
element, use theclassName
attribute and set it toalert
. Result:className="alert"
. - To import the file with styles in the
index.js
file, useimport
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.
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 2. Kapitel 7
Fråga AI
Fråga AI
Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal
Awesome!
Completion rate improved to 2.17
Challenge: Apply External CSS to a React App
Svep för att visa menyn
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.
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 setprops.children
. Result:<div>{props.children}</div>
. - To add a class name to the
div
element, use theclassName
attribute and set it toalert
. Result:className="alert"
. - To import the file with styles in the
index.js
file, useimport
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.
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 2. Kapitel 7