gpt4 book ai didi

html - CSS 媒体和查询不起作用?

转载 作者:行者123 更新时间:2023-11-28 12:54:31 26 4
gpt4 key购买 nike

这是我在 header.html 文件中的 CSS 媒体查询代码。我在 html 文件中编写 css 媒体查询。

<style type="text/css">

@media (min-width:100px ) and (max-width:480px ){
.background-color-sec-1-images {
background-image: url("localhost/set/img/img1.jpg");
background-repeat:no-repeat;
background-size:100% 100%;
}
}
@media (min-width:480px ) and (max-width:768px ){
.background-color-sec-1-images {
background-image: url("localhost/set/img/img1.jpg");
background-repeat:no-repeat;
background-size:100% 100%;
}
}
@media (min-width:768px ) and (max-width:1200px ){
.background-color-sec-1-images {
background-image: url("localhost/set/img/img1.jpg");
background-repeat:no-repeat;
background-size:100% 100%;
}
}
</style>

此 CSS 无效。

当我像这样编写 css 时工作正常。

    <style type="text/css">

@media (min-width:100px ){
.background-color-sec-1-images {
background-image: url("localhost/set/img/img1.jpg");
background-repeat:no-repeat;
background-size:100% 100%;
}
}
@media (min-width:480px ){
.background-color-sec-1-images {
background-image: url("localhost/set/img/img1.jpg");
background-repeat:no-repeat;
background-size:100% 100%;
}
}
@media (min-width:768px ){
.background-color-sec-1-images {
background-image: url("localhost/set/img/img1.jpg");
background-repeat:no-repeat;
background-size:100% 100%;
}
}
</style>

但这是覆盖 css。所以这对我不起作用。

但为什么不使用 @media (min-width:100px) 和 (max-width:400px) 查询呢?

谢谢。

最佳答案

编辑:在纯 css 中,您必须声明您的媒体并在 INSIDE 中放置您的条件。

@media print { // rule (1)
#anId{
//something here
}
@media (max-width: 12cm) { // rule (2)
//something here
}
}

here docs

所以您的第一个规则可以是:

@media screen{
@media (min-width:100px ) and (max-width:480px ){
.background-color-sec-1-images {
background-image: url("localhost/set/img/img1.jpg");
background-repeat:no-repeat;
background-size:100% 100%;
}
}
}

关于html - CSS 媒体和查询不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22815379/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com