关闭按钮css位置

时间:2016-09-14 18:54:33

标签: css asp.net-mvc

我的模态底部有一个关闭按钮。看起来它正在上下移动取决于评论部分在顶部的时间长短。无论评论部分有多长,我都试图将它的位置固定在底部。所以我使用了 relative ,但如果你们有更好的想法解决这个问题,我将不胜感激。感谢。

查看:

(function() {
"use strict";
$('form#ajax').on('submit', function() {
    var that = $(this),
        url  = that.attr('action'),
        type = that.attr('method'),
        data = {};
    that.find('[name]').each(function(index, value) {
        var that   = $(this),
            name   = that.attr('name'),
            value  = that.val();
        data[name] = value;
    });
$.ajax({
    url: url,
    type: type,
    data: data,
    success: function(response) {
        $('#display').html(response).delay(8000).fadeOut(1000);
    }
  });
return false;

CSS:

<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>

2 个答案:

答案 0 :(得分:2)

刚刚给模态体提供了固定的高度,这样就可以在不改变按钮位置的情况下滚动身体

enter code h

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</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

答案 1 :(得分:0)

只需添加位置:固定并将其下沉到底部,如果这就是你想要的。

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