【问题标题】:jQuery dialog theme and stylejQuery 对话框主题和样式
【发布时间】:2010-10-16 16:40:09
【问题描述】:

如何更改 jQuery 对话框标题栏的背景颜色?

我查看了主题滚轮,但它似乎不适合我。

谢谢

【问题讨论】:

  • 取决于您使用哪个插件来显示此类对话框(jQuery 本身没有任何对话框)。

标签: jquery dialog themes titlebar background-color


【解决方案1】:

您可以通过修改 ui-dialog-titlebar CSS 类来更改它,但我强烈建议您使用ThemeRoller tool

另见:

【讨论】:

    【解决方案2】:

    我这样做(为标题添加“ui-state-error”样式):

    <script type="text/javascript">
                $(function () {
                    $("#msg").dialog({
                        open: function () {
                            $(this).parents(".ui-dialog:first").find(".ui-dialog-titlebar").addClass("ui-state-error");
                        }
    
                    });
    
                });
            </script>  
    

    【讨论】:

    • 不要用javascript改变它。使用 CSS。
    【解决方案3】:

    对话框中的每个元素都有相关的类。

    使用 Firebug 检查元素并使用 CSS 设置样式。例如,标题栏具有“ui-dialog-titlebar”类。

    (假设您使用的是 jQuery UI 对话框)

    【讨论】:

      【解决方案4】:

      使用dialogClass 属性。您可以应用于 jquery 对话框中的任何 css。 下面我们正在格式化标题和内容块。

      <head>
      <style>
      .main-dialog-class .ui-widget-header{background: url("/Images/your-background.png") repeat-x scroll 34px 42px #a4cf50;font-size:16px;border:0;text-transform:uppercase}
      .main-dialog-class .ui-widget-content{background-image:none;background-color:#fff}
      </style>
      <script>
              $('#jq_dialog').dialog({
                  title: 'Detalhes do produto',
                  modal: true,
                  resizable: false,
                  width: 500,
                  maxHeight: 400,
                  closeText: 'fechar',
                  draggable: true,
                  show: 'fade',
                  hide: 'fade',
                  dialogClass: 'main-dialog-class'
              });
      </script>
      </head>
      <body>
      <div id="jq_dialog">Hello StackOverflow!</div>
      </body>
      

      【讨论】:

      • 我同意。使用 javascript 应用或删除类似乎是错误的做法。 css 类准确地描述了元素的状态,您只想在该状态下更改元素的外观。
      • 改变模态弹窗按钮的颜色怎么样?
      【解决方案5】:

      前面的示例运行良好,但错误主题只有红色。

      这是一个简单的解决方案,只需更改 css 中的标题图像:

      css:

      .ui-widget-header-custom{ 
          background: #f6a828 url(../images/ui-bg_flat_95_0a43ac_40x100.png) 50% 50% repeat-x;      
      }
      

      javascript:

      $('#my_dialog').dialog({ 
          open: function(event, ui){ 
              $(this).parents(".ui-dialog:first").find(".ui-widget-header")
                  .removeClass("ui-widget-header").addClass("ui-widget-header-custom");
          }
      });
      

      请注意,与前面的示例相反,我删除了:

      removeClass("ui-widget-header")
      

      而不仅仅是在以下位置添加类:

      find(".ui-dialog-titlebar")
      

      必须注意,此示例适用于没有链接的对话框标题。

      【讨论】:

        【解决方案6】:

        有时您无法编辑 css 文件。所以你可以试试这个:

        dialog = $('<div/>').dialog({
          title: 'Dialog with css for title bar',
          open: function() {
            $(this).parents(".ui-dialog:first").find('.ui-dialog-titlebar').css('background-color','#275D9E');
          } 
        });
        

        【讨论】:

          猜你喜欢
          • 2016-05-29
          • 1970-01-01
          • 2018-10-06
          • 2012-07-12
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-01-28
          • 1970-01-01
          相关资源
          最近更新 更多