Html 如何在移动设备上正确显示图像?
我们的背景图像是1920x1080p,它可以在桌面浏览器上正确显示,但不能在手机上显示(不能在纵向或横向模式下)。如何解决这个问题?我需要多个图像还是有办法自动调整大小?这是.css文件Html 如何在移动设备上正确显示图像?,html,css,responsive-design,Html,Css,Responsive Design,我们的背景图像是1920x1080p,它可以在桌面浏览器上正确显示,但不能在手机上显示(不能在纵向或横向模式下)。如何解决这个问题?我需要多个图像还是有办法自动调整大小?这是.css文件 #tf-home{ background: url(../images/OdysseyTitleImage.jpg); background-size: cover; background-position: center; background-attachment: fixe
#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>
这可能是由于
高度:1080px代码>在#tf home.overlay中
。它在桌面上看起来不错,因为它有足够的空间来支撑一个很大的高度。但同样的高度也适用于移动,因此图形的面积比平均移动视口大得多
您是否尝试过在移动媒体查询中创建更合适(更小)的高度?例如
@media (max-width: 600px) {
#tf-home{
background-attachment: scroll;
}
#tf-home .overlay {
height: 320px;
}
}
在我看来,它不像Android代码——为什么我要通过搜索Android来找到它?我没有什么可以提供的。womp womp简直不敢相信我点击了另一个。好吧,很抱歉。我需要创建一个单独的图像并保存它,还是这段代码自动重新调整较大图像的大小?我会从使用相同的图像开始,看看你是否可以用一种方式在桌面上操作它,用另一种方式在移动设备上操作它。CSS能够为较小的屏幕调整桌面图像的大小。一旦代码以两种不同的方式显示图像,您就可以创建第二个图像,如果桌面图像不适合,则可以针对移动设备进行优化。你的电话。由于某些原因,它在iPhone上确实不起作用。我尝试使用代码,但仍然无法正确显示图像。背景附件:已修复代码>也可能导致问题。我已经更新了上面答案中的代码。