EN
React - multiple classNames in one element
0 points
In this article we would like to show you how to add multiple classNames to one element in React.
Below example shows two CSS styles: .border
and .background
.
We add both styles to the div
by using className
property with space between the classNames.
App.css
file:
xxxxxxxxxx
1
.border {
2
border: dashed;
3
border-color: red;
4
}
5
6
.background {
7
background-color: greenyellow;
8
}
App.jsx
file:
xxxxxxxxxx
1
import React from 'react';
2
import './App.css';
3
4
const App = () => {
5
return (
6
<div className="background border">
7
My div
8
</div>
9
);
10
};
Note:
Styles can be placed in two separate files, we just need to import both of them and add styles with the same method.
Browser output:
