Picflight
Picflight

Reputation: 3852

jQuery dialog theme and style

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

Upvotes: 14

Views: 73708

Answers (6)

Hermann Schwarz
Hermann Schwarz

Reputation: 1735

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');
  } 
});

Upvotes: 0

Christian C. Salvad&#243;
Christian C. Salvad&#243;

Reputation: 827286

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

See also:

Upvotes: 13

Junior Mayhe
Junior Mayhe

Reputation: 16411

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>

Upvotes: 2

Geoffroy CALA
Geoffroy CALA

Reputation: 951

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.

Upvotes: 1

DonSleza4e
DonSleza4e

Reputation: 731

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>  

Upvotes: 12

jonstjohn
jonstjohn

Reputation: 60276

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)

Upvotes: 3

Related Questions