我有一个摄影网站,我的网站目标是一个接一个地在页面上显示图像。非常非常简单。但是,该网站未在桌面和移动平台上统一显示。到目前为止,该网站在iPhone 5和S7上是完美的。它在图像大小调整方面存在问题,并且在具有大css像素宽度的某些桌面和移动设备上居中。我不知道如何解决这个问题。我将在下面包含html和css。提前谢谢!
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>
答案 0 :(得分:0)
由于您的.container
具有固定/已知宽度,因此您可以为左侧和右侧执行自动边距。这看起来像这样:
margin: 0 auto;
代替margin: 10px;
我还建议您在height: auto;
张图片上使用.resize
。这样,高度将自动设置,保持原始图像比例不变。当看到坐在岩石上的家伙的压扁照片时,这是最明显的,因为它是一张高大的(即肖像)照片。
希望有所帮助!
答案 1 :(得分:0)
我建议从改进标记开始:
figure
标记将alt
属性添加到您的图片以获取辅助功能