Creating a custom CSS overlay for a jQueryUI widget

Having some trouble darkening the widget overlay provided by jQueryUI's "dialog". Despite trying to override the CSS used by jQuery, specifically the class ui/widget-overlay, I can't seem to apply my own styles successfully in my stylesheet.

I attempted $( '.ui-widget-overlay' ).addClass( 'override' ) but it didn't load my style (confirmed using Chrome developer tools). Similarly, $( '.ui-widget-overlay' ).removeClass( 'ui-widget-overlay' ).addClass( 'override' ) had no effect either.

Even using the !important marker in my stylesheet did not yield the desired result.

You can find my Fiddle here. The current jQueryUI standard CSS for .ui-widget-overlay is:

.ui-widget-overlay { background: #aaaaaa url(images/ui-bg_flat_0_aaaaaa_40x100.png) 50% 50% repeat-x; opacity: .3;filter:Alpha(Opacity=30); }

I want to replace it with this:

.ui-widget-overlay { background: #222222 50% 50% repeat-x; opacity: .3;filter:Alpha(Opacity=30); }

HTML

<a href="#" id="advisers-image">
    <div class="circle hovershadow advisers advisers-box-shadow text">Professional
        advisers</div>
</a>

<a href="#" id="industry-image">
    <div class="circle hovershadow industry industry-box-shadow">Industry</div>
</a>

<div style="clear: both;"></div>

<div id="advisers-dialog" class="dialog">

    <div id="tabs">
        <ul>
            <li><a href="#tabs-1">Law firms</a></li>
            <li><a href="#tabs-2">Accounting and audit firms</a></li>
            <li><a href="#tabs-3">Management consultants and economists</a></li>
        </ul>
        <div id="tabs-1">
            <p>Law firm text here.</p>
            <div id="tabs-inner-link"><p>Click <a href="#">here</a> to see how we can give you the edge.</p></div>
        </div>
        <div id="tabs-2">
            <p>Accounting and audit firm text goes here.</p>
        </div>
        <div id="tabs-3">
            <p>Management consultants and economists text goes here.</p>
        </div>
    </div>
</div>

<div id="industry-dialog" class="dialog" title="Industry">Industry
    text goes here</div>

Javascript

$( "#tabs" ).tabs();

var commonDialogOptions={
autoOpen: false,
height: "auto",
modal:true,
width:700
};

$("#industry-dialog, #advisers-dialog").dialog(commonDialogOptions);

$( "#industry-image" ).click(function() {
$( '.ui-widget-header' ).addClass( 'override' );
$( '.ui-widget-header a' ).addClass( 'override' );
$( '.ui-widget-overlay' ).addClass( 'override' );
$( "#industry-dialog" ).dialog( "open" );
});     

$( "#advisers-image" ).click(function() {
$( '.ui-widget-header' ).addClass( 'override' );
$( '.ui-widget-header a' ).addClass( 'override' );
$( '.ui-widget-overlay' ).addClass( 'override' );
$( "#advisers-dialog" ).dialog( "open" );
$( "#tabs" ).tabs( "option", "heightStyle", "content" );
$( "#tabs" ).tabs( 'select', 0 );
});

CSS

.circle {
width: 220px;
height: 220px;
border-radius: 50%;
border: 2px solid #fff;
float: left;
display: inline-block;

/* text styling for circles - see also the .text style below */
font-size: 35px;
color: #FFF;
line-height: 220px;
text-align: center;
font-family: Ubuntu, sans-serif;
}

.dialog {
font-family: 'Istok Web', sans-serif;
font-size: 14px;
line-height: 1.8em;
}

#tabs {
font-family: 'Istok Web', sans-serif;
font-size: 14px;
line-height: 1.8em; 
}

#tabs a:link { font-weight: bold; text-decoration: none; color: #5E2750; }
#tabs a:visited { font-weight: bold; text-decoration: none; color: #5E2750; }
#tabs-inner-link a:hover { text-decoration:underline; }

.advisers {
background: #5E2750;
margin-left: 28%;
margin-right: 13%;
}

.advisers-box-shadow {
box-shadow: 0px 0px 1px 1px #5E2750
}

.industry {
background: #DD4814;
}

.industry-box-shadow {
box-shadow: 0px 0px 1px 1px #DD4814
}

.hovershadow:hover { box-shadow: 0px 0px 4px 4px #AEA79F }

.text { /* used by professional advisers circle */
line-height: 40px;
padding-top: 70px;
height: 150px
}

/* Styles below are overriden styles found in jquery-ui.css */
.ui-widget-header.override { border: 1px solid #ffffff; background: #ffffff; color: #DD4814; font-weight: bold; }
.ui-widget-header.override a { color: #DD4814; }
.ui-widget-overlay.override { background: repeat-x scroll 50% 50% #222222; opacity:0.3; filter:Alpha(Opacity=15); }

Answer №1

To customize the appearance of the dialog, you can add the .addClass('override') method to the dialog options within the open event:

var customDialogOptions = {
    autoOpen: false,
    height: "auto",
    modal: true,
    width: 700,
    open: function (event, ui) {
        $('.ui-widget-header').addClass('override');
        $('.ui-widget-header a').addClass('override');
        $('.ui-widget-overlay').addClass('override');
    }
};

Check out this demo on JsFiddle: http://jsfiddle.net/CXhVs/2/

For more information about the jQuery UI open event, visit the following documentation: jquery UI open event docs

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Modifying a menu using jQuery: Hover function not functioning properly while dragging

I'm currently working on a webpage that involves reordering a menu using the jquery sortable function. The menu includes a navigation bar with links positioned horizontally, and when hovering over a link, a submenu drops down as expected. However, I h ...

What is the most efficient method for utilizing a jQuery selector in terms of performance?

I'm working on optimizing the JavaScript code for our website and could use some advice on what to do and what to avoid. Currently, we are utilizing jQuery 1.7.1 as our library. While I may be new to optimizing/writing optimized code, one thing I und ...

What is the best way to access the inner html of every cell within a table row that I have selected?

I want to implement a feature on my website where users can click a "save" button on a specific row in a table and save the entire row's innerHtml onto another page as their favorite hiking trails. I've been trying to achieve this by adding clic ...

Convert HTML code into a customized JSON structure

Is there a way to convert HTML into a specific JSON object? For instance This HTML page is well-structured (originally in markdown). I am interested in creating a JSON version of the different sections present on the page. In this scenario, every "h2" s ...

The replace function fails to recognize Cyrillic characters when combined with the /b flag

Struggling with a persistent issue, I've noticed that my code works perfectly with Latin characters but fails to recognize Cyrillic characters when using jQuery. $('p').each(function() { var $this = $(this); $this.html($this.text().re ...

Is HTML5 Ajax Upload Degrading?

Recently, I came across a fascinating technique for uploading files using Ajax: http://www.sitepoint.com/html5-javascript-file-upload-progress-bar/ This method has piqued my interest and raised a couple of questions in my mind. Surprisingly, the tech ...

Move the modal dialog so it appears closer to the top of the page

I am facing a challenge with my jQuery modal dialog. While it is loading properly, I am restricted to using an older version of jQuery (1.12.4) and cannot upgrade it. My goal is to center the modal close to the top of the page, similar to how it is positio ...

MacOS web browsers adjust content to fit the screen size

As I delve into React development, one thing that has caught my attention is how MacOS browsers try to fit all the page content in view rather than allowing users to scroll. Let me illustrate this with an example: function Example() { const Elements = ...

What is the best method for placing text over an image in Dreamweaver?

What steps should I take to overlay text on an image using Dreamweaver? Similar to the example linked below: https://i.stack.imgur.com/8GvkW.png Below is a snippet of my code: HTML <body> <main> <header> <img src="images/headerimag ...

The Bootstrap 3 Navbar displays a #EEEEEE color when a link is hovered over

I have not specified a hover color in the stylesheet for links to be #EEEEEE. I want the navbar hover effect to blend in with the navbar background, creating a seamless transition when hovered over. For reference, here is my current stylesheet code: Paste ...

What is the best way to use JavaScript to click on a block and retrieve its attribute value?

Struggling to capture the data-id attribute value of each item on click, despite researching online. Seeking guidance as I navigate the learning process and encounter programming frustrations. document.addEventListener("click", handle); const demo = e. ...

Resolving issues with jQuery input values

I have been working on a form that allows users to choose an amount or specify another amount. When the user clicks on "other amount," it changes the displayed amount to $5. My goal is to make it so that when the user specifies an amount other than 5, it u ...

Is there a way to move my icon to the next row once it is added?

Can anyone suggest a style, bootstrap, or code solution for my issue? Currently, when I add an item, it is placed at the end of the row, but I want them to shift to the next row. Below are two images showing my current implementation: pic1 pic2 <div cl ...

Link a PHP variable to a JavaScript variable

Is there a way to set the value of a JavaScript variable using a PHP variable? $(function(){ $("select[name=myselectlist]").change(function(){ var id = $(this).val(); if(id != 0) { $.post("ajax.php", {"id":id}, func ...

Incorporating a remote PHP file into your website using JavaScript

Is it feasible to utilize JS (jQuery) for executing a $.post from any website on any domain to a script on my server? This query stems from my reluctance to disclose my PHP files to clients (and avoid spending money on ionCube or similar solutions). By se ...

Nested Bootstrap structure with a column containing two sub-columns

I am attempting to create a grid layout using bootstrap. The layout should consist of a full 12 column layout on desktop, with an 8 column grid and a 4 column grid within it. The 8 column grid will contain an image/text, while the 4 column grid will have t ...

Having trouble getting an HTML form with PHP to successfully save data into a MySQL database server

https://i.sstatic.net/lLH0V.jpg I'm currently working on a code snippet that generates a <textarea> for user input. However, I seem to be encountering an issue where the code only outputs "please include some content", even when there is text i ...

Tips for embedding external URLs into a div element without using an iframe

I need help loading an external URL into a div without using iframe, embed, or object tags. I have tried examples but they do not seem to be working properly. Here is an example of what I have tried: $("#testDiv").load("//localhost:8000/cities/Mountain%2 ...

centering the text within the div for perfect alignment

I've been attempting to customize a Register form. My goal is to position the heading in the center of the div while having another login form located right beside it. Using flexbox, I styled them and then applied justify-content as center. Additiona ...

Animating skill bars as you scroll down the page

How can I achieve a skill bar animation on a specific section of the page scroll? I have attempted to create a sliding skill bar animation, but it is not producing the desired effect. It currently starts animating at the beginning of the page, but I want i ...