【问题标题】:how to display images correctly on mobile devices?如何在移动设备上正确显示图像?
【发布时间】:2016-09-13 19:52:48
【问题描述】:

我们拥有的背景图片是 1920x1080p,它可以在桌面浏览器上正确显示,但在移动设备上却不能(不是纵向或横向模式)。无论如何要解决这个问题?我需要多张图片还是有办法自动调整大小?这是 .css 文件。

#tf-home{
    background: url(../images/OdysseyTitleImage.jpg);
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    background-repeat: no-repeat;
    color: #cfcfcf;
}

#tf-home .overlay{
    background: -moz-linear-gradient(top,  rgba(0,0,0,0.8) 0%, rgba(0,0,0,0.73) 17%, rgba(0,0,0,0.66) 35%, rgba(0,0,0,0.55) 62%, rgba(0,0,0,0.4) 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,0.8)), color-stop(17%,rgba(0,0,0,0.73)), color-stop(35%,rgba(0,0,0,0.66)), color-stop(62%,rgba(0,0,0,0.55)), color-stop(100%,rgba(0,0,0,0.4))); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top,  rgba(0,0,0,0.8) 0%,rgba(0,0,0,0.73) 17%,rgba(0,0,0,0.66) 35%,rgba(0,0,0,0.55) 62%,rgba(0,0,0,0.4) 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top,  rgba(0,0,0,0.8) 0%,rgba(0,0,0,0.73) 17%,rgba(0,0,0,0.66) 35%,rgba(0,0,0,0.55) 62%,rgba(0,0,0,0.4) 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(top,  rgba(0,0,0,0.8) 0%,rgba(0,0,0,0.73) 17%,rgba(0,0,0,0.66) 35%,rgba(0,0,0,0.55) 62%,rgba(0,0,0,0.4) 100%); /* IE10+ */
    background: linear-gradient(to bottom,  rgba(0,0,0,0.8) 0%,rgba(0,0,0,0.73) 17%,rgba(0,0,0,0.66) 35%,rgba(0,0,0,0.55) 62%,rgba(0,0,0,0.4) 100%); /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#cc000000', endColorstr='#66000000',GradientType=0 ); /* IE6-9 */
    height: 1080px;
    background-attachment: fixed;
}
.home-lead{
    color: #fff;
    padding: 10px 15px;
    background-color: rgba(51, 51, 51, 0.9);
    font-size: 21px;
}
.content{
    position: relative;
    padding: 30% 0 0;
}

这是 .html 文件

<div id="tf-home" class="text-center">
    <div class="overlay">
        <div class="content">
            <div><a href="https://www.youtube.com/watch?v=HRlP0t41wCw" class="btn tf-btn btn-default popup-video">Watch the trailer</a></div>
            <a href="#tf-game" class="fa fa-angle-down page-scroll"></a>
        </div>
    </div>
</div>

【问题讨论】:

  • 在我看来不像 Android 代码 - 为什么我会通过搜索 Android 找到它?我没有什么可以提供的。 womp womp 不敢相信我点击了另一个。
  • 好的,抱歉。

标签: html css responsive-design


【解决方案1】:

这可能是由#tf-home .overlay 中的height: 1080px; 引起的。它在桌面上看起来不错,因为它有足够高的空间。但是同样的高度也适用于移动设备,所以图形的面积比一般的移动设备视口要大很多。

您是否尝试过在移动设备的媒体查询中创建更合适(更小)的高度?例如。

@media (max-width: 600px) {
    #tf-home{
        background-attachment: scroll;
    }
    #tf-home .overlay {
        height: 320px;
    }
}

【讨论】:

  • 我需要创建单独的图像并保存它还是此代码自动重新调整较大图像的大小?
  • 我会从使用相同的图像开始,看看您是否可以在桌面上以一种方式操作它,而在移动设备上以另一种方式操作。 CSS 能够为较小的屏幕调整桌面图像的大小。一旦您拥有以两种不同方式显示图像的代码,如果桌面图像不适合,您可以创建第二个针对移动设备优化的图像。您的来电。
  • 由于某种原因,它确实不适用于 iphone。我尝试使用代码,但仍然无法正确显示图像。
  • background-attachment:fixed; 也可能导致问题。我已经更新了上面答案中的代码。
猜你喜欢
  • 1970-01-01
  • 2016-11-11
  • 2016-02-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多