What's the best way to position a modal in the center and have it appear below the linked button

On my front page, I have 4 links that are meant to open modals. However, there is an issue with the positioning of the modals. For example, when clicking on the 'Vente' link, the modal appears at the top of the page and only covers half of the screen with its background. I am struggling to position the modal in the center below the links with the close button on the left side.

I have included both the HTML and CSS code below:

HTML

<!doctype html>
<html lang="en">

<head>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <!-- Bootstrap CSS -->
  <link href="https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
  <link rel="stylesheet" href="css/styles.css">

  <title>Nina Beaute BI</title>
</head>

<body>
  <div class="square rounded p-5 border border-secondary">
    <img src="img/BELIVOIR.png" alt="Nina Beaute" class="center" style="width:200px;">
    <ul class="list">
      <li><button class="myBtn_multi">Vente</button></li>
      <li><button class="myBtn_multi">Inventaire</button></li>
      <li><button id="myBtn2">Achat</button><li>
      <li><button id="myBtn3">Finance</button></li>
    </ul>

<!-- The Modal -->
...
...
<!-- Optional JavaScript; choose one of the two! -->
...

</body>

</html>

CSS

div{ /*CSS styles*/ }

ul { /*CSS styles*/ }

li { /*CSS styles*/ }

button { /*CSS styles*/ }

.list li:last-child { /*CSS styles*/ }

.center { /*CSS styles*/ }

.modal {} //CSS for modal styling

.modal-content {} //CSS for modal content styling

.close {} //CSS for close button styling

Answer №1

https://dotnetfiddle.net/zZEAMT Take a look at this presentation.

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <style>
        .theStyle {
            z-index: 1;
            left: 50px;
            top: 350px; /*<-----adjust height*/
            position: absolute;
            overflow: auto;
        }

        .list li:last-child {
            border-right: none;
        }

        ul {
            padding-top: 10px;
            padding-bottom: 100px;
        }

        li {
            float: left;
            width: 25%;
            text-align: center;
            list-style-type: none;
            border-right: 2px solid;
        }

        button {
            background-color: none;
            border: none;
            color: blue;
            text-decoration: underline;
            background-color: white;
            font-family: helvetica;
            font-size: 20px;
        }
    </style>
    <meta name="viewport" content="width=device-width" />
    <title>Index2005</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
    <div class="square rounded p-5  border border-secondary">
        <ul class="list">
            <li><button style="margin-bottom: 20px;" class="btn  btn-default" data-toggle="modal" data-target="#myModal">Sales</button></li>
            <li><button style="margin-bottom: 20px;" class="btn  btn-default" data-toggle="modal" data-target="#myModal">Inventory</button></li>
            <li><button style="margin-bottom: 20px;" class="btn  btn-default" data-toggle="modal" data-target="#myModal">Purchase</button></li>
            <li><button style="margin-bottom: 20px;" class="btn  btn-default" data-toggle="modal" data-target="#myModal">Finance</button></li>
        </ul>
    </div>
    <div class="modal fade" id="myModal" role="dialog" data-backdrop="false">
        <div class="modal-dialog">
            <!-- Modal content-->
            <div class="modal-content  theStyle">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h4 class="modal-title">The Title</h4>
                </div>
                <div class="modal-body">
                    Hello Universe
                </div>
            </div>

        </div>
    </div>
</body>
</html>

Answer №2

Perhaps this solution will assist you:

.popup {
    transform: translate(0px, 0px);
}
.popup-content {
  padding: 10px; /* <- add this */
}

Answer №3

.popup{
   right: 50%;
   bottom: 50%;
}

Include this code and delete the margin:auto property from modal-content.

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

Refusing to conceal content within Outlook email

As I work on creating a responsive email template that is compatible with Outlook, I encounter a strange issue. The HTML for Outlook displays correctly, as does the responsive HTML. However, once the email is sent to Outlook, the content becomes duplicated ...

What is the best way to calculate the total sum of the elements in an array of integers while adhering to certain restrictions using JavaScript?

I attempted to find the sum of an array's elements using a specific approach, but unfortunately, the output was undefined instead of an integer. The constraints for the array are that array.length > 0 and array[i] <= 1000. function calculateArr ...

Can these two arrays be merged together in JavaScript?

Here is the structure of the first array: [ 0:{program: id_1}, 1: {program: id_2} ] Now, let's take a look at the second array: [ 0: [ 0: {lesson: name_1}, 1: {lesson: name_2} ], 1: [ 0: {lesson: name_3} ] ] I am attempti ...

What is the most effective method to align two elements within a container in CSS? (one on the left and one on the right of the container)

I need help with positioning two colored box elements within a container using CSS. You can see my test page here: The code for the content in the center area of the website is as follows: HTML/CSS code: #header2 { background-color: #DEB887; } ...

What could be causing the page to automatically scroll to the bottom upon loading?

My experience with this bootstrap/jquery page in Firefox (v39, latest updates installed) has been unusual as it always seems to jump to the bottom of the page upon clicking. Upon inspecting the code, I couldn't find any JavaScript responsible for thi ...

Failure to Include jQuery in Header.php File

After adding the jQuery library to header.php, I encountered an issue where index.php was unable to access the library. Surprisingly, when the library was referenced directly from index.php, access to the jQuery library worked without any problems. Here i ...

Guide on querying a single document in MongoDB that contains a specific value for an element within an array of arrays

I am facing an issue with a document that has an array of arrays and is using embedded documents in MongoDB. The collection name Orders looks like this: "_id" : "HjPGrdkffg7dQPtiX", "ListOrdersResult" : [ { "Orders" : { ...

Using Vue Js directive to implement a Select2 component

I've been exploring the example of the Vue.js wrapper component and trying to customize it to use a v-select2 directive on a standard select box, rather than creating templates or components for each one. You can view my implementation in this JS Bin ...

Revealed the previously hidden private variables within the Revealing Module Pattern

I have encountered an issue while implementing the Revealing Module Pattern, as I am struggling to expose a modified private property. var myRevealingModule = (function(){ var name = 'Samantha'; function updateName () { name = ...

The Angular JS controller failing to trigger the Spring MVC function

I'm currently working on integrating Angular JS with an existing Spring MVC project and encountering an issue when calling a Spring controller from the Angular JS controller. Here is a snippet of my app.js: 'use strict'; var AdminApp = ang ...

The presence of a Bootstrap addon is resulting in horizontal scrolling on mobile devices within the webpage

I am encountering a peculiar issue with an input-group in my cshtml file which features a Bootstrap addon. The problem arises on mobile devices, where upon focusing on the input field, the page scrolls horizontally to the right, revealing the right margin ...

Transformation of Gremlin-Javascript Output to JSON Format

Looking for a solution to easily convert the output of Gremlin-Javascript into JSON format. The data seems to be in the form of a Map or multiple Maps based on the traversal. Currently, we are resorting to manually determining the type and utilizing Objec ...

Unable to showcase JavaScript outcome on the HTML page

I have been working on creating a JavaScript function to calculate the Highest Common Factor (HCF). While testing my code in the VS Code console, the correct value is displayed. However, I'm encountering an issue when trying to display the result on t ...

What is the best way to stay on track with internal anchor links when navigating with Aurelia?

I'm currently working on developing a style guide for a project and one of the features I would like to implement is a basic click behavior on anchor links, allowing them to smoothly scroll to the corresponding section on the page. For instance: < ...

Enhance your dynamic content with jQuery/AJAX through customized CSS styling

Below is the jquery (3.1.1)/ajax request that I am using: $.ajax({ type: "POST", url: "pref.php", dataType: "text", data: { groupe_id: groupe_id, action: "getProducts" }, cache: false, error: function(html){ ...

Utilizing erb within a coffeescript file for modifying the background styling

Is there a way to change the background image of a div based on user selection from a dropdown menu? For instance, if the user picks "white" the background image becomes white, and for "red" it changes to red. I'm struggling with this in coffeescript ...

How to filter an array in Angular 4 without the need for creating a new array and then displaying the filtered results within the same

In my collection of students, I have their names paired with their academic outcomes. studentResults = [ {name: 'Adam', result : 'Passed'}, {name: 'Alan', result : 'Failed'}, {name : 'Sandy', result : &ap ...

Challenges Faced when Connecting JavaScript to HTML

This is a snippet of my HTML where I link the .js file <!DOCTYPE html> <html> <head> <link rel="stylesheet" type="text/css" href="CSS/Style.css"> <title> Learning JavaScript </title& ...

Add the content script to a webpage just one time

I am looking to inject a content script on context menu click in an extension manifest version 3. I need a way to determine if the script is already injected or not. If it hasn't been injected yet, I want to inject the content script. This condition m ...

Angular Material style service

Recently, I've been tinkering with a service that allows me to alter the color scheme of my project in Angular Material. Following the official documentation, I managed to change the color successfully. However, I hit a roadblock when trying to revert ...