
- jQuery Mobile Tutorial
- jQuery Mobile - Home
- jQuery Mobile - Overview
- jQuery Mobile - Setup
- jQuery Mobile - Pages
- jQuery Mobile - Icons
- jQuery Mobile - Transitions
- jQuery Mobile - Layouts
- jQuery Mobile - Widgets
- jQuery Mobile - Events
- jQuery Mobile - Forms
- jQuery Mobile - Themes
- jQuery Mobile - CSS Classes
- jQuery Mobile - Data Attributes
- jQuery Mobile Useful Resources
- jQuery Mobile - Interview Questions
- jQuery Mobile - Quick Guide
- jQuery Mobile - Useful Resources
- jQuery Mobile - Discussion
jQuery Mobile - Styling and Theming Dialogs
Description
Different styling and theming can be applied to a dialog. Following are the ways to apply themes and styles to a dialog −
Themes can be included in the dialog by adding the attribute data-theme to any containers such as header, footer, or content.
Include data-corners = "false" to remove the rounded corner of the dialog as by default the corners are set as rounded.
data-overlay-theme attribute sets the overlay to any pattern letter.
Multiple button can also be used in the dialogs. The dialog can be fixed to the top by including {margin-top:0} to the class specified for the page. ui-dialog.my-dialog .ui-dialog-contain
Example
Following example demonstrates the use of styling and theming dialogs in the jQuery Mobile.
<!DOCTYPE html> <html> <head> <meta name = "viewport" content = "width = device-width, initial-scale = 1"> <link rel = "stylesheet" href = "https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src = "https://code.jquery.com/jquery-1.11.3.min.js"></script> <script src = "https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> <style> .ui-dialog.dialog-actionsheet .ui-dialog-contain { margin-top: 0; } </style> </head> <body> <div data-role = "page" id = "page1"> <div data-role = "header" data-theme = "b"> <h2>Header</h2> </div> <div role = "main" class = "ui-content"> <a href = "#page2" class = "ui-btn ui-corner-all ui-btn-inline"> Open Dialog</a> <a href = "#page3" class = "ui-btn ui-corner-all ui-btn-inline"> Photos Dialog</a> </div> <div data-role = "footer"> <h4>Footer</h4> </div> </div> <div data-role = "page" data-dialog = "true" id = "page2" data-corners = "false" data-overlay-theme = "b"> <div data-role = "header"> <h1>First Dialogs</h1> </div> <div role = "main" class = "ui-content"> <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.</p> <a data-rel = "back" class = "ui-btn ui-corner-all ui-btn-inline">Back</a> </div> </div> <div data-role = "page" class = "dialog-actionsheet" data-dialog = "true" id = "page3"> <div role = "main" class = "ui-content"> <h3>Share Photos</h3> <a href = "#page4" data-transition = "slidedown" class = "ui-btn ui-shadow ui-corner-all ui-btn-b">Email</a> <a href = "#page4" data-transition = "slidedown" class = "ui-btn ui-shadow ui-corner-all ui-btn-b">Share on Facebook</a> <a href = "#page4" data-transition = "slidedown" class = "ui-btn ui-shadow ui-corner-all ui-btn-b">Tweet photo</a> <a data-rel = "back" class = "ui-btn ui-shadow ui-corner-all ui-btn-a"> Cancel</a> </div> </div> <div data-role = "page" class = "dialog-actionsheet" data-dialog = "true" id = "page4"> <div role = "main" class = "ui-content"> <h3>Photos uploaded successfully</h3> <a href = "#page1" class = "ui-btn ui-shadow ui-corner-all ui-btn-a"> View photo page</a> <a href = "#page1" class = "ui-btn ui-shadow ui-corner-all ui-btn-a"> Done</a> </div> </div> </body> </html>
Output
Let's carry out the following steps to see how the above code works −
Save the above html code as style_theming.html file in your server root folder.
Open this HTML file as http://localhost/style_theming.html and the following output will be displayed.