css如何让一张图平铺width 100%;并且高度等于整个手机屏幕的50%?

如题:css如何让一张图平铺width 100%;并且高度等于整个手机屏幕的50%?

阅读 5.2k
6 个回答

最简单的办法:height: 50vh; width: 100%

image{
    width: 100%;
    height: 50%;
    position: absolute;
    top: 0;
}


clipboard.png

width通过css应该就可以,height的话可以通过jquery来实现,大概意思如下,`window.onload=function(){
$('#img').css('height',$(documet).height()/2);
}`

.test{
    width:100%;
    height:0;
    padding-bottom:50%;
    backgroud:url(xx) repeat;
}
-----------------------

不对。。看错了,是手机屏幕的50%啊。那无视我这条。_(:з」∠)_

新手上路,请多包涵

宽度当然是100%了,高度的话,如果你熟练用jQuery,就用jQuery获取页面的高度/2不就是一半了么。

$(document).height()/2
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏