css - @media only 屏幕不工作

标签 css mobile media

我必须针对移动设备优化网站。试图通过@media only screen 来做到这一点,但它对我不起作用。也许有人知道如何将它正确地放入代码中?

body {
  background-color: black;
  background-image: url(../images/background.jpg);
  background-size: 100vw 100vh;
}
header {
  box-sizing: border-box;
  top: 0;
  right: 0;
  left: 0;
  position: absolute;
  width: 100vw;
  height: 15vh;
  border-top: 0.5vmin ridge gray;
  border-right: 0.5vmin ridge gray;
  border-left: 0.5vmin ridge gray;
}
header img {
  max-height: 14vmin;
  display: block;
  margin-left: auto;
  margin-right: auto;
  vertical-align: center;
}
etc.
<!DOCTYPE html>

<head>
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <link type="text/css" rel="stylesheet" href="css/homepage.css">
  <meta http-equiv="Content-type" content="text/html;charset=utf-8" />
  <title>Airinn hotel // Home</title>
</head>

<body>

  <header>
    <img src='images/logo.png' />etc.

最佳答案

这是应该如何完成的(移动优先):

.test {
    width: 200px;
}

@media screen and (min-width: 1024px) {
    .test {    
        width: 1000px;
    }
}

演示:http://jsfiddle.net/yzt9zjno/

此外,this tutorial should help .

关于css - @media only 屏幕不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33416210/

相关文章:

javascript - 在javascript中循环动态对象

android - 使用 javafx 在 android 中创建推送通知

jquery - 使用 jquery mobile 动态设置单选按钮处于事件状态

image - 为什么 magento 中的 wysiwyg 插件让我断开链接?

android - 如何列出要存储在服务器上的歌曲详细信息

css - 传递一个空的 LESS 参数以使用默认值?

css - 顺风 CSS : hide one div and replace it with another

android - 为什么android popupwindow showAsDropDown offsetx 无效?

javascript - 如何使用 Blob URL、MediaSource 或其他方法播放串联的媒体片段 Blob?

javascript - grunt-watch 跳过了我的一些任务,为什么?