I tried to add two classname form styles but I could not add two CSS classes in a single div.
my code is as follows:
blog.js
JavaScript
x
16
16
1
2
import styles from '../styles/Home.module.css'
3
.
4
<div className={styles.container}>
5
<h2 >Recent Blogs</h2>
6
<hr/>
7
{blogs.map((data)=>{
8
return <div key={data.slug}>
9
<div className={'${styles.card} ${styles.canclick}'}>
10
<Link href={`blogpost/${data.slug}`}><h3>{data.title}</h3>
11
</Link>
12
<em>{data.author}</em>
13
</div>
14
<p>{data.content.substr(0,200)}</p>
15
</div>
16
Home.module.css
JavaScript
1
16
16
1
.canclick{
2
cursor: pointer;
3
}
4
5
.card {
6
margin: 1rem;
7
padding: 1.5rem;
8
text-align: left;
9
color: inherit;
10
text-decoration: none;
11
border: 1px solid #eaeaea;
12
border-radius: 10px;
13
transition: color 0.15s ease, border-color 0.15s ease;
14
max-width: 300px;
15
}
16
Advertisement
Answer
Instead of using single quote, you need to use backtick for template string:
JavaScript
1
6
1
// This works
2
`${styles.card} ${styles.canclick}`
3
4
// This won't work
5
'${styles.card} ${styles.canclick}'
6
Check out this for more context