[英]How to apply media query in Gatsby site?
Here is my index.js code.这是我的 index.js 代码。
import * as styles from "../styles/home.module.css";
export default function index() {
return (
<section id="#">
<div
className={styles.heading}>
Hello World!
</div>
</section>
}
Here is my CSS file home.module.css这是我的 CSS 文件 home.module.css
.heading {
color: yellow;
}
@media screen and (max-width:768px) {
.heading{
color: red;
}
}
The original color of the text remains yellow.文本的原始颜色保持黄色。 I don't know why but when I resize the window the color does not change to red.
我不知道为什么,但是当我调整 window 的大小时,颜色不会变为红色。 May I know where I am wrong or what is the possible solution?
我可以知道我错在哪里或可能的解决方案是什么吗?
First of all, you must import react
.首先,你必须导入
react
。
import * as React from 'react'
And you are missing close parenthesis )
.而且您缺少右括号
)
。
I've made some changes and it works well on my end.我做了一些改变,它对我来说效果很好。
import * as React from 'react'
import * as styles from './home.module.css'
const IndexPage = () => (
<section id="#">
<div className={styles.heading}>Hello World!</div>
</section>
)
export default IndexPage
home.module.css home.module.css
.heading {
color: yellow;
@media screen and (max-width: 768px) {
color: red;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.