Bootstrap 无法在引导模式全屏中将页脚保持在底部

xa9qqrwz  于 2023-05-27  发布在  Bootstrap
关注(0)|答案(4)|浏览(180)

我试着把bootstrap modal的页脚放在底部,但我做不到,这是我的html结构:

<!-- Button trigger modal -->
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  Launch demo modal
</button>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

基本上我想显示在全屏模式模态,这工作很好,但页脚不去底部。
CSS:

.modal-dialog {
 width: 100%;
  height: 100%;
  padding: 0;
}

.modal-content {
  height: 100%;
  border-radius: 0;
}

我创建了一个jsfiddle来解释这种情况:
http://jsfiddle.net/8XdVt/?utm_source=website&utm_medium=embed&utm_campaign=8XdVt

http://jsfiddle.net/8XdVt/show/

rxztt3cl

rxztt3cl1#

你可以给予model-content一个相对位置,modal-footer的绝对位置,bottom为0 px;
试试用

.modal-content {
  height: 100%;
  border-radius: 0;
  position:relative;
}

.modal-footer {
  border-radius: 0;
  bottom:0px;
  position:absolute;
  width:100%;
}

小提琴:http://jsfiddle.net/1fh2n5y3/

dddzy1tm

dddzy1tm2#

一切正常,我的朋友。
Jsfiddle

.modal-dialog {
  width: 100%;
  height: 100%;
  padding: 0;
}

.modal-content {
  height: 100%;
  border-radius: 0;
}

.modal-footer {
  position: absolute;
  bottom: 0;
  width: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"/>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<!-- Button trigger modal -->
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  Launch demo modal
</button>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>
zd287kbt

zd287kbt3#

将这几行添加到模式页脚Fiddle默认情况下,模式内容具有位置相对性。我使用!important来在类modal-dialog上否决css。如果你有separet css文件,那么你不需要使用!很重要

.modal-dialog {

  width:100% !important;
  height: 100%;
  margin: 0 auto !important;
  padding:20px 20px;
}

.modal-content {
  height: 100%;
  border-radius: 0;
}

.modal-footer{
position:absolute;
bottom:0;
width:100%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script
  src="https://code.jquery.com/jquery-3.1.1.min.js"
  integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
  crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<!-- Button trigger modal -->
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  Launch demo modal
</button>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>
am46iovg

am46iovg4#

如果您使用angular和ngbootstrap库并使用

ngbModal.open(MyComponent);

你可以把它放在你的组件里

@HostBinding('class') class = 'd-flex flex-column h-100';

并将modal-body或flex下的其他元素设置为flex-grow-1

相关问题