简体   繁体   English

显示警告屏幕分辨率

[英]Show warnings screen resolution

I have a webpage which is designed to view using a minimum resolution of 800px width. 我有一个网页,旨在使用最小800px宽度的分辨率进行查看。 I would like to add a warning to the users browsing with a resolution < 800px saying something like 我想向浏览分辨率小于800px的用户添加警告,例如

This webpage was designed to be viewed using a resolution of.... 设计该网页时使用的分辨率为...。

How can I do that? 我怎样才能做到这一点? Is that not possible to do with CSS Media-Queries? CSS Media Queries不可能吗?

A different solution, without placing that text as an actual content into the document, is to use a pseudoelement. 在不将文本作为实际内容放入文档的情况下,另一种解决方案是使用伪元素。

eg http://codepen.io/anon/pen/ejlsp 例如http://codepen.io/anon/pen/ejlsp

CSS code CSS代码

@media all and (max-width: 799px) {

    body:before {
      content: "this webpage is best viewed...";
      display: block;
      position: fixed;
      padding: 20px;
      background: #fff;
      border: 2px #ccc solid;
      outline: 400px solid rgba(20,20,20, .7);
      left: 50%;
      top: 50%;
      -webkit-transform: translate(-50%, -50%);
      -moz-transform: translate(-50%, -50%);
      transform: translate(-50%, -50%);
    }

}

Use CSS media queries for that: 为此使用CSS 媒体查询

.resolution-warning {
    display: none;
}
@media screen and (max-width: 800px) {
    .resolution-warning {
        display: block;
    }
}

And put in HTML somewhere: 并在某处放置HTML:

<div class="resolution-warning">You screen resolution is too small.</div>

Here is a demo 1 and 2 , try resizing a browser. 这是演示12 ,请尝试调整浏览器的大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM