【发布时间】:2017-12-17 18:43:33
【问题描述】:
我想用科尔多瓦 jquery 制作简单的应用程序,我想根据手机/平板电脑的屏幕宽度生成 div 的宽度。 我用这个得到了屏幕的宽度
var physicalScreenWidth = window.screen.width * window.devicePixelRatio;
var physicalScreenHeight = window.screen.height * window.devicePixelRatio;
问题是如何将屏幕宽度与我的 css 结合起来。
这是我的静态 css,我不知道如何将可变宽度组合到这个 css。 我手动创建宽度:300px、130px 等。当手机/平板电脑不同英寸时会出现问题..
.some {
margin-left:-10px;
width:300px;
height:130px;
margin-bottom: 5px;
background-color:#fff;
border-width:1px;
border-style:solid;
border-bottom-color:#aaa;
border-right-color:#aaa;
border-top-color:#ddd;
border-left-color:#ddd;
}
.one{
float:left;
width:130px;
height:130px;
}
.three{
width:170px;
height:130px;
position:absolute;
left:140px;
}
.four{
width:170px;
height:70px;
}
.five{
width:170px;
height:60px;
}
HTML
<div class="some">
<div class="one"><img class="bgr" src="1.jpg"></div>
<div class="three">
<div class="four"><p style="margin-left:10px;margin-top:2px;"><font face="arial" size="3"><b>Descc ...</b></font></p></div>
<div class="five"></div>
</div>
</div>
结果
【问题讨论】:
-
你不能用 % 代替 px 吗?
-
我知道,% 是一个解决方案,但问题是 div ONE 中的图像。我想将图像的宽度和高度全部放入 div 之一(图像的宽度和高度 = div 的宽度和高度)任何解决方案?
-
您不需要为该 div 指定特定的宽度或高度。 jsbin.com/yajepih/edit?html,css,output
标签: android jquery css cordova