简体   繁体   English

自定义jQuery UI对话框样式

[英]Customize jQuery UI dialog style

I have this dialog: 我有这个对话框:

var dialog1 = $('<div>').dialog({ 
    autoOpen: false, 
    modal: true,
    closeText: null,
    hide: "scale",
    show:"fade",
    height: 'auto',
    width: 450,
    dialogClass:"edialog"
}); 

when I want to customize style,inline style overrides my style: 当我想自定义样式时,内联样式会覆盖我的样式:

overrriding

How can I force dialog to use my style without using !important or edit generated inline style? 如何在不使用!important或编辑生成的内联样式的情况下强制对话框使用我的样式?

You don't. 你没有。 Inline has the highest precedence over the selector chain. 内联比选择器链具有最高优先级。 The only way to override it, that I know of, is to modify the DOM of the element or use !important . 我知道,覆盖它的唯一方法是修改元素的DOM或使用!important

I would say if they went through the trouble of defining the styles inline, it is for a good reason and probably shouldn't be modified. 我会说,如果他们经历了内联定义样式的麻烦,这是有充分理由的,可能不应该修改。


Here would be the difference between using !important and changing the inline style with jQuery: 这将是使用!important和使用jQuery更改内联样式之间的区别:

jQuery: $(".ui-dialog").css({ "position" : "fixed", "top" : "50%" }); jQuery: $(".ui-dialog").css({ "position" : "fixed", "top" : "50%" });

css: .ui-dialog { position: fixed !important; top: 50% !important; } css: .ui-dialog { position: fixed !important; top: 50% !important; } .ui-dialog { position: fixed !important; top: 50% !important; }

Dialog Options (Barmar's comment): 对话选项(Barmar的评论):

$(".my-form").dialog({ position: { my: "top", at: "top" } });

It depends on how you feel and want to manage your source code. 这取决于您的感受和想要管理源代码的方式。 CSS seems like a easier and more elegant solution to me if you can't do it through the properties the Dialog object exposes. 如果你不能通过Dialog对象公开的属性来做CSS,那么CSS似乎是一个更简单,更优雅的解决方案。

  1. You find custom dialog in CSS 您在CSS中找到自定义对话框
  2. The example, if you want edit width of dialog, only add "!important" after width: 例如,如果要编辑对话框的宽度,只需在宽度后添加“!important”:

    .ui-dialog { position: relative; .ui-dialog {position:relative; padding: .2em; 填充:.2em; width: 500px !important;} 宽度:500px!important;}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM