【问题标题】:My website is responsive but it doesnt react at the right sizes我的网站是响应式的,但它没有以正确的尺寸做出反应
【发布时间】:2018-08-02 22:36:11
【问题描述】:

所以我创建了一个响应式网站,但该网站并没有在它应该改变的时候改变。 我在下面链接的网站显示,在我的 Iphone 6 Plus 上,它的格式应该正确,但是当我在我的 iphone 上查看网站时,它处于平板电脑视图模式。

您可以在这里查看我的意思http://quirktools.com/screenfly/#u=http%3A//maartennauta.com&w=1024&h=600&s=1

CSS 代码

html * {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  font-family: 'Montserrat', sans-serif;
}

body {
  margin-left: auto;
  margin-right: auto;
}

header {
  padding-bottom: 1px;
}

footer {
  text-align: center;
}

.logo {
  border-radius: 10px;
  height: 100px;
  margin-top: 15px;
  margin-bottom: 5px;
  width: 178px;
  margin-left: auto;
  margin-right: auto;
  display: block;
}

img {
  width: 100%;
  max-width: 100%;
  height: auto;
  vertical-align: middle;
}

.style-nav ul {
  list-style-type: none;
  text-align: center;
}

.style-nav ul li a {
  text-decoration: none;
  color: #2F322A;
  text-align: center;
  display: block;
  text-transform: uppercase;
  padding: 8px;
}

.style-nav ul li a:hover {
  color: black;
  text-shadow: 2px 2px 10px #000000;
  transition: 0.5s ease;
  -webkit-transition: 0.5s ease;
}

.hero {
  background-image: url(../Images/Background.jpg);
  background-size: cover;
  padding-top: 15px;
  padding-left: 20px;
  padding-right: 20px;
  padding-bottom: 50px;
  color: #FFFFFF;
  text-align: center;
}

.infobox-tan {
  background-color: #C29D73;
  color: #FFFFFF;
  padding: 30px 20px 60px;
  text-align: center;
}

.infobox-grey {
  background-color: #717A84;
  color: #FFFFFF;
  padding: 30px 20px 60px;
  text-align: center;
}

.row:before,
.row:after {
  content: "";
  display: table;
  color: #FFFFFF;
  text-align: center;
}

h1.small {
  font-size: 30px;
  text-transform: uppercase;
  font-weight: 200;
  margin-bottom: 60px;
}

h2 {
  font-size: 25px;
  text-transform: uppercase;
  font-weight: 100;
  margin-bottom: 20px;
  padding: 30px
}

h3 {
  font-size: 16px;
  text-transform: uppercase;
  font-weight: 200;
  margin-bottom: 60px;
}

h4 {
  font-size: 16px;
  font-weight: 200;
  margin-bottom: 35px;
}

p {
  font-size: 15px;
  text-transform: none;
  font-weight: 20;
  margin-bottom: 60px;
}

p.footertext {
  color: gray;
  font-size: 15px;
  text-transform: none;
  font-weight: 20;
  margin-top: 20px;
  margin-bottom: 20px;
}

.button {
  border-radius: 30px;
  border: 2px #FFFFFF solid;
  padding: 8px 15px;
  color: #FFFFFF;
  text-decoration: none;
  margin-bottom: 30px;
}

.button:hover {
  color: #242424;
  border: 2px #242424 solid;
  transition: 0.5s ease;
  -webkit-transition: 0.5s ease;
}

.row:after {
  clear: both;
}

.col {
  width: 100%;
}


/*Tablet View*/

@media (min-width: 700px) {
  .style-logo {
    float: center;
  }
  body {
    max-width: 778px;
  }
  .style-nav ul li {
    display: inline-block;
  }
  h1.normal {
    font-size: 57px;
    text-transform: uppercase;
    font-weight: 200;
    margin-bottom: 60px;
  }
  .row:before,
  .row:after {
    content: "";
    display: table;
    padding: 5px;
    color: #FFFFFF;
    text-align: center;
  }
  .col-tablet {
    width: 50%;
  }
  .col {
    float: left;
    padding-bottom: 14px;
    padding-left: 7px;
    padding-right: 7px;
  }
}


/*Desktop View*/

@media (min-width: 1024px) {
  .style-logo {
    float: center;
  }
  .style-nav {
    float: center;
  }
  .col-desktop {
    width: 25%;
  }
  body {
    max-width: 1200px;
  }
}
<!doctype html>
<html>

<head>
  <link href="CSS/Styles.css" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
  <meta charset="utf-8">
  <title>Home</title>
</head>

<body>
  <header>
    <div class="row">
      <div class="col">
        <img class="logo" src="Images/Logo company.png" alt="Logo">
        <nav class="style-nav">
          <ul>
            <li><a href="#">Education</a></li>
            <li><a href="#">Photos</a></li>
            <li><a href="#">Services</a></li>
          </ul>
        </nav>
      </div>
    </div>
  </header>
  <main>
    <div class="row">
      <div class="col">
        <div class="hero">
          <h3>Editor's Choice</h3>
          <h4>Maarten Nauta</h4>
          <h1 class="normal small">Webdesign</h1>
          <a href="#" class="button">Read More</a>
        </div>
      </div>
    </div>

    <div class="row">
      <div class="col col-tablet">
        <div class="infobox-tan">
          <h2>Education</h2>
          <p>And a summary of my achievements</p>
          <a href="#" class="button">Read More</a>
        </div>
      </div>
      <div class="col col-tablet">
        <div class="infobox-grey">
          <h2>Services</h2>
          <p>Graphic/Web design - Video/Photo editing</p>
          <a href="#" class="button">Read More</a>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col col-tablet col-desktop"><img src="Images/Stock-img-1.jpeg.jpg" alt="1"></div>
      <div class="col col-tablet col-desktop"><img src="Images/Stock-img-2.jpeg.jpg" alt="2"></div>
      <div class="col col-tablet col-desktop"><img src="Images/Stock-img-3.jpeg.jpg" alt="3"></div>
      <div class="col col-tablet col-desktop"><img src="Images/Stock-img-4.jpeg.jpg" alt="4"></div>
    </div>

  </main>
  <footer>
    <div class="row">
      <div class="col">
        <p class="footertext">©2018 Maarten Nauta</p>

      </div>
    </div>
  </footer>
</body>

</html>

【问题讨论】:

  • 欢迎来到 SO!为了获得反馈,将冗长的代码示例剥离到与问题相关的部分并省略其他部分可能会有所帮助——尤其是在 CSS sn-p 中。

标签: html css media-queries responsive


【解决方案1】:

您的 iPhone 的每英寸像素数比标准桌面屏幕多,实际上它的宽度大于 700 像素。为了让网页将像素视为屏幕屏幕大小的单位,您需要meta viewport tag

<meta name="viewport" content="width=device-width, initial-scale=1">

使用此标签,您的媒体查询将像标准 72 ppi 的屏幕一样运行。

【讨论】:

    【解决方案2】:

    你错过了viewport meta tag

    (...) Apple 在 Safari iOS 中引入了“视口元标记”,让 Web 开发人员控制视口的大小和比例。很多别的 移动浏览器现在支持这个标签,虽然它不是任何 网络标准。 Apple 的文档很好地解释了 Web 开发人员可以使用这个标签,但我们必须做一些侦探工作 弄清楚如何在 Fennec 中实现它。例如, Safari 的文档说内容是一个“逗号分隔的列表” 但是现有的浏览器和网页使用逗号、分号、 和空格作为分隔符。

    <meta name="viewport" content="width=device-width, initial-scale=1">
    

    【讨论】:

      猜你喜欢
      • 2013-08-28
      • 1970-01-01
      • 2012-04-20
      • 1970-01-01
      • 2020-12-19
      • 2020-01-21
      • 1970-01-01
      • 2013-08-18
      • 2021-04-30
      相关资源
      最近更新 更多