检测屏幕分辨率来加载替代 CSS 是个好主意吗?
我与一位平面设计师合作,他一直希望制作大于我推荐的 960 像素的网站。我可以使用液体布局做一定量的工作,但我真的很喜欢能够加载不同的 CSS 以实现更大的分辨率。我用谷歌搜索并找到了下面的链接,但我担心我没有听到更多关于此的信息。这是一个可靠的方法吗?我很担心,因为我以为会有更多的人想要这样做。
Im working with a graphic designer who constantly wants to make websites larger than the 960 pixels i recommend. I can do a certain amount with liquid layouts but id really love to be able to load different CSS for larger resolutions. I googled it and found the link below, but im worried that I havnt heard more about this. Is this is a reliable method? Im concerned as I would have thought that more people would want to do this.
http://www.ilovecolors.com.ar/detect-screen-size-css-style/
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简单回答你的问题:没有。
即使是,构建多个 CSS 文件等似乎效率很低。有比依赖分辨率更好的方法。
一个冗长的答案:
当 960 变成“哦,那是 2010 年了……”您的网站有多少会显得过时?同时,并不是每个浏览互联网的人都拥有 30 英寸影院显示器或双显示器设置。我尝试进行设计以最好地适应我的流量。
尽管检测浏览器可能会很好窗口宽度和/或屏幕宽度(显示器分辨率),我认为大多数意见是这样的:了解您的目标受众并为其设计/构建。
构建 960 网格和 CSS,然后构建1024 网格和 CSS = 效率低下,而且不是很“面向未来”。
如果您观察网站流量,发现 90% 的访问者使用 1 或 2(或 3)种分辨率,请构建效果良好的流畅布局。对于这些受众来说,
流体布局可能是针对当前市场上不断扩展的设备、分辨率、视口尺寸、屏幕定义(低、中、高)的最佳通用解决方案,更不用说 18 个月后了
@media 屏幕和(最大宽度:960px){
h1,h2 { 颜色:#990000;字体大小:1.4em; }
}
@media 屏幕和(最大宽度:1280px){
h1,h2 { 颜色:#336699;字体大小:1.8em; }
}
最小和最大宽度
添加到您的CSS(或类似的逻辑)还可以帮助满足更广泛的分辨率/浏览器尺寸,并为您的设计提供更长的保质期。并且不依赖 document.window.width() 函数。让您的钱得到最大的回报。流畅的设计、@media 查询、JavaScript 有助于弥补一些差距。您最终将获得更少的代码、更“面向未来”的设计以及更高比例的满意访问者。
To simply answer your question: No.
Even if it was, it seems inefficient to build multiple CSS files, etc. There are better methods than relying on resolution.
A longer-winded answer:
When 960 becomes "oh, that's so 2010..." how many of your sites will look dated? At the same time, not everyone that browses the internet has a 30" Cinema display either, or a dual monitor setup. I try to design to best accommodate MY traffic.
Although it may be nice to detect browser window widths, and/or screen widths (monitor resolution), I think the majority opinion is this: Know your intended audience and design/build for it.
Building a 960 grid and a CSS, then building a 1024 grid and a CSS = Inefficiency, and not very "future proof".
If you're watching your site traffic and see that 90% of your visitors are using 1 or 2 (or 3) resolutions, build a fluid layout that works well for that audience.
Fluid layouts are probably the best universal solution to the ever-expanding array of devices, resolutions, viewport sizes, screen definitions (low, medium, high) on the market now -- let alone 18 months from now.
Checkout @media queries to add to a fluid layout/design. Modify one CSS file (not 3). http://www.w3.org/TR/css3-mediaqueries/
@media screen and (max-width:960px) {
h1, h2 { color:#990000; font-size:1.4em; }
}
@media screen and (max-width:1280px) {
h1, h2 { color:#336699; font-size:1.8em; }
}
Add
min- and max- widths
to your CSS (or a similar logic) can also help satisfy a wider range of resolutions/browser sizes, as well as give your design a longer shelf life. And doesn't rely on a document.window.width() function.Get the most bang for your buck. Fluid designs, @media queries, javascript to help bridge some gaps. You'll end up with less code, a more "future proof" design, and a larger percentage of satisfied visitors.