下面是我的head标签中的脚本。min-width:500运行正常,但紧接着的下一个查询max-width:499px似乎不起作用,我在使用和不使用screen and的情况下都尝试了一下,甚至在styles.css样式表中添加它也不起作用。我只是在我的屏幕上尝试它,它应该是工作的。有人能发现我做错了什么吗?
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
h2 {
color: orangered;
text-align: center;
}
@media screen and (min-width: 500px) {
body{
color:greenyellow;
background-color: black;
}
}
@media screen and (max-width: 499px) {
body {
color:pink;
background-color: navy;
}
}
</style>
<link rel = "stylesheet" href = "styles.css">谁能告诉我为什么我的VSCode不能预测mid-width或max-width,而是在写的时候接受它。
发布于 2020-07-08 12:27:24
我在VS代码中检查了你的代码,它可以很好地处理背景颜色,但它不会改变文本的颜色(H2标签),我不认为VS代码有任何问题,你可以这样做来改变文本颜色。
当您编写媒体查询时,您会更改正文中的背景颜色和文本,但如果您使用的是h2标签,则它不起作用,因此您应该为h2编写特定的代码
试试下面的代码...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
h2 {
color: orangered;
text-align: center;
}
@media screen and (min-width: 500px) {
h2 {
color: green;
}
body {
background-color: black;
}
}
@media screen and (max-width: 499px) {
h2 {
color: pink;
}
body {
background-color: navy;
}
}
</style>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h2>TechWithVP</h2>
Some other text
</body>
</html>https://stackoverflow.com/questions/62787348
复制相似问题