有没有办法让媒体查询选择特定页面?

Cal*_*sto 2 html css media-queries responsive-design

我使用单独的 CSS 文件制作了一个网站,现在我想将它们组合起来。问题是我不能简单地将所有内容复制/粘贴到 1 个文件中,因为我的媒体查询具有不同的 html、h1、h2、h3 值。

有没有办法让媒体查询指定一个页面,让它只选择主页的html和h1,而不改变联系页面的html和h1?

编辑:这是一个 Wordpress 自定义模板,因此所有页面将共享相同的标题和 html 开始标记。

例子:

我将如何合并这两个文件?

索引.css:

html {
    font-size: 16px;
}

h1 {
    font-size: 1.5rem;
}

@media only screen and (min-device-width: 700px) {
    html {
        font-size: 17px;
    }
    h1 {
        font-size: 2rem;
    }
}
Run Code Online (Sandbox Code Playgroud)

联系方式.css:

html {
    font-size: 18px;
}

h1 {
    font-size: 1rem;
}

@media only screen and (min-device-width: 700px) {
    html {
        font-size: 19px;
    }
    h1 {
        font-size: 1.5rem;
    }
}
Run Code Online (Sandbox Code Playgroud)

Pra*_*man 7

为该特定页面提供一个类,如下所示:

<html class="specific-page">
Run Code Online (Sandbox Code Playgroud)

在 CSS 中:

@media only screen and (min-device-width: 700px) {
    html.specific-page {
        font-size: 19px;
    }
    .specific-page h1 {
        font-size: 1.5rem;
    }
}
Run Code Online (Sandbox Code Playgroud)

或者:

  1. 将此<link />单独添加到该特定页面。
  2. 或者作为<style>该特定页面中的标签。

  • @Calisto 您可以在 WordPress 中提供页面级别的样式。`:)` 否则,对于特定页面,只需给出:`document.body.parentNode.classList.add("specific-page");` 大声笑。`:D` (2认同)