jQuery dialog theme and style

前端 未结 6 1551

How do I change the background color of the title bar of a jQuery dialog?

I have looked at the themeroller but it does not seem to work for me.

Thanks

相关标签:
6条回答
  • 2021-02-05 14:11

    The previous example works well but with only the red color of the error theme.

    Here a simple solution with just changing the header image in the 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");
        }
    });
    

    Notice that contrary to the previous example, I removed the:

    removeClass("ui-widget-header")
    

    instead of just adding the class on the:

    find(".ui-dialog-titlebar")
    

    Must note that this example works with the dialog header without its link.

    0 讨论(0)
  • 2021-02-05 14:11

    Sometimes you can't edit the css file. So you can try this:

    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');
      } 
    });
    
    0 讨论(0)
  • 2021-02-05 14:18

    Use the dialogClass property. You can apply to whatever css in jquery dialog. Below we are formatting header and content blocks.

    <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>
    
    0 讨论(0)
  • 2021-02-05 14:20

    You can change it by modifying the ui-dialog-titlebar CSS class, but I highly recommend you to use the ThemeRoller tool.

    See also:

    • UI/Dialog/Theming
    • UI/Theming/API
    0 讨论(0)
  • 2021-02-05 14:27

    I do this way (adding "ui-state-error" style for header):

    <script type="text/javascript">
                $(function () {
                    $("#msg").dialog({
                        open: function () {
                            $(this).parents(".ui-dialog:first").find(".ui-dialog-titlebar").addClass("ui-state-error");
                        }
    
                    });
    
                });
            </script>  
    
    0 讨论(0)
  • 2021-02-05 14:29

    There are classes associated with each element in the dialog.

    Use Firebug to inspect the elements and use CSS to style them. For example, the title bar has the class "ui-dialog-titlebar".

    (this assumes that you are using the jQuery UI Dialog)

    0 讨论(0)
提交回复
热议问题