Jquery Ui对话框按钮在鼠标悬停时改变位置

时间:2013-05-03 15:17:33

标签: jquery css jquery-ui stylesheet

我正在使用jquery ui对话并使用jquery添加按钮:

 $("#151").dialog({
                autoOpen: false,
                autoResize: true,
                buttons: {
                    "OK": function () {
                        jQuery(this).dialog('close');
                    }
                }
                ,
                open: function () {
                    $('.ui-dialog-buttonset').find('button:contains("OK")').focus();
                    $('.ui-dialog-buttonset').find('button:contains("OK")').addClass('customokbutton');
                }
            });

和custombutton类看起来像这样:

.customokbutton { 
    text-indent: -9999em; /* hides the text */
    color: transparent; /* also hides text */
    background-image: url(images/login-icon.png); /*replaces default image */
     background-repeat: no-repeat; 
    background-color: transparent;  
    background-repeat: no-repeat;   
    cursor: pointer;  
    border:none;
    height:30px;
    outline: none;
}

但是当我把鼠标按在按钮上时,它有点向下和向右。我看到使用Firebug,当我带走鼠标(更改位置)时,会添加以下css类

<button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only customokbutton" role="button" aria-disabled="false"><span class="ui-button-text">OK</span></button>

这个当我将鼠标悬停在按钮上时:

<button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only customokbutton ui-state-hover" role="button" aria-disabled="false"><span class="ui-button-text">OK</span></button>

和css是这样的:

.ui-state-hover,
.ui-widget-content .ui-state-hover,
.ui-widget-header .ui-state-hover,
.ui-state-focus,
.ui-widget-content .ui-state-focus,
.ui-widget-header .ui-state-focus {
    border: 1px solid #707070;
/*  background: #dadada;*/
    font-weight: normal;
    color: #212121;
}

我该如何解决?

1 个答案:

答案 0 :(得分:0)

这主要取决于主题,但似乎jQuery CSS中的ui-state-hover具有1px边框:

border: 1px solid #fbcb09;

css在这里:http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/themes/ui-lightness/jquery-ui.css

也许这就是将按钮1px向右和向下移动的原因。您可以尝试在CSS中强制执行border: none;属性,如下所示:

.customokbutton { 
  [...]
  border:none !important;
  [...]
}