使JQuery对话框内容的宽度和高度均为100%

Jac*_*cob 4 css jquery height dialog width

我创建一个div,然后在对话框中打开它.我尝试了这个div的样式,以实现内容在两个方向上扩展到100%.

到目前为止我尝试了什么:设置div风格

#content {
    width:auto !important;
    height:auto !important;
    background-color:red !important;
    display:block !important;
}
Run Code Online (Sandbox Code Playgroud)

并设置默认的div样式

$(div).dialog({ dialogClass: 'someStyle' });

.someStyle .ui-dialog-content 
{
    height:auto !important;
    display:block !important;
}
Run Code Online (Sandbox Code Playgroud)

似乎什么都没有用!我重写宽度属性但不能覆盖高度属性.怎么破解这个?

我希望实现这样的目标:http://jsfiddle.net/S3FQv/

har*_*ryg 11

您可以使用jQuery widthheight属性来获取视口的像素宽度,并将它们作为样式应用于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
});
Run Code Online (Sandbox Code Playgroud)

看到这个小提琴:http://jsfiddle.net/URpmR/2/

如果用户更改浏览器的大小,您还应该添加一些额外的代码来重新执行该函数:

$(window).resize(myFunction());
Run Code Online (Sandbox Code Playgroud)


Jam*_*lly 1

为了使内容具有 100% 的高度,必须在htmlbody标签上指定该高度:

html, body { height:100%; margin:0; padding:0; }
Run Code Online (Sandbox Code Playgroud)

此外,设置auto并不一定意味着宽度和/或高度为 100%。同样,旧版本的 IE 也不width: auto;支持height: auto;

如果可能的话,您也不应该用来!important覆盖现有样式。

JSFiddle 示例