我创建一个div,然后在对话框中打开它.我尝试了这个div的样式,以实现内容在两个方向上扩展到100%.
到目前为止我尝试了什么:
设置div样式
#content { width:auto !important; height:auto !important; background-color:red !important; display:block !important; }
并设置默认的div样式
$(div).dialog({ dialogClass: 'someStyle' }); .someStyle .ui-dialog-content { height:auto !important; display:block !important; }
似乎什么都没有用!我重写宽度属性但不能覆盖高度属性.怎么破解这个?
我希望实现这样的目标:http://jsfiddle.net/S3FQv/
解决方法
您可以使用jQuery width和height属性来获取视口的像素宽度,并将其作为样式应用于div
var w = $(window).width(); var h = $(window).height(); //Set up the dialog with the width and height set above. $('#myDialog').dialog({ title: 'My Dialog',height: h,width: w });
看到这个小提琴:http://jsfiddle.net/URpmR/2/
如果用户更改浏览器的大小,您还应该添加一些额外的代码来重新执行该函数:
$(window).resize(myFunction());