【问题标题】:Resize an image in HTML/CSS for mobile devices为移动设备调整 HTML/CSS 中的图像大小
【发布时间】:2015-06-19 11:42:07
【问题描述】:

我有一张背景图片,但我真的不知道如何为移动设备调整它的大小...我已经尝试了所有方法!宽度:100%,最大宽度:100%;等等 是高度/覆盖物影响它吗?

.jumbotron {
  background-image:url('http://www.part-box.com/images/yellow-frog.png');
  height: 500px;
  background-repeat: no-repeat;
  background-size: cover;
}

【问题讨论】:

  • 你到底想得到什么?覆盖整个页面?具体尺寸?相对于原始大小?相对于页面的大小?
  • 我希望图像覆盖页面的整个宽度,但响应调整大小

标签: html image


【解决方案1】:

媒体查询可以解决这个问题。计算移动设备和其他设备的宽度。

 @media screen and (max-width: 1000px) {
        .jumbotron {
           background-image:url('http://www.part-box.com/images/yellow-frog.png');
            height: 200px; // customize it
            background-repeat: no-repeat;
            background-size: cover;
              }
    }

 @media screen and (max-width: 300px) {
        .jumbotron {
           background-image:url('http://www.part-box.com/images/yellow-frog.png');
            height: 500px; //customize it
            background-repeat: no-repeat;
            background-size: cover;
              }
    }

或者,您可以将 html 与引导程序集成,使代码在所有平台上都能响应。

【讨论】:

  • 嗯,是的,我想@media 会起作用——也许只是不那么顺利。
  • 如何将 bootstrap 集成到其中?
  • 不在 css 中,但 html 需要使用 bootstrap 3.0 脚本和 css 添加,在w3schools.com/bootstrap了解更多信息
猜你喜欢
  • 2020-12-22
  • 1970-01-01
  • 2013-10-15
  • 2013-03-27
  • 1970-01-01
  • 2017-11-27
  • 2018-06-24
  • 1970-01-01
  • 2013-03-26
相关资源
最近更新 更多