Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 媒体查询问题-防止覆盖CSS规则_Html_Css_Media Queries - Fatal编程技术网

Html 媒体查询问题-防止覆盖CSS规则

Html 媒体查询问题-防止覆盖CSS规则,html,css,media-queries,Html,Css,Media Queries,最初我有我的基本CSS,然后我添加了一个640媒体查询 @media screen and (max-width:640px) {} @media screen and (max-width:840px) {} 我对所有东西都进行了编码,以适应移动设备,一切都很好。刚才我添加了另一个媒体查询 @media screen and (max-width:640px) {} @media screen and (max-width:840px) {} 现在,我的网站的移动部分正在接受第二个媒体

最初我有我的基本CSS,然后我添加了一个640媒体查询

@media screen and (max-width:640px) {}
@media screen and (max-width:840px) {}
我对所有东西都进行了编码,以适应移动设备,一切都很好。刚才我添加了另一个媒体查询

@media screen and (max-width:640px) {}
@media screen and (max-width:840px) {}

现在,我的网站的移动部分正在接受第二个媒体查询的代码?我不知道哪部手机的最大宽度有这么大。为什么840媒体查询会干扰我的移动媒体查询?

为了防止覆盖CSS,请使用以下代码仅为640px和840px之间的宽度指定规则:

或者,您可以对代码重新排序:

@media screen and (max-width:840px) {} 

@media screen and (max-width:640px) {} /* This will override the above CSS rules */

查看此页面:了解一些好的做法。

为了防止CSS重写,请使用以下代码仅为640px和840px之间的宽度指定规则:

或者,您可以对代码重新排序:

@media screen and (max-width:840px) {} 

@media screen and (max-width:640px) {} /* This will override the above CSS rules */

查看此页面:学习一些好的做法。

你可以使用manoj所说的

这是来自的指南-希望对您有所帮助

/* Smartphones (portrait and landscape) ----------- */
    @media only screen 
    and (min-device-width : 320px) 
    and (max-device-width : 480px) {
    /* Styles */
    }

    /* Smartphones (landscape) ----------- */
    @media only screen 
    and (min-width : 321px) {
    /* Styles */
    }

    /* Smartphones (portrait) ----------- */
    @media only screen 
    and (max-width : 320px) {
    /* Styles */
    }

    /* iPads (portrait and landscape) ----------- */
    @media only screen 
    and (min-device-width : 768px) 
    and (max-device-width : 1024px) {
    /* Styles */
    }

    /* iPads (landscape) ----------- */
    @media only screen 
    and (min-device-width : 768px) 
    and (max-device-width : 1024px) 
    and (orientation : landscape) {
    /* Styles */
    }

    /* iPads (portrait) ----------- */
    @media only screen 
    and (min-device-width : 768px) 
    and (max-device-width : 1024px) 
    and (orientation : portrait) {
    /* Styles */
    }

    /* Desktops and laptops ----------- */
    @media only screen 
    and (min-width : 1224px) {
    /* Styles */
    }

    /* Large screens ----------- */
    @media only screen 
    and (min-width : 1824px) {
    /* Styles */
    }

    /* iPhone 4 ----------- */
    @media
    only screen and (-webkit-min-device-pixel-ratio : 1.5),
    only screen and (min-device-pixel-ratio : 1.5) {
    /* Styles */
    }

你可以用manoj说的话

这是来自的指南-希望对您有所帮助

/* Smartphones (portrait and landscape) ----------- */
    @media only screen 
    and (min-device-width : 320px) 
    and (max-device-width : 480px) {
    /* Styles */
    }

    /* Smartphones (landscape) ----------- */
    @media only screen 
    and (min-width : 321px) {
    /* Styles */
    }

    /* Smartphones (portrait) ----------- */
    @media only screen 
    and (max-width : 320px) {
    /* Styles */
    }

    /* iPads (portrait and landscape) ----------- */
    @media only screen 
    and (min-device-width : 768px) 
    and (max-device-width : 1024px) {
    /* Styles */
    }

    /* iPads (landscape) ----------- */
    @media only screen 
    and (min-device-width : 768px) 
    and (max-device-width : 1024px) 
    and (orientation : landscape) {
    /* Styles */
    }

    /* iPads (portrait) ----------- */
    @media only screen 
    and (min-device-width : 768px) 
    and (max-device-width : 1024px) 
    and (orientation : portrait) {
    /* Styles */
    }

    /* Desktops and laptops ----------- */
    @media only screen 
    and (min-width : 1224px) {
    /* Styles */
    }

    /* Large screens ----------- */
    @media only screen 
    and (min-width : 1824px) {
    /* Styles */
    }

    /* iPhone 4 ----------- */
    @media
    only screen and (-webkit-min-device-pixel-ratio : 1.5),
    only screen and (min-device-pixel-ratio : 1.5) {
    /* Styles */
    }

媒体查询在.css文件中的位置顺序起着重要作用,它们在.css文件中的优先级顺序是从上到下的升序,您只需按如下方式更改此顺序:

把这个@media screen和max width:840px{}媒体查询放在这个@media screen和max width:640px{}上面,它会解决这个问题

或者,您可以使用以下CSS:

@media screen and (min-width: 640px) and (max-width:840px) { 
  /* your code here */
}

媒体查询在.css文件中的位置顺序起着重要作用,它们在.css文件中的优先级顺序是从上到下的升序,您只需按如下方式更改此顺序:

把这个@media screen和max width:840px{}媒体查询放在这个@media screen和max width:640px{}上面,它会解决这个问题

或者,您可以使用以下CSS:

@media screen and (min-width: 640px) and (max-width:840px) { 
  /* your code here */
}

把第二条规则放在第一位。