移动设备上的图片库

时间:2015-07-02 22:48:21

标签: html css image mobile responsive-design

我刚刚创建了一个图片库,我想知道如何使其响应并在移动设备上工作。 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;
}

1 个答案:

答案 0 :(得分:0)

它需要更多的CSS,因为你的html结构不是很好。

.wideImage {
    max-width: 1200px;
    width: 100%;
    display:block;
    z-index: -1;
    margin:auto;
    height: auto;
    max-height: 100%;
    position: relative;
    top: 50%;
    transform: translateY(-50%);
    -webkit-transform: translateY(-50%);
    -ms-transform: translateY(-50%);
    transform: translateY(-50%);
}
html, body {
    height: 100%;
}
相关问题