【发布时间】:2015-07-03 07:46:48
【问题描述】:
我刚刚创建了一个图片库,我想知道如何使它具有响应性并在移动设备上工作。 https://willhay.io/photography/benches/ 现在,如果你把它放在 iPhone 上,它看起来很糟糕。图像占用'100vh',因此是整个屏幕的高度。在横向模式下,它看起来不错,尽管它会奇怪地缩小。在纵向模式下,由于图像占据了屏幕高度的 100%,因此宽度溢出并且不适合屏幕。
如何在移动设备上做到这一点,它会填充 100% 的宽度并垂直居中?
<!doctype html>
<html>
<head>
<meta charset="UTF-8"/>
<!-- <meta name="viewport" content="width=device-width, initial-scale=.5" > -->
<title>Bay Trail Benches</title>
<link rel="stylesheet" href="../../css/photography.css"/>
<link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
<link rel="shortcut icon" href="../../favicon.ico" type="image/x-icon" />
</head>
<body>
<a class="xButton" href="../../photography">✕</a>
<a class="rightButton" href="../gazing-up">⇒</a>
<a class="leftButton" href="../columns">⇐</a>
<img class="wideImage" alt="benches" src="../images/benches.jpg">
</body>
</html>
CSS
.wideImage {
height:100vh;
width:auto;
display:block;
margin:auto;
}
【问题讨论】:
-
将
width: auto;更改为width: 100%; -
这会改变图像的纵横比
标签: html css image mobile responsive-design