Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Style a React Application | Styling React Applications
Introduction to React

bookChallenge: 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:

  1. Create the component Alert that has the div element inside.
  2. The div element should have the alert class name.
  3. The div element should have the children prop as the content.
  4. The div element should have the following CSS.
padding: 20px;
border-radius: 10px;
background-color: lightgreen;
color: darkmagenta;
  1. To create aย divย element in the component, useย <div>...</div>.
  2. To passย props.childrenย as the text content enclose it withinย {...}ย and setย props.children. Result:ย <div>{props.children}</div>.
  3. To add a class name to theย divย element, use theย classNameย attribute and set it toย alert. Result:ย className="alert".
  4. 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'.
  5. To apply styles to theย divย element, use the class name selectorย .alertย and insert the styles from the task.

Everything was clear?

How can we improve it?

Thanks for your feedback!

Sectionย 4. Chapterย 4

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Sectionย 4. Chapterย 4
some-alt