CSS positioning of a close button is vital for a seamless

My modal has a close button at the bottom, but its position seems to be shifting up and down based on the length of the comment section directly above it. I'm looking for a way to keep the close button fixed at the bottom regardless of the comment section's length. I tried using relative positioning, but I welcome any better suggestions on how to achieve this. Thank you.

View:

<div class="form-horizontal">
    <div class="modal-title title">
        <p>@ViewBag.name<span> Info</span></p>
    </div>
    <div id="info">
        <p>@Html.Label("Name: ") @ViewBag.name</p>
        <p>@Html.Label("Age: ") @ViewBag.age</p>
        <p>@Html.Label("Comment: ") @ViewBag.comment</p>
    </div>
    <div id="close">
        <div class="col-md-12">
            <input type="button" id="closeButton" value="Close" class="btn btn-default" />
        </div>
    </div>
</div>

CSS:

.btn {
    border: 2px solid transparent;
    background: white;   
    color: black;
    font-size: 16px;
    line-height: 15px;
    padding: 10px 0; 
    display: block;
    width: 150px;
    margin: 0 auto;
}
.title {
    position: relative;
    top: 20px;
}
.title p {
    text-align: center;
    font-size: 30px;
}
.title span {
    color: black;   
}
#info {    
    position: relative;     
    top: 50px;
    left: 20px;
}
#info p {
    font-size: 15px !important;
    width: 310px;
}
#close {
    position: relative;
    top: 70px;
}

Answer №1

Implemented a fixed height for the modal body to allow scrolling without affecting button position.

enter code h

<!DOCTYPE html>
<html lang="en>
<head>
  <title>Sample Bootstrap Page</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<style>
</style>
<body>

<div class="container">
  <h2>Modal Example</h2>
  <!-- Trigger the modal with a button -->
  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

  <!-- Modal -->
  <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">
    
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Modal Header</h4>
        </div>
        <div class="modal-body" style="height:200px; overflow-y:scroll;">
           <p>@Html.Label("Name: ") @ViewBag.name</p>
        <p>@Html.Label("Age: ") @ViewBag.age</p>
        <p>@Html.Label("Comment: ") @ViewBag.comment</p>
        </div>
        <div class="modal-footer">
         <input type="button" id="closeButton" value="Close" class="btn btn-default" />
        </div>
      </div>
      
    </div>
  </div>
  
</div>

</body>
</html>

ere

Answer №2

To achieve the desired effect, simply insert position: fixed and align it to the bottom.

#close {
    position: fixed;
    bottom: 0px;
    left: 50%;
}

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

Display a specific paragraph inside a div using jQuery

I am having trouble getting my jQuery code to display a specific paragraph when a particular div is clicked on. My goal is for the content "v" to be displayed if the user clicks on the ".Virus" div, and for the contents of ".screenInfo" to be shown if the ...

The art of arranging React components

I'm struggling to organize my react components properly and I'm having difficulty with CSS Flexbox. Here are the 3 react components: function App() { return ( <> <div className = "header"> <h1>Connect ...

Tips for resolving CSS issues in a vast style sheet

I'm currently facing a challenge with modifying the CSS of a Wordpress plugin I need to utilize. The learnpress.css stylesheet is very extensive, spanning over 2000 lines, making it quite complex to comprehend. All I am trying to achieve is a simple t ...

Click a button to dynamically create a div element with jQuery

Whenever I click the button to add an address, I want to dynamically create a new div structure using jQuery <div id="container"> <div class="address"> <div class="input-reg rb-item input-group"> <sp ...

Adding pictures to the background image

I am encountering an issue with the code on my Wordpress website Here is a snippet of HTML: <div class="test"> <?php if(has_category( 'update' ) || has_category( 'uncategorized' )) { ?> <img alt="icn" src="& ...

Dealing with full-width elements on mobile devices

I've got a pretty basic question here but can't seem to find a straightforward answer. I'm using Bootstrap to style a website and struggling with making it mobile-responsive. Following the given answer, I used this code to show a button ne ...

Ensure that the text stays aligned at the center within an `<li>` tag, especially when there is an image along with the text within the element

I have a basic list structured like this: <ul> <li>ONE</li> <li>TWO</li> <li>THREE</li> <li>FOUR</li> <li>FIVE</li> <li>SIX</li> <li><hr&g ...

In Stripe.js, the background color and height of the credit card input cannot be customized

I'm struggling with customizing the appearance of a Stripe credit card input within my Vue.js application. I want to adjust the background color to #f1f1f1 and set the height to 60px, but despite trying both base styles and css, I can't seem to g ...

Leveraging the power of AJAX, PHP, and JavaScript to display numerous status updates throughout an extended operation

It has come to my understanding that when using PHP, it is not feasible to send messages to the DOM using AJAX as the entire script must finish executing before the response becomes available. This leaves me with two possible solutions: Break down the le ...

Styling Icons for Tabs in Material UI

I am dynamically using these tabs: <Tabs value={value} onChange={handleChange} variant="scrollable" scrollButtons="off" indicatorColor="primary" textColor="pr ...

AngularJS - creating a dropdown style that will reset the route

I'm having trouble with my AngularJS spa page and the main navigation dropdown link. When I click on the dropdown, the content inside ng-view disappears. It seems like the angular route is getting confused by the '#' in the href. How can I s ...

Issue of scrolling on Firefox 3.6 due to CSS page width set to 100%

Strange issue with my website on Firefox 3.6 - there is an unwanted horizontal scroll bar at the bottom even though nothing exceeds 100% of the body width. This problem does not occur in Chrome, Safari, or Firefox 4... Any suggestions? Check out the li ...

``There seems to be a malfunction with the modal feature in the asp.net

Within my strongly typed view, I have a loop that iterates over a list of objects fetched from a database. Each object is displayed within a jumbotron element, accompanied by a button labeled "Had role before". When this button is clicked, a modal opens wh ...

Will refreshing a browser's software automatically delete the cache?

When the browser's software is updated, what happens to the cache? For instance, let's say I have some code hosted on a third-party website that includes an embedded logo image. If the host updates the logo and I clear the cache, the new logo wi ...

Increasing the maximum width of an image in CSS is necessary to see the max-height take effect

Within my HTML structure: <Col md="6"> <div className="hero-section"> <div className={`flipper ${isFlipping ? "isFlipping" : ""}`}> <div className="front"> <div className="hero-section-content"> ...

Adjust the left and right margins while maintaining the vertical margin spacing

Is there a way to apply horizontal margin while inheriting vertical margin without explicitly setting margin-left and margin-right? I was hoping for something like margin: inherit 20px; to be effective. Take a look at the example here: https://jsfiddle.ne ...

Managing scroll position based on media queries in JavaScript

I'm currently working on implementing a fade-in/out effect on scroll for a web project. In my JavaScript code, I need to specify a certain value for the scroll position, such as an offset, to trigger the effect. The issue: The offset value may not ...

Are there any inventive methods to dynamically populate HTML content directly from a URL?

My objective is not to avoid incorporating code (such as JavaScript) here, but rather to create a specific tool. Imagine I have a URL string like domain.com/something, which can produce either a single string like "John", or potentially JSON data dependin ...

Ways to initiate a flip motion

Looking for a way to create a flip image effect when clicked by the user. Here is the code I have so far: let img = document.querySelector('img') let div; let click = 0; img.onclick=function(){ console.log(click) if(click %2 ==0){ d ...

The issue of the background image not expanding to cover the entire page when resized is problematic

Hello there, I'm currently working on making my website responsive and I've run into a problem with GIF images. No matter what I do, they just won't fill the entire page. When I try to make them smaller, it leaves white spaces at the top and ...