Adjust the width of a modal in Bootbox for a specific modal only

Currently, I am successfully using Bootbox 4 along with Bootstrap 3 on IE (IE 8 / IE 9) without any issues.

In Bootstrap 3, it seems that you can adjust the modal width using CSS like this, but the drawback is that this change will apply to all modals:

.modal-dialog {
    width:70% !important;
}

Is there a method in CSS, jQuery, or Bootbox settings to specifically modify the width of a Bootbox alert modal for only one particular instance? The documentation provided by Bootbox is limited and I haven't been able to find information on this elsewhere.

Update

Below is the JavaScript code that generates the specific modal (with sample data):

bootbox.dialog({
    message: " \
        <table class='table table-hover'> \
            <thead> \
                <tr> \
                    <th>Item Name</th> \
                    <th>Location</th> \
                    <th>Path</th> \
                    <th>Last Update</th> \
                </tr> \
            </thead> \
            <tbody> \
                <tr> \
                    <td>Item 1</td> \
                    <td>Navbar - Level 2</td> \
                    <td>Products - blabla</td> \
                    <td>Added by xxx on 05 Aug 2014</td> \
                </tr> \
            </tbody> \
        </table>",
    title: "Search Results",
    buttons: {
        main: {
            label: "Close",
            className: "btn-primary"
        }
    },
    className: "modal70"
});

Here is my current CSS styling:

.modal-dialog.modal70 {
    width:70% !important;
}

Answer №1

Give this a shot:

.modal70 > .modal-dialog {
    width:70% !important;
}


Update:

Check out the Demo

Answer №2

Just to provide additional details...

According to the documentation, you have the option to adjust the size of the modal using the "size" property in the constructor.

This adds the appropriate Bootstrap modal size class to the dialog wrapper.
The valid values are 'large' and 'small' (Default: null)

bootbox.dialog({
    size: <small|large>
});

Check out the snippet below for an example of how to use it (best viewed in full screen)

$(".size-by-function-0").click(function() {
    bootbox.dialog({
        size: "null",
        title: "Example of Modal with Default Size",
        message: "...",
    });
});

$(".size-by-function-1").click(function() {
    bootbox.dialog({
        size: "small",
        title: "Example of Small Size Modal",
        message: "...",
    });
});

$(".size-by-function-2").click(function() {
    bootbox.dialog({
        size: "large",
        title: "Example of Large Size Modal",
        message: "...",
    });
});

/*********************/
// Or make it dynamic... using only one function
$(".dynamic-size").click(function() {
    bootbox.dialog({
        size: $(this).data('size'),
        title: "Example of Dynamic Size Modal",
        message: "...",
    });
});
p {
    cursor: pointer;
    background-color: #ccc;
}
<script type="text/javascript" src="//code.jquery.com/jquery-2.1.0.js"></script>
<script type="text/javascript" src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<script type="text/javascript" src="https://github.com/makeusabrew/bootbox/releases/download/v4.3.0/bootbox.min.js"></script>

<p class="size-by-function-0">Modal with default size</p>
<p class="size-by-function-1">Modal with "size: small"</p>
<p class="size-by-function-2">Modal with "size: large"</p>

<hr />

<p class="dynamic-size" data-size="null">Modal with "size: default"</p>
<p class="dynamic-size" data-size="small">Modal with "size: small"</p>
<p class="dynamic-size" data-size="large">Modal with "size: large"</p>

For more information, visit the source:

Please Note: This feature requires Bootstrap 3.1.0 or newer.

Answer №3

If Moshtaf's solution is not effective, try adding the following line as well:

.modal70 > .modal-dialog {
    width:70% !important;
    max-width:70% !important;
}

The reason for this addition is that Bootbox also includes a default value for max-width which may conflict with the specified width.

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

Displaying several modals with a backdrop on top of one another using Bootstrap

My issue involves two modals: one that displays appointment information with a delete button, and another that serves as a warning before deleting. I want the delete-warning modal to overlay a backdrop on the modal beneath it, graying it out. However, both ...

View-only text area and Internet Explorer version 9 scroll bars

I'm encountering an issue with setting the readonly attribute on textareas. I am using JQuery to apply the attribute, as shown here: $("#mytextarea").prop("readonly", true); For CSS styling: textarea { width: 400px; height: 400px; } textarea[readon ...

Using Jquery to determine if a div is empty, excluding any content before or after it

I'm looking to use JQuery to determine if a Div is empty without taking into account any content added before or after it. When checking for emptiness, I want to ignore anything placed before or after the div. $(function(){ if($('#content&ap ...

Is there a way to turn off step navigation in bootstrap?

Displayed below is a visual representation of the bootstrap step navigation component. Presently, there is an unseen 'next' button located at the bottom of the page. When this 'next' button is pressed, it transitions from 'step-1 ...

Displaying dynamically loaded content using jQuery as the user scrolls

I'm currently working on a page that retrieves data from an SQL database table and displays it. I need to load more data as the user scrolls down the page. Since the data comes from the database, it's tricky to determine which rows have already b ...

problems with loading jquery and jquery UI conditionally

This code snippet demonstrates how to load jQuery from a CDN, falling back to a local version if needed: <script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> <script>!window.jQuery && document.write( ...

CSS: Preserve HTML elements and only conceal the text within an <a> tag

Inside an "a" element, there's an image followed by text as a link. I'm looking to only hide the text of the link without affecting the display of the image. <a href="https://www.example.com/page"> <img src=" ...

Customized style sheets created from JSON data for individual elements

One of the elements in the API requires dynamic rendering, and its style is provided as follows: "elementStyle": { "Width": "100", "Height": "100", "ThemeSize": "M", "TopMargin": "0", " ...

Is there a way to ensure my background image crops properly as I resize my webpage?

Currently, I am facing an issue with resizing my background image. The image does not distort when resized, which is good, but it also does not crop as desired. For instance, there is a banner at the top of the page with a graphic on the left side. When I ...

Unique underlined text design (+using+ and - symbols-)

I'm looking to create a customized text decoration, as shown in the image below: https://i.stack.imgur.com/emjND.png It's easy to achieve a dashed line using CSS for decorations like this: color: red; border-bottom: 3px dashed; // You can adjus ...

Aligning floating elements in the center

Presently, I am working with the following code... <!DOCTYPE html> <html> <head> <title>Test</title> <meta charset="UTF-8" /> <link href="verna.css" type="text/css" rel="stylesheet" /> </head> ...

Achieving Full Height and Width of Tab Panel with Bootstrap 4.3

I recently upgraded to bootstrap 4.3 and discovered the handy sizing classes m-* and w-* for setting element height and width. After successfully achieving 100% height and width for the container, I'm now looking to apply these dimensions to the tab-p ...

Guide to display half of an image and allow for full image viewing upon mouse hover

After creating my bootstrap 4 website, I encountered an issue with the code below where only half of the image is displayed initially due to a conflict in the code. It also fails to work properly when moving the mouse after shifting the whole image from ri ...

An easy way to switch animations using CSS display:none

Dealing with some missing gaps here, hoping to connect the dots and figure this out. I'm attempting to create a functionality where a div slides in and out of view each time a button is clicked. Eventually, I want multiple divs to slide out simultane ...

Having trouble finding the correct route using an ajax request

Having trouble finding the correct route through an ajax call In my view, I have 2 HTML buttons that are generated using PHP <?php if ($comment_exist == null): ?> <p><input type ="button" id = "sb" value="I Comment"></p> &l ...

Error message: "The variable 'bitmap' is not defined in jQuery/CreateJS $.ajax"

I recently acquired a product designer that uses CreateJS and jQuery. Within the code, there is a function called UrlLoader which wraps an $.ajax call. function UrlLoader(params) { $.ajax({ url: url, type: 'POST' ...

IFrame displaying blank page instead of report

The following code snippet displays a report within an IFrame: HTML <div id="dialogReport"> <div> <iframe id="reportFrame" style="width: 800px; height: 600px; border: 2px solid black; margin: 10px auto;"> </iframe> </di ...

Ways to dynamically update a div with data from a JSON response

I'm currently in the process of developing a search platform. I have three static divs on the search results page that display certain content, all containing similar code. For example: <div id="result" class="card"> <img src="hello.png" ...

Choose every fourth row in the table

Is there a way to alternate the background colors of selected groups of 4 rows in a table? I want to make one group red and the next group blue. Any suggestions or ideas on how to achieve this? <table> <tr style="background-color: red;"> ...

Troubleshooting: Bootstrap update functionality is only functional in Debug configuration in Visual Studio

I recently made the switch from Bootstrap 2 to Bootstrap 4, updating the syntax, grids, and other elements. While everything was working fine in debug mode, I encountered an issue when trying to release the website. Even though there were no errors during ...