【问题标题】:How do size a simulated smartphone screen in a responsive div?如何在响应式 div 中调整模拟智能手机屏幕的大小?
【发布时间】:2014-01-15 16:29:09
【问题描述】:

所以我试图在一个 div 中展示一个移动网站,它看起来像放置在响应式 html5 网站上的智能手机。我弄乱了 CSS,以便智能手机 div 在调整窗口宽度时保持稳定的纵横比。现在我正在尝试在 div 中放置一个 iframe 来模拟手机的屏幕。 我遇到的问题是我的响应式 CSS 技巧弄乱了屏幕的位置。

这是一个 jFiddle:http://jsfiddle.net/E6X4j/2/

我尝试将其相对定位,但这与 CSS 中的响应技巧相混淆。有什么建议吗?

HTML:

<div id="smartphonewidth">
<div id="smartphoneheight">
    <object type="text/html" data="http://www.engadget.com" style="width:100%; height:100%;">    
    </object>
</div>

CSS:

#smartphonewidth {
      margin-left: 5%;
      background-image: url('http://i.imgur.com/lavEp8B.png?1?5267');
      background-repeat: no-repeat;
      width: 50%;
      padding: 20%;
      background-size: 100% 100%;}

#smartphoneheight {
    position: absolute;}

【问题讨论】:

标签: html css iframe responsive-design


【解决方案1】:

FIDDLE

#smartphonewidth {
          margin-left: 5%;
          background-image: url('http://i.imgur.com/lavEp8B.png?1?5267');
          background-repeat: no-repeat;
          width: 58%;
          padding: 15%;
          background-size: 100% 100%;
}

#smartphoneheight {
    height: 15%;
position: relative;
margin-bottom: -69px;
margin-top: -50px;
}


<div id="smartphonewidth">
    <div id="smartphoneheight">
        <object type="text/html" data="http://www.engadget.com" style="width:100%; height:70%;">    
        </object>
    </div>
</div>

【讨论】:

  • 从绝对位置切换#smartphoneheight 位置的问题是,现在智能手机图像无法响应用户更改页面宽度。在我原来的 jFiddle 中,无论页面宽度如何,智能手机图像都保持纵横比。
【解决方案2】:

使用此链接CSS3 media queries for reponsive design

要针对小型设备,我们可以使用以下语法:

@media only screen and (max-device-width: 480px) {
          //your css here
    }

请查看JSFIDDLE

CSS:

#smartphonewidth {
          margin-left: 5%;
          background-image: url('http://i.imgur.com/lavEp8B.png?1?5267');
          background-repeat: no-repeat;
          width: 50%;
          padding: 20%;
          background-size: 100% 100%;

}

#smartphoneheight {
    position: relative;
    z-index:1;
    width:100%;
    height:100%;
}

【讨论】:

  • 抱歉,我不关心屏幕分辨率。网站的响应部分已经运行。我的问题与另一个 div 中的一个 div 有关。
  • 在答案中检查我的小提琴并回复问题..!!
  • 我认为我的情况措辞不佳。这张 iPhone 的图片被放置在响应式 html5 网站上。我的目标是让 iPhone 图像在图像的屏幕区域内有另一个网站的 iFrame。这有帮助吗?我知道我遇到了一个初始风格的问题。
  • 嘿,看看我提供的小提琴..!!它完全符合您的要求..??
  • 我已经尝试过了,但是从绝对位置切换#smartphoneheight 的问题在于,随着用户更改页面宽度,iPhone 图像的纵横比不再恒定。如果你回到我的 jFiddle,你可以改变 html 页面的宽度并且手机已经保持相同的纵横比。不过,我确实很感谢您的努力!
猜你喜欢
  • 2019-03-27
  • 1970-01-01
  • 2012-08-31
  • 2019-10-14
  • 1970-01-01
  • 2014-09-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多