JaP*_*k14 48 html css html5 css3 media-queries
我目前正在尝试设计一个兼容多种屏幕尺寸的布局.我正在设计的屏幕尺寸如下:
屏幕尺寸:
我遇到的问题是创建css3媒体查询,以便当窗口的宽度达到其中一个宽度时,我的布局会发生变化.下面是我正在使用的媒体查询的示例,但它不适合我,所以我想知道是否有人可以帮我修复它.
<link rel="stylesheet" type="text/css" media="screen and (max-width: 700px)" href="css/devices/screen/layout-modify1.css">
<link rel="stylesheet" type="text/css" media="screen and (min-width: 701px) and (max-width: 900px)" href="css/devices/screen/layout-modify2.css">
<link rel="stylesheet" type="text/css" media="screen and (max-width: 901px)" href="css/devices/screen/layout-modify3.css">
Run Code Online (Sandbox Code Playgroud)
我尝试使用一组新的媒体查询,但它们仍然不适合我.请有人帮忙解释一下我的错误.你们当中有几个人已经尝试过解释,但我没有得到它.新媒体查询显示如下:
<link rel="stylesheet" type="text/css" media="screen and (max-width: 640px)" href="css/devices/screen/layout-modify1.css">
<link rel="stylesheet" type="text/css" media="screen and (max-width: 800px)" href="css/devices/screen/layout-modify2.css">
<link rel="stylesheet" type="text/css" media="screen and (max-width: 1024px)" href="css/devices/screen/layout-modify3.css">
<link rel="stylesheet" type="text/css" media="screen and (max-width: 1280px)" href="css/devices/screen/layout-modify4.css">
Run Code Online (Sandbox Code Playgroud)
Oli*_*pin 84
将它全部放在一个文档中并使用它:
/* 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 - 5s ----------- */
@media
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
/* Styles */
}
/* iPhone 6 ----------- */
@media
only screen and (max-device-width: 667px)
only screen and (-webkit-device-pixel-ratio: 2) {
/* Styles */
}
/* iPhone 6+ ----------- */
@media
only screen and (min-device-width : 414px)
only screen and (-webkit-device-pixel-ratio: 3) {
/*** You've spent way too much on a phone ***/
}
/* Samsung Galaxy S7 Edge ----------- */
@media only screen
and (-webkit-min-device-pixel-ratio: 3),
and (min-resolution: 192dpi)and (max-width:640px) {
/* Styles */
}
Run Code Online (Sandbox Code Playgroud)
资料来源:http://css-tricks.com/snippets/css/media-queries-for-standard-devices/
在这一点上,我肯定会考虑使用em
值而不是像素.有关更多信息,请查看以下帖子:https://zellwk.com/blog/media-query-units/.
cim*_*non 44
除非你有更多的样式表,否则你已经弄乱了你的断点:
#1 (max-width: 700px)
#2 (min-width: 701px) and (max-width: 900px)
#3 (max-width: 901px)
Run Code Online (Sandbox Code Playgroud)
第三个媒体查询可能是min-width: 901px
.现在,它与#1和#2重叠,只在屏幕正好为901像素宽时自动控制页面布局.
编辑更新的问题:
(max-width: 640px)
(max-width: 800px)
(max-width: 1024px)
(max-width: 1280px)
Run Code Online (Sandbox Code Playgroud)
媒体查询与catch或if/else语句不同.如果任何条件匹配,则它将应用其匹配的每个媒体查询中的所有样式.如果您只min-width
为所有媒体查询指定了一个,则可能会匹配部分或全部媒体查询.在您的情况下,640px宽的设备匹配所有4个媒体查询,因此所有样式表都被加载.您最有可能寻找的是:
(max-width: 640px)
(min-width: 641px) and (max-width: 800px)
(min-width: 801px) and (max-width: 1024px)
(min-width: 1025px)
Run Code Online (Sandbox Code Playgroud)
现在没有重叠.仅当设备的宽度介于指定的宽度之间时,才会应用样式.
归档时间: |
|
查看次数: |
171076 次 |
最近记录: |