[英]Why is @media (max-device-width: 360px) affected by the @media (max-device-width: 1024px)?
Just curious why one of the "media size" is affected by the bigger "bigger media size"? 只是好奇为什么其中一个“媒体大小”受到更大“更大的媒体规模”的影响? I have more code but where thing else works but these two.
我有更多的代码,但其他东西工作,但这两个。
@media only screen and (max-device-width: 360px){ .contact_center_image{ position: relative; margin-left: 20%; bottom: 50px; } .image_size{ width: 400px; height: 300px; } } @media only screen and (max-device-width: 1024px){ .contact_center_image{ position: relative; margin-left: 23%; bottom: 50px; } .image_size{ width: 1000px; height: 700px; } }
<div class="contact_center_image"> <img src="https://images.pexels.com/photos/67636/rose-blue-flower-rose-blooms-67636.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" alt="Image" class="image_size"> </div>
CSS stands for "Cascading Style Sheets", meaning there is a vertical hierarchy. CSS代表“Cascading Style Sheets”,意思是有一个垂直层次结构。 Your lower code takes dominance when both rules apply, and in this case, a screen size less than 360px is also less than 1024px.
当两个规则都适用时,较低的代码占主导地位,在这种情况下,小于360px的屏幕尺寸也小于1024px。 If you want the 360px rule to have greater priority, you need to move it below the 1024px snippet.
如果您希望360px规则具有更高的优先级,则需要将其移至1024px片段下方。
@media only screen and (max-device-width: 1024px){
.contact_center_image{
position: relative;
margin-left: 23%;
bottom: 50px;
}
.image_size{
width: 1000px;
height: 700px;
}
}
@media only screen and (max-device-width: 360px){
.contact_center_image{
position: relative;
margin-left: 20%;
bottom: 50px;
}
.image_size{
width: 400px;
height: 300px;
}
}
@media only screen and (max-device-width: 1024px){
This conditional will return true
for any device width size up to and including the spacified value. 对于任何设备宽度大小(包括空间值),此条件将返回
true
。
So think of it as: 所以把它想象成:
@media only screen and (any-device-width-up-to-1024+1px){
Therefore 360px width is less than 1024px width so both your @media
rules will be applied. 因此360px宽度小于1024px宽度,因此将应用您的
@media
规则。
Try using min-device-width
rules instead, or a combination of both max-
and min-
for each @media
scope. 尝试使用
min-device-width
规则,或者对每个@media
范围使用max-
和min-
的组合。
While you can have multiple rules Cascading over each other (when both apply, the last one is applied last), this will cause a lot of style repetitions and you'd need to update multiple @media
statements to make a change propergate through these cascades. 虽然你可以有多个规则相互叠加 (当两者都适用时,最后一个应用最后),这将导致很多样式重复,你需要更新多个
@media
语句,通过这些级联进行更改。
Below, the first rule will apply to widths of 361 up to 1024 the second will apply to widths from 0 up to 360. 下面,第一条规则将适用于361到1024的宽度,第二条规则适用于从0到360的宽度。
@media only screen and (max-device-width: 1024px)
and (min-device-width: 361px) {
.contact_center_image{
position: relative;
margin-left: 23%;
bottom: 50px;
}
.image_size{
width: 1000px;
height: 700px;
}
}
@media only screen and (max-device-width: 360px){
.contact_center_image{
position: relative;
margin-left: 20%;
bottom: 50px;
}
.image_size{
width: 400px;
height: 300px;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.