【问题标题】:Image gallery on mobile devices移动设备上的图片库
【发布时间】: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


【解决方案1】:

它需要更多的 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%;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-01
    • 2010-12-10
    • 1970-01-01
    • 2011-11-26
    相关资源
    最近更新 更多