图片在桌面和移动平台上显示不一样

Images are not displaying the same across desktop and mobile platforms

我有一个摄影网站,我的网站目标是在页面上一个接一个地显示图片。非常非常简单。但是,该网站并未在桌面和移动平台上统一显示。到目前为止,该网站在 iPhone 5 和 S7 上是完美的。在某些具有大 css 像素宽度的桌面和移动设备上,图像大小调整和居中存在问题。我不确定如何解决这个问题。我将在下面同时包含 html 和 css。提前致谢!

Link 到网站 Click Here for website

CSS

@media screen and (max-width: 320px) {
  /* Smaller Devices */
  img{
    width: cover;
    max-width: 100%;
    height: cover;
  }
}
@media screen and (min-width: 374px) and (max-width: 376px) {
  /* iPhone 6 */
  img{
    width: cover;
    max-width: 100%;
    height: cover;
  }
}

@media screen and (min-width: 319px) and (max-width: 321px) {
  /* iPhone 5 */
  img{
    width: cover;
    max-width: 100%;
    height: cover;
  }

}

@media screen and (min-width: 359px) and (max-width: 361px) {
  /* Galaxy S7 */
  img{
    width: cover;
    max-width: 100%;
    height: cover;
  }
}

@media screen and (min-width: 481px) {
  /* Desktops */
  img {
  width: cover ;
  max-width: 100% ;
  height: cover ;
  }
  .resize {
   width: 1024px; /* 1024 */
   height: 682px; /* 682 */  

  }
  .container {
    margin: 10px;
    width: 1260px;
    height: 1365px;
    line-height: 115px;
    text-align: center;
    border: 0px solid red;
   }


}

body {
   background-color: gainsboro;
}

HTML

<!DOCTYPE html>
<html>
<head>
<title>Outdoor Photography</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="keywords" content="Grant Birkinbine, Birki, Grant, Photography, Outdoors" />
<link href="css/bootstrap.css" rel='stylesheet' type='text/css' />
<link href="css/style.css" rel='stylesheet' type='text/css' />
</head>
<body>

        <img src="colo.jpg">
            <br><br>
            <img src="logo.png">
            <br>
            <img src="Description.png">
            <br><br>


            <div class='container'>
            <a href="The-Great-Outdoors.html"><img class="resize" src="/images/The-Great-Outdoors.jpg"></a>
            <br><br>
            <a href="Howelsen-Hill.html"><img class="resize" src="/images/Howelsen-Hill.jpg"></a>
            <br><br>
            <a href="Wind-And-Water.html"><img class="resize" src="/images/Wind-And-Water.jpg"></a>
            <br><br>
            <a href="In-The-Golden-Light.jpg"><img class="resize" src="/images/In-The-Golden-Light.jpg"></a>
            <br><br>
            <a href="The-Canyon.html"><img class="resize" src="/images/The-Canyon.jpg"></a>
            <br><br>
            </div>








</body>
</html>

因为你的 .container 有一个 fixed/known 宽度,你可以只为左边和右边做一个自动边距。看起来像这样:

margin: 0 auto; 而不是 margin: 10px;

我还建议在您的 .resize 图片上使用 height: auto;。这样高度会自动设置,保持原始图像比例不变。这在看那个人坐在岩石上的被压扁的照片时最为明显,因为它是一张高大的(即肖像)照片。

希望对您有所帮助!

我建议从改进标记开始:

  • 将您的图像包裹在块元素中以防止内联 space
  • 在适当的地方使用 figure 标签
  • alt 属性添加到您的图像以实现辅助功能