jQuery对话框:如何控制按钮窗格高度

时间:2011-05-20 17:15:42

标签: jquery css jquery-ui jquery-ui-dialog

如何在不更改CSS文件的情况下手动调整/设置jQuery对话框中按钮窗格的高度?我想从Javascript调整包含消息的DIV和包含按钮(以绿线标记)的DIV的高度。

jQuery Dialog

function showMessageDialog(title, message, width){
     // create div if it doesn't exist already
     if(!$("#msgDialogDiv").length) {
         $("<DIV></DIV>").appendTo("body").attr("id","msgDialogDiv");
     }
     // set the message
     $("#msgDialogDiv").html(message).css("color","red");

     // show the dialog
     $("#msgDialogDiv").dialog({
        modal: true, resizable: false, draggable: false, title: title, width: width,
        buttons: {OK: function(){$(this).dialog("close");}}
      });

      // This changes the height as I want.
      // $("#msgDialogDiv").css({"overflow":"hidden","height":"10px"});
      // this changes the font on button
      //$("#msgDialogDiv").dialog("widget").find(".ui-button-text").css("font-size", "11px");
      return;
}

showMessageDialog("Hello Stackoverflow!", "This is my first question on stackoverflow",400);

在发布此问题时,我尝试调整DIV高度并且工作正常。我也尝试更改按钮的字体大小,但这只会改变按钮的大小。我想控制整个DIV的大小。是否是由于按钮周围的填充物?

4 个答案:

答案 0 :(得分:6)

自己找到它。这就是我想要的。

// set the size of the button
$("#msgDialogDiv").dialog("widget")
                  .find(".ui-button-text").css("font-size", "10px")

// this is not required. but doesn't hurt. To hardcode the height, 
// just change to height instead of minHeight
//$("#msgDialogDiv").css({"minHeight":"10px"})

// button pane style
$("#msgDialogDiv").dialog("widget").find(".ui-dialog-buttonpane")
                  .css({"padding":".1em .1em .1em 0","margin":"0 0 0 0"} )

// button style
$("#msgDialogDiv").dialog("widget").find("button")
                  .css({"padding":"0 .2em 0 .2em","margin":"0 .5em 0 0"} )

答案 1 :(得分:5)

将以下内容放在您自己的自定义CSS文件中,在jQuery UI CSS之后加载:

.ui-dialog .ui-dialog-buttonpane {
    margin: 0px;
    padding: 0px;
}

由于 CSS特殊性规则,需要双选择器。如果没有.ui-dialog前缀,则无法覆盖先前加载的默认值。

请参阅http://jsfiddle.net/alnitak/UQAqg/

答案 2 :(得分:0)

这是旧帖子。但这也可以通过以下方式完成。

假设您在html中关注了div

<div id="no-record-found-message" title="No Record found" >
    <p>No Record found for the selected event</p>
</div>

在Js中创建对话框时分配一个类

function createNoRecordFoundDialog(div) {

    var $noRecordFoundDiv = $("#" + div);

    var $noRecordFoundDialog = $noRecordFoundDiv.dialog({
        autoOpen: false,                // set this to false so we can manually open it
        dialogClass: "noRecordFound",   // your css class
        width: 250,
        show: {
            effect: "scale",
            duration: 1000
        },
        hide: {
            effect: "scale",
            duration: 1000
        },
        modal: true,
        resizable: false,
        buttons: {
            Ok: function() {
                $( this ).dialog( "close" );
            }
        }
    }); // end of dialog

    return $noRecordFoundDialog;
}

css

.noRecordFound .ui-dialog-buttonpane {
    margin: 0px !important;
    padding: 0px !important;
}

.noRecordFound .ui-dialog-content {
    min-height: 38px !important;
}

答案 3 :(得分:-2)

只需更改jQueryUI.css文件

即可