How can I ensure the dialog title and button are centered, and how can I center a JQuery dialog box after the browser has

My current issue involves creating a dialog with centered text, but I'm struggling to achieve the same effect with the title and button. Additionally, the button I've created doesn't seem to be functional when placed in the dialog box. Despite my attempts to center the JQuery dialog box after browser resize, I have not been successful. I would greatly appreciate any help in resolving these issues. Thank you all in advance for your assistance. Here is the link to the jsfiddle: https://jsfiddle.net/robontrix/194Ljr30/

HTML:

       <div id="dialog">            
          <p style="text-align:center"> Your computer use can be monitored by others! Consider using a public computer or a friend's computer. Please view more computer safety tips or escape to Google. Then more computer safety tips linked to a page with details about browser history, cache, search history, etc. and escape to Google linked to Google.</p>
          <p style="text-align:center"> To learn more how to computer safety, click the following link: <br><a href="#">Safety Tips</a></br></p>
          <!--Wording can be better just for the meantime-->
          <p style="text-align:center"> If you are not safe, click the following link: <br><a href="#">Get Me Out of Here!</a></br></p> 
        </div> 

        <!--JQuery -->
        <script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
        <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js" type="text/javascript"></script>
        <script src="//code.jquery.com/jquery-1.10.2.js"></script>

        <script>
            $('#dialog').attr('title','Safety Warning!').dialog({
             width : 700,
             height: 350,
             modal:true,
             opacity:.7,
             closeOnEscape: true, 
             draggable: false, 
             resizable: false,
             buttons: { "Close": function() {
                $(this).dialog("close");
                }
             }
            });
            $(window).resize(function() {
              $('#dialog').dialog('option','position', 'center');
            });
        </script> 

Answer №1

To center the button and titlebar using CSS, make sure you have loaded the jquery-ui css. Here is an example:

.ui-dialog .ui-dialog-buttonpane .ui-dialog-buttonset {
    float: none;
}

.ui-dialog .ui-dialog-title, .ui-dialog .ui-dialog-buttonpane {
    text-align:center;
    padding-left: 0.4em;
    padding-right: 0.4em;
}

If the button is not functioning correctly, it may be due to another element blocking its functionality. Check for any elements with conflicting z-index values in the DOM.

For reference, here is an updated jsfiddle link.

Make sure you are loading the jquery-ui CSS. If not, you can manually add the CSS for dialogs by including the following link:

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.3/css/base/jquery.ui.dialog.css">

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

How to successfully close a jQuery dialog within a user control

My user control has a list view with a hyperlink (LnkDelete) that triggers a jQuery dialog. Here is the javascript code responsible for this functionality: $('#LnkDelete').live('click', function (e) { var page = $(this).at ...

Setting the root position of a div: How can it be done?

Imagine a scenario where a div element is designed to follow the mouse cursor on the screen. This functionality is achieved by manipulating the document's `mousemove` event and adjusting the div's `left` and `top` positions based on the event dat ...

Struggling to retrieve information from a PHP page using AJAX?

I am facing an issue with my HTML form and AJAX code. I have used AJAX to send the ID of the clicked button to a PHP page, but it seems that the PHP page is receiving a null value instead of the expected ID. As a beginner who has learned through tutorials, ...

Troubleshooting: Phonegap Not Responding to Ajax Requests

I've been trying to figure out how to make an ajax request work with PhoneGap, but I haven't had any luck so far. I'm using the latest version of PhoneGap and Android Studio. When I preview my app in AVD, everything looks good except for the ...

Hide the search popup when the user clicks on the "find" button within the jqgrid

What is the solution to closing the search popup when clicking on the Find button? When I search for data in jqgrid and click on the Find button, the Search popup remains open even though the data has been filtered. How can I close the popup after searchin ...

Is there a way to regularly extract the most up-to-date HTML code from a dynamic website for designers to work

Our team of designers is responsible for creating graphical mockups, initial html, css, and image sprites for new designs. They also maintain these files. Once the hand-off is complete, our developers then take everything and work it into .Net code, templa ...

Using a width of 100% with the display inline-block property does not function as intended

Is there a way to have both a checkbox and text input in one line, with the text input being responsive? I attempted to use display: inline-block, which worked for keeping them in the same line, but I'm having trouble making the text input fill the re ...

When incorporating conditional statements into your code, make sure to utilize the tags <script> along with

I have some script tags as shown below: <script src="cordova-2.5.0.js"></script> <script src="js/jquery-1.7.2.min.js"></script> <script src="js/jquery.mobile-1.1.1.min.js"></script> <script src="js/jquery.xdomainajax ...

In Angular, when a component is clicked, it is selecting entire arrays instead of just a single item at a

I am currently working on implementing a rating feature using Angular. This component will be used to rate different languages based on how proficient I am with them. My issue lies in the fact that when I click on one array element, it automatically selec ...

What is causing the inability of this simple Google Maps link to function properly on a Nexus 7?

Visit this link for Google Maps A client has reported that the link above is causing an error when opening the maps app. The error message reads: "unsupported link. Google Maps can't open this link." This problem is occurring on a Nexus 7 and Samsu ...

Flask Template Failing to Load Local CSS

Hello there, I am currently working on integrating custom CSS into my Flask application. While I had no issues loading Bootstrap, I seem to be facing some difficulties with my local CSS. Below is the method I am using to load my CSS: <link rel="st ...

Is it possible to replace multiple li elements with multiple ul elements within a single ul for better organization?

In the world of HTML and CSS, there are endless possibilities for creating unique designs. Recently, I stumbled upon an interesting question that has been lingering in my mind without a clear answer. Typically, people use a single "ul" element to create a ...

QuickSearch displayed at the center with a floating left alignment

I have been trying to center a QuickSearch div with multiple Q & A sections, but I am having no success. The div is floated to the left and has a background image. HTML <div class="l-row"> <div class="QuickSearch"> <div class="loop"& ...

Blazor: Passing a CSS class as a parameter to a child component

Is there a way to ensure css isolation works properly when passing a class as an argument to a child component? In the following code snippet, I anticipated the child component would display in blue, but that's not happening. Parent.razor <div cla ...

Canvas Frustratingly Covers Headline

Several months ago, I successfully created my portfolio. However, upon revisiting the code after six months, I encountered issues with its functionality. Previously, text would display above a canvas using scrollmagic.js, and while the inspector shows that ...

Tips for updating the label content once a dropdown has been chosen

Currently, I am working on a Python project and have created a dropdown field in models.py. However, I am facing an issue while trying to display it in the HTML template despite having written the necessary jQuery code. models.py addtype = models.CharFie ...

Tips on extracting information from an AJAX call using JQuery

My current project involves utilizing a webapi in asp.net that outputs JSON data. I am looking to integrate this webapi with JQuery within a php-created website. The following is the JQuery code I am using to retrieve information from the webapi: $.ajax( ...

Tips for incorporating unique images into each individual flex box

I am new to the world of coding, having just embarked on this journey less than a week ago. Following a tutorial by a developer on YouTube, I tried to add my own twist to the project in order to differentiate it from the original. However, I've hit a ...

retrieve all the table data cells except for the initial one

I have a specific table structure that I need to work with: <table> <tr> <td></td> <td></td> <td></td> <td></td> <td></td> <td&g ...

The images in Bootstrap-Grid at 1920 resolution stay compact

Is there a way to make images grow beyond the 1280 resolution? This is how it appears at 1920 resolution https://i.sstatic.net/JmYc7.png And this is at 1280 resolution https://i.sstatic.net/Sk19K.png <div id="logokutu1" class="d ...