繁体   English   中英

Bootstrap:仅将div用作XS屏幕的模态?

[英]Bootstrap: Use div as modal only for xs screens?

我在小屏幕上方有两列Bootstrap布局。 对于超小型类,我想从常规流程中隐藏第二列, 而将其用作模式的内容

是否可以用一种优雅的方式来实现(即,无需使用Javascript在DOM中移动它)?

例:

<div class="row">
    <!-- Main Column -->
    <div class="col-sm-8 col-md-9">
        Main contents blah blah blah
    </div>
    <!-- Secondary Column -->
    <div class="col-sm-4 col-md-3">
        Other contents. These appear normally in sm, md, lg. In xs, it should be the contents of a modal.
    </div>
</div>

示例模式(应在其中显示第二列):

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        This is where I want the contents from the secondary column
      </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>

是的,您可以通过使用jQuery的$.html()函数获取列的html,然后再次使用$.html()将其放在模式中来实现。 结合阿卜杜拉的建议,应该可以为您提供所需的服务。 这是我创建的一个演示:

 $("#myModalBtn").click(function() { $("#myModal .modal-body").html($("#myModalContent").html()); $("#myModal").modal("show"); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <div class="container"> <div class="row"> <!-- Main Column --> <div class="col-sm-8 col-md-9"> Main contents blah blah blah <button type="button" class="btn btn-primary visible-xs" id="myModalBtn">Launch demo modal</button> </div> <!-- Secondary Column --> <div class="col-sm-4 col-md-3 hidden-xs" id="myModalContent"> Other contents. These appear normally in sm, md, lg. In xs, it should be the contents of a modal. </div> </div> </div> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> <h4 class="modal-title" id="myModalLabel">Modal title</h4> </div> <div class="modal-body"> This is where I want the contents from the secondary column </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> 

单击“ 运行代码段”,然后单击“整页”链接以查看其运行情况。

在Bootstrap中使用hidden-属性。

  1. Hidden-xs-隐藏在特小
  2. 隐藏的sm-小隐藏
  3. Hidden-md-隐藏在特小
  4. 等..

选中此响应实用程序

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM