【发布时间】:2021-08-01 09:04:28
【问题描述】:
我一直在尝试和寻找几个小时,但我找不到我的问题的解决方案。 我试图在 Next JS 中为我的媒体查询断点使用不同的文件,但它们似乎什么也没做。
我在以下位置创建它们: styles/queries/sizeone.css(第一个断点)
我像这样在我的 _app.tsx 上导入了它们,并且还覆盖了默认 Next JS 头部的视口标签。
import { AppProps } from 'next/app';
import Head from 'next/head'
import '../styles/globals.css'
import '../styles/normalize.css'
import '../styles/queries/sizeone.css'
function App({ Component, pageProps }: AppProps) {
return (
<>
<Head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</Head>
<Component {...pageProps} />
</>
)
}
export default App;
这就是我在 sizeone.css 文件中所做的,它只是一个简单的媒体查询。
@media only screen and (min-width: 1px) and (max-width: 767px){
#hero .content .title h1 {
text-align: center;
color: var(--main-color);
font-family: var(--main-font);
font-weight: 700;
font-size: 20px;
margin: 0 0;
}
}
这就是我将样式应用于元素的方式:
<section id={styles.hero}>
<div className="wrapper">
<div className={styles.content}>
<div className={styles.title}>
<h1>Creating <span className="gradient-text">remarkable</span> <br /><span className="gradient-text">experiences</span> through digital art.</h1>
<p>Freelancing UI/UX design & Front-end development</p>
这是 sizeone.css 文件中显示的部分。
感谢您抽出宝贵时间阅读我的问题,希望我们能找到解决方案:)
【问题讨论】:
-
您好 Gonçalo,欢迎来到 StackOverflow。您提供的示例并未真正显示您如何将样式应用于任何标签/组件。请根据以下内容提供最小的可重现示例:stackoverflow.com/help/minimal-reproducible-example
-
嘿!我刚刚添加了我实际将样式应用于元素的方式,希望它有所帮助,并且根据最小的可重现示例。
标签: css next.js responsive