我的代码中的某些媒体查询是不起作用的,有关如何解决这个问题的任何建议?例如,320px和360px媒体查询不起作用
320px媒体查询不起作用。 360PX媒体查询不起作用。 但是其他媒体查询正在起作用。 关于如何解决此问题的任何建议?
body {
font-family: "Trebuchet Ms", Cambria, "Times New Roman", sans-serif;
}
.topnav {
background-color: #333;
width: 100%;
position: fixed;
top: 0px;
margin-left: -9px;
}
.topnav a:hover {
background-color: darkgreen;
color: white;
text-decoration: underline;
}
nav {
margin: 33px;
margin-top: 32px;
}
img#logo {
width: 101px;
float: left;
margin-top: -15px;
margin-left: -20px;
}
a.active {
background-color: #04aa6d;
color: white;
text-decoration: none;
}
nav a {
color: #f2f2f2;
text-align: center;
padding: 14px 14px;
text-decoration: none;
font-size: 17px;
}
a.icon {
display: none;
}
#right {
float: right;
margin-top: -16px;
}
.pastor {
width: 1000px;
margin-left: 275px;
margin-top: -231px;
}
hr {
border-top: 3px double #0193de;
margin: 50px 0px 50px;
}
ul {
list-style-type: none;
}
#li {
float: right;
margin-top: -49px;
margin-right: 15px;
}
li#li {
padding: 10px 20px;
}
li#li a {
color: whitesmoke;
background-color: #04AA6D;
}
li#li a:hover {
color: black;
}
#figure {
display: flex;
justify-content: center;
}
figure figcaption {
text-align: center;
}
#events {
background-color: #0193de;
text-align: center;
}
.figure {
text-align: center;
display: inline-block;
margin-left: auto;
width: 350px;
height: 424px;
}
.figure img {
width: 350px;
height: 424px;
}
figure figcaption {
color: white;
}
#footer {
background-color: #333;
text-align: center;
color: white;
}
#footer a{
color: green;
}
#footer a:link {
color: white;
}
#footer a:visited {
color: white;
}
#footer a:hover {
background-color: darkgreen;
text-decoration: underline;
}
#marg {
margin-top: 25px;
display: block;
}
/*This is the gallery section*/
#figs.figures {
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.figures figcaption {
color: black;
}
#pictures {
background-color: #12954b;
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.pictures img {
height: 700px;
width: 437px;
}
#pictures figcaption {
color: white;
}
/*This is the donate section*/
.dropbtn {
background-color: #04AA6D;
color: white;
padding: 16px;
font-size: 16px;
border: none;
width: 100%;
}
.dropdown {
position: relative;
display: inline-block;
width: 100%;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
width: 100%;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: center;
}
.dropdown-content a:hover {background-color: #ddd;}
.dropdown:hover .dropdown-content {display: block;}
.dropdown:hover .dropbtn {background-color: #3e8e41;}
abbr {
text-decoration: underline;
}
/*This is the contact section*/
.margin {
margin-top: 100px;
text-align: center;
}
.margin2 {
text-align: center;
}
input:focus {
border: 3px solid #0193de;
}
input {
width: 51%;
padding: 12px 20px;
margin: 8px 1px;
box-sizing: border-box;
border-right-color: #0193de;
}
textarea {
width: 51%;
height: 100px;
padding: 12px 20px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
resize: none;
border-right-color: #0193de;
}
.submit {
background-color: #04AA6D;
border: none;
color: white;
padding: 16px 32px;
text-decoration: none;
margin: 4px;
cursor: pointer;
width: 50.8%;
}
.reset {
background-color: red;
border: none;
color: white;
padding: 16px 32px;
text-decoration: none;
margin: 4px;
cursor: pointer;
width: 50.8%;
}
@media screen and (min-width: 320px) {
body {
font-family: "Trebuchet Ms", Cambria, "Times New Roman", sans-serif;
}
.topnav {
overflow: hidden;
background-color: #333;
position: fixed;
width: 100%;
top: 0px;
margin-left: -9px;
}
.topnav a{
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.topnav a:hover {
background-color: #04AA6D;
color: black;
text-decoration: underline;
}
.topnav a.active {
background-color: darkgreen;
color: white;
}
.topnav a:visited {
color: dodgerblue;
}
.topnav .icon {
display: none;
}
img#logo {
width: 70px;
}
nav {
margin: 12px;
margin-top: 0px;
}
#right {
display: flex;
justify-content: center;
margin-top: 10px;
margin-right: 79px;
}
#p {
display: inline-block;
}
.pastor {
width: 300px;
margin-top: -26px;
margin-left: 23px;
}
hr {
width: 100%;
border-top: 3px double #0193de;
margin: 50px 0px 50px;
}
ul {
list-style-type: none;
}
ul li {
display: inline-block;
}
#il {
margin-left: -34px;
margin-top: -2px;
}
#li {
float: right;
margin-top: 20px;
margin-right: 2px;
}
#li a {
text-align: center;
color: whitesmoke;
background-color: #04AA6D;
}
li#li {
padding: 0px;
}
#figure {
display: flex;
flex-direction: column;
}
.iframe {
margin-left: 0px;
width: 250px;
}
#figure figcaption {
color: black;
}
figcaption {
text-align: center;
}
#events {
background-color: #0092dc;
text-align: center;
}
.figure {
margin-left: 25px;
width: 250px;
}
.figure img {
width: 350px;
margin-left: 0px;
}
.figure figcaption {
color: white;
text-align: center;
}
#footer {
background-color: #333;
text-align: center;
color: white;
}
#marg {
display: block;
margin: 20px 0px;
}
#downnavbar a:link {
color: white;
}
#downnavbar a:visited {
color: dodgerblue;
}
#downnavbar a:hover {
text-decoration: underline;
}
#downnavbar a {
text-decoration: none;
}
#downnavbar a.active {
background-color: transparent;
}
#downnavbar a:hover {
background-color: transparent;
}
#marg .fa-brands{
color: #269f5b;
}
#footer address a {
color: green;
}
address {
margin-top: 10px;
}
@media screen and (min-width: 320px) {
.topnav a:not(:first-child) {
display: none;
}
.topnav a.icon {
float: right;
display: block;
}
}
@media screen and (min-width: 320px) {
.topnav.responsive {
position: fixed;
width: 361px;
}
.topnav.responsive .icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a{
float: none;
display: block;
margin-top: 21px;
}
}
}
@media screen and (max-width: 360px)
@media screen and (max-width: 412px)
@media screen and (min-width: 414px)
@media screen and (min-width: 428px)
@media screen and (min-width: 768px)
@media screen and (min-width: 800px)
@media screen and (min-width: 820px)
@media screen and (min-width: 834px)
@media screen and (min-width: 884px)
320px媒体查询不起作用。 360PX媒体查询不起作用。但是其他媒体查询正在起作用。关于如何解决这个问题的任何建议?
The 320px media query is not working.
The 360px media query is not working.
But the other media queries are working.
Any suggestions on how to resolve this?
body {
font-family: "Trebuchet Ms", Cambria, "Times New Roman", sans-serif;
}
.topnav {
background-color: #333;
width: 100%;
position: fixed;
top: 0px;
margin-left: -9px;
}
.topnav a:hover {
background-color: darkgreen;
color: white;
text-decoration: underline;
}
nav {
margin: 33px;
margin-top: 32px;
}
img#logo {
width: 101px;
float: left;
margin-top: -15px;
margin-left: -20px;
}
a.active {
background-color: #04aa6d;
color: white;
text-decoration: none;
}
nav a {
color: #f2f2f2;
text-align: center;
padding: 14px 14px;
text-decoration: none;
font-size: 17px;
}
a.icon {
display: none;
}
#right {
float: right;
margin-top: -16px;
}
.pastor {
width: 1000px;
margin-left: 275px;
margin-top: -231px;
}
hr {
border-top: 3px double #0193de;
margin: 50px 0px 50px;
}
ul {
list-style-type: none;
}
#li {
float: right;
margin-top: -49px;
margin-right: 15px;
}
li#li {
padding: 10px 20px;
}
li#li a {
color: whitesmoke;
background-color: #04AA6D;
}
li#li a:hover {
color: black;
}
#figure {
display: flex;
justify-content: center;
}
figure figcaption {
text-align: center;
}
#events {
background-color: #0193de;
text-align: center;
}
.figure {
text-align: center;
display: inline-block;
margin-left: auto;
width: 350px;
height: 424px;
}
.figure img {
width: 350px;
height: 424px;
}
figure figcaption {
color: white;
}
#footer {
background-color: #333;
text-align: center;
color: white;
}
#footer a{
color: green;
}
#footer a:link {
color: white;
}
#footer a:visited {
color: white;
}
#footer a:hover {
background-color: darkgreen;
text-decoration: underline;
}
#marg {
margin-top: 25px;
display: block;
}
/*This is the gallery section*/
#figs.figures {
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.figures figcaption {
color: black;
}
#pictures {
background-color: #12954b;
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.pictures img {
height: 700px;
width: 437px;
}
#pictures figcaption {
color: white;
}
/*This is the donate section*/
.dropbtn {
background-color: #04AA6D;
color: white;
padding: 16px;
font-size: 16px;
border: none;
width: 100%;
}
.dropdown {
position: relative;
display: inline-block;
width: 100%;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
width: 100%;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: center;
}
.dropdown-content a:hover {background-color: #ddd;}
.dropdown:hover .dropdown-content {display: block;}
.dropdown:hover .dropbtn {background-color: #3e8e41;}
abbr {
text-decoration: underline;
}
/*This is the contact section*/
.margin {
margin-top: 100px;
text-align: center;
}
.margin2 {
text-align: center;
}
input:focus {
border: 3px solid #0193de;
}
input {
width: 51%;
padding: 12px 20px;
margin: 8px 1px;
box-sizing: border-box;
border-right-color: #0193de;
}
textarea {
width: 51%;
height: 100px;
padding: 12px 20px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
resize: none;
border-right-color: #0193de;
}
.submit {
background-color: #04AA6D;
border: none;
color: white;
padding: 16px 32px;
text-decoration: none;
margin: 4px;
cursor: pointer;
width: 50.8%;
}
.reset {
background-color: red;
border: none;
color: white;
padding: 16px 32px;
text-decoration: none;
margin: 4px;
cursor: pointer;
width: 50.8%;
}
@media screen and (min-width: 320px) {
body {
font-family: "Trebuchet Ms", Cambria, "Times New Roman", sans-serif;
}
.topnav {
overflow: hidden;
background-color: #333;
position: fixed;
width: 100%;
top: 0px;
margin-left: -9px;
}
.topnav a{
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.topnav a:hover {
background-color: #04AA6D;
color: black;
text-decoration: underline;
}
.topnav a.active {
background-color: darkgreen;
color: white;
}
.topnav a:visited {
color: dodgerblue;
}
.topnav .icon {
display: none;
}
img#logo {
width: 70px;
}
nav {
margin: 12px;
margin-top: 0px;
}
#right {
display: flex;
justify-content: center;
margin-top: 10px;
margin-right: 79px;
}
#p {
display: inline-block;
}
.pastor {
width: 300px;
margin-top: -26px;
margin-left: 23px;
}
hr {
width: 100%;
border-top: 3px double #0193de;
margin: 50px 0px 50px;
}
ul {
list-style-type: none;
}
ul li {
display: inline-block;
}
#il {
margin-left: -34px;
margin-top: -2px;
}
#li {
float: right;
margin-top: 20px;
margin-right: 2px;
}
#li a {
text-align: center;
color: whitesmoke;
background-color: #04AA6D;
}
li#li {
padding: 0px;
}
#figure {
display: flex;
flex-direction: column;
}
.iframe {
margin-left: 0px;
width: 250px;
}
#figure figcaption {
color: black;
}
figcaption {
text-align: center;
}
#events {
background-color: #0092dc;
text-align: center;
}
.figure {
margin-left: 25px;
width: 250px;
}
.figure img {
width: 350px;
margin-left: 0px;
}
.figure figcaption {
color: white;
text-align: center;
}
#footer {
background-color: #333;
text-align: center;
color: white;
}
#marg {
display: block;
margin: 20px 0px;
}
#downnavbar a:link {
color: white;
}
#downnavbar a:visited {
color: dodgerblue;
}
#downnavbar a:hover {
text-decoration: underline;
}
#downnavbar a {
text-decoration: none;
}
#downnavbar a.active {
background-color: transparent;
}
#downnavbar a:hover {
background-color: transparent;
}
#marg .fa-brands{
color: #269f5b;
}
#footer address a {
color: green;
}
address {
margin-top: 10px;
}
@media screen and (min-width: 320px) {
.topnav a:not(:first-child) {
display: none;
}
.topnav a.icon {
float: right;
display: block;
}
}
@media screen and (min-width: 320px) {
.topnav.responsive {
position: fixed;
width: 361px;
}
.topnav.responsive .icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a{
float: none;
display: block;
margin-top: 21px;
}
}
}
@media screen and (max-width: 360px)
@media screen and (max-width: 412px)
@media screen and (min-width: 414px)
@media screen and (min-width: 428px)
@media screen and (min-width: 768px)
@media screen and (min-width: 800px)
@media screen and (min-width: 820px)
@media screen and (min-width: 834px)
@media screen and (min-width: 884px)
The 320px media query is not working. The 360px media query is not working. But the other media queries are working. Any suggestions on how to resolve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您在问题中的顺序中以它们为单位,则很明显:
最大宽度:412px
Will operwrite 320和360 max宽:例如最大宽度:412px
也适用于310px宽的屏幕。您需要重新安排订单以避免这种情况。If you have them in the order like in your question, it's clear: The
max-width: 412px
will overwrite the 320 and 360 max-width: For examplemax-width: 412px
also applies to a screen that's 310px wide. You need to rearrrange the order to avoid that.CSS从上到下读取 - 这意味着最后属性应用于您的选择器,只要有效,就可以优先。这意味着一个更“精确”
Media-Query
规则prop将不是优先于另一个,如果Media-Query
放置在下方其他和他们的两个规则都是有效的。因此,您应始终使用以下方式制作媒体Query
-rules以这种方式,只要适用规则,第一个
媒体 - Query-Query
就将始终优先。当第二个Media-Query
的规则应用时,这将优先考虑。尝试将此代码片段的屏幕大小拖动到整页中,您将看到此代码构造的工作原理。CSS is read from top to bottom - this means that the last property applied to your selector will take priority, as long as its valid. This means that a more "precise"
media-query
rule prop will not take priority over another, if themedia-query
is placed below the other and both of their rules are valid. Because of this, you should always makemedia-query
-rules with:This way, the first
media-query
will always take priority as long as its rules apply. When the secondmedia-query
's rule apply, that will take priority instead and so on. Try dragging the screen size of this code snippet in full page and you'll see how this code structuring works.让我们逐一浏览媒体查询,看看我们最终的位置。
这是查询(目前什么都没关系)。 (只要从360px媒体查询之前就删除了虚假的卷发右支撑)。
好的,假设我坐在一个非常狭窄的视口上 - 假设250px。
是的,我通过了此测试,所以这里的任何内容都将被应用
哦,我也通过了此测试,因此在这里进行的任何内容都将被应用(并从上一个媒体查询中覆盖一些东西)
lo!我已经通过了此测试,所以这里设置的任何设置都将覆盖以前的设置
,我失败了,所以这里什么也没有适用
,
我也未能通过此设置。
失败
失败
失败
失败
,因此到最后,我拥有的样式是412px宽度的任何东西。
如果我的宽度为360px或更小(除了第一个测试失败之外),则情况也是如此。
因此,对于最大测试,您将不得不将它们相反。这是一个320px或更少的视口的缩短版本:
lo!我已经通过了此测试,所以这里设置的任何设置都将覆盖以前的设置
哦,我也通过了此测试,所以在这里进行的任何内容都将应用(并从上一个媒体查询中覆盖一些东西)
是的,我通过了此测试,所以无论如何这里将应用(并覆盖上一个类似的设置),
因此,对于320px来说,这应该是可以的360px。
现在,分钟路程正确吗?他们都不会被低于414px的视口满足,因此320px和360px不会受到影响。
假设我在宽度440px的视口上。
通过了,以便将设置应用程序
通过,以便应用设置填充,覆盖
我已经失败的任何相同设置的设置。
失败的
失败
失败
失败
,这似乎还可以。
请记住,CSS被命名为CASCADE是有原因的,最后一个适用的设置将是“粘贴”的设置。
Let's just go through the media queries one by one and see where we end up.
Here are the queries (doesn't matter what's in them for now). (As long as that spurious curly right brace has been removed from just before the 360px media query).
OK suppose I'm sitting on a very narrow viewport - let's say 250px.
Yes, I pass this test so whatever is in here will get applied
Oh, I have passed this test too so whatever is in here will get applied (and override some stuff from the previous media query)
Lo! I have passed this test so anything set here will override previous settings
Ah, I've failed this one so nothing in here applies
And I've failed this one too
And I've failed this one.
Failed
Failed
Failed
Failed
So by the end the styles that I have are those for anything up 412px width.
And the same will be true if my width is 360px or less (apart from failing the first test).
So for max tests you are going to have to put them the other way round. Here's a shortened version for a 320px or less viewport:
Lo! I have passed this test so anything set here will override previous settings
Oh, I have passed this test too so whatever is in here will get applied (and override some stuff from the previous media query)
Yes, I pass this test so whatever is in here will get applied (and override any similar settings from the previous)
So, that should be fine for 320px Try it yourself for 360px.
Now, are the mins the right way round? None of them will be satisfied by a viewport of less than 414px so the 320px and the 360px won't be affected.
Let's suppose I'm on a viewport with width 440px.
Passed so the settings will be applied
Passed so the settings fill be applied, overriding any of the same already set
I've failed this one.
Failed
Failed
Failed
Failed
So that would seem to be OK.
Remember that CSS is named cascade for a reason, the last applicable setting will be the one that 'sticks'.