setting div width according to the screen size of user

允我心安 提交于 2019-12-06 08:13:03

What about some CSS? http://jsfiddle.net/TJGZU/

body, html { /* set size of body to full page and remove margins */
    width: 100%;
    height: 100%;
    padding: 0;
    margin: 0;
}

div { /* set div to full width and height */
    width: 100%;
    height: 100%;
}

by css seems ideal as pimvdb has suggested...doing it in jquery would be inline styling which would be a bad practice which can be avoided unless necessary.

by means of jquery:

    var windowWidth = $(window).width();
    var windowHeight =$(window).height();
    $('div').css({'width':windowWidth ,'height':windowHeight });

Edited Part:

var windowWidth = ((parseInt($(window).width())) / 2) - 120;

like this whatever height and width seems ideal for you, you can obtain via this.

user2958974

below is a sample code for your problem:

var windowWidth = ((parseInt($(window).width())) / 2) - 120;

Also, note that this answer makes use of jQuery.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!