2012/10/14

JQUERY UI Dialogで幅が反映されない!?

ダイアログをiframeで表示したのですが、スタイルシートでいくら幅を設定しても反映されず・・・

JavaScript、ダイアログ呼出部分抜粋

$(function () {
    $("#dialog-button").click(function(e){
        e.preventDefault();
        $('<iframe frameborder="0" src="dialog.php" />').dialog({
            title: title,
            autoOpen: true,
            modal: true,
            width: 640,
            height: 430,
            resizable: false,
            autoResize: false,
            overlay: {
                opacity: 0.5,
                background: "black"
            },
            close: function(event){
                $(this).dialog('destroy');
                $(event.target).remove();
            }
        });
    });
});

実際に表示された要素を検証してみると

<iframe id="dialog-iframe" frameborder="0" src="dialog.php"
 style="display: inline; width: auto;
 min-height: 0px; height: 375.59999990463257px; "
 class="ui-dialog-content ui-widget-content"
 scrolltop="0" scrollleft="0"></iframe>

ダイアログ自体は640pxで表示されているのに、iframeの幅がwidth:autoで大体300pxぐらいしかでていない・・・

JavaScriptもCSSもそれほど詳しくなくて、追いきれなかったので・・・強引に対応。。。

対応後

$(function () {
    $("#dialog-button").click(function(e){
        e.preventDefault();
        $('<iframe id="dialog-iframe" frameborder="0" src="dialog.php" />').dialog({
            title: title,
            autoOpen: true,
            modal: true,
            width: 640,
            height: 430,
            resizable: false,
            autoResize: false,
            overlay: {
                opacity: 0.5,
                background: "black"
            },
            close: function(event){
                $(this).dialog('destroy');
                $(event.target).remove();
            }
        });
        $("#dialog-iframe").css("width","640px");
    });
});

原因とか正しそうなCSS設定方法などあったら教えて下さい。。。

JQUERY 1.8.0、JQUERY-UI 1.8.24