在本文中,我们将详细介绍css–多少媒体查询?的各个方面,并为您提供关于css媒体查询@media的相关解答,同时,我们也将为您带来关于css---响应式---媒体查询、css–使用Chrome中的r
在本文中,我们将详细介绍css – 多少媒体查询?的各个方面,并为您提供关于css媒体查询 @media的相关解答,同时,我们也将为您带来关于css --- 响应式 --- 媒体查询、css – 使用Chrome中的rem单元进行媒体查询?、css – 全屏媒体查询、css – 哪些是在创建移动响应设计中使用的最重要的媒体查询?的有用知识。
本文目录一览:- css – 多少媒体查询?(css媒体查询 @media)
- css --- 响应式 --- 媒体查询
- css – 使用Chrome中的rem单元进行媒体查询?
- css – 全屏媒体查询
- css – 哪些是在创建移动响应设计中使用的最重要的媒体查询?
css – 多少媒体查询?(css媒体查询 @media)
您建议使用多少媒体查询?
我做了4个设计:
横向模式960(ipad和更像桌面)
768用于纵向模式(ipad)
340用于肖像模式(iphone)
以及所有960以上
现在我的问题:
1)首先我甚至不知道为什么我使用960而不是1024.我刚才读了一些东西,因为滚动条你要将宽度减小到960.这对于平板电脑和智能手机呢?
2)我选择了这些宽度因为我认为,如果有人使用横向模式,它将切换到“ipad-media-query”并返回“iphone-media-query”.但这只是我的理论.我是媒体查询的新手.这就是我问的原因.感谢任何帮助甚至建议的CSS代码示例,以便为网站提供最佳的媒体查询量!?
3)我只想覆盖大多数平板电脑,智能手机,台式机等受最佳媒体查询大小的影响.我非常感谢您的“最佳解决方案”!
这取决于您和您的设计,有多少媒体查询适合使用以及如何实现它们.
作为指南,我建议看一下Twitter Bootstrap如何实现他们的媒体查询.他们已经对它进行了大量研究以得出它们的数字,这将是一个很好的起点.
http://twitter.github.com/bootstrap/scaffolding.html#responsive
css --- 响应式 --- 媒体查询
响应式
我自己的理解
就是限制住像素范围
然后分别写入一套css
HTML就写两套或者更多 但只显示一套
其实吧
现在!!!
很少有网站是用响应式写的
主流的一些像是 某宝 某东
都是用js判断
也就是做一个pc端 一个移动端
看用户用的是电脑还是手机
根据判断结果 更改页面地址
那为什么还要学呢。。。
应付面试啊!
反正又不难
学就学喽
方法1 -- css写法
// CSS
@media(max-width:320){ // 320像素以下执行里面的css 范围:0 ~ 320
body{ background:red }
}
@media(min-width:321) and ( max-width:375 ){ // css 范围:321 ~ 375
body{ background:blue }
}
@media(min-width:376){ // css 范围:376 ~ 正无穷
body{ background:purple }
}
方法2 -- link写法
用文件代替内容
<!-- HTML -->
<head>
<!-- 这个css 在该范围下才会生效 -->
<link rel=''stylesheel'' href=''style.css'' media=''(max-width:320px)''/>
</head>
应用
做响应式的时候:
先做手机 再做网站 --- Mobile first 【推荐】
先做网站 再做手机 --- Desktop first
用js判断一下是网站还是手机
并写入不同的地址
//js
function judge(){
if((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
//window.location.href="移动端url";
alert("mobile")
}
else {
// window.location.href="pc端url";
alert("pc")
}
}
judge();
meta 标签
作用:标签就是告诉浏览器, 不要在移动端显示的时候缩放
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1">
css – 使用Chrome中的rem单元进行媒体查询?
rem单元在Chrome中完美运行,似乎它们在媒体查询中不受支持.这可能吗?或者这个CSS有什么问题吗?
body { background-color: yellow; } @media only all and (max-width: 40rem) { body { background-color: red; } } @media only all and (min-width: 40rem) and (max-width: 60rem) { body {background-color: green;} } @media only all and (min-width: 60rem) { body { background-color: blue; } }
活在http://jsfiddle.net/jsQ2N/2/show/,em-only版本在http://jsfiddle.net/jsQ2N/3/show/.
解决方法
Relative units in media queries are based on the initial value,which means that units are never based on results of declarations. For example,in HTML,the ‘em’ unit is relative to the initial value of ‘font-size’.
(font-size的初始值为medium,通常等于浏览器用户首选项中的默认字体大小设置.)
由于除了相对单位的上述引用之外,媒体查询3没有为任何特定单元定义特殊规则,因此rem应该像em一样工作,处理font-size的初始值.如果它在Chrome中不起作用,则很可能是一个错误.
css – 全屏媒体查询
@media (device-width: 100vw) and (device-height: 100vh) { .content { padding: 0px !important; } }
在Firefox中完美运行但在Chrome中非常不可靠(在Windows 7 x64上都是最新版本).我可以尝试仅在不是全屏模式时应用我的覆盖,但需要反转查询.所以我的问题是:
> Chrome应该支持查询吗?
>我如何否定它(逻辑上没有)?
附:
我的视口声明如下:
<Meta name="viewport" content="width=device-width,initial-scale=1.0"/>
解决方法
body.is-fullscreen .content { padding...
例如:
document.addEventListener('fullscreenchange',function() { document.body.classList.toggle('is-fullscreen',document.fullscreenEnabled); });
此事件具有供应商前缀版本,因此请确保您使用的是所需的版本.
css – 哪些是在创建移动响应设计中使用的最重要的媒体查询?
/* 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 */ }
解决方法
/* Landscape phones and down */ @media (max-width: 480px) { ... } /* Landscape phone to portrait tablet */ @media (max-width: 767px) { ... } /* Portrait tablet to landscape and desktop */ @media (min-width: 768px) and (max-width: 979px) { ... } /* Large desktop */ @media (min-width: 1200px) { ... }
编辑:这个问题的原始答案是从Bootstrap版本2。Bootstrap以来更改了他们的媒体查询在版本3.注意,没有明确查询小于768px的设备。这种做法有时被称为移动优先。任何媒体查询以外的任何内容都会应用于所有设备。媒体查询块中的所有内容都会扩展并覆盖全局可用的内容以及所有较小设备的样式。认为它是响应式设计的渐进增强。
/* Extra small devices (phones,less than 768px) */ /* No media query since this is the default in Bootstrap */ /* Small devices (tablets,768px and up) */ @media (min-width: 768px) { ... } /* Medium devices (desktops,992px and up) */ @media (min-width: 992px) { ... } /* Large devices (large desktops,1200px and up) */ @media (min-width: 1200px) { ... }
在Bootstrap 3’s docs检查。
关于css – 多少媒体查询?和css媒体查询 @media的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于css --- 响应式 --- 媒体查询、css – 使用Chrome中的rem单元进行媒体查询?、css – 全屏媒体查询、css – 哪些是在创建移动响应设计中使用的最重要的媒体查询?的相关信息,请在本站寻找。
本文标签: