【问题标题】:Bootstrap 3 modal dialogs and meteorBootstrap 3 模态对话框和流星
【发布时间】:2013-10-25 17:44:43
【问题描述】:

我对 bootstrap 很陌生,所以请温柔一点。我正在尝试让一个模式对话框与流星一起显示并且有一些方法,但我真的坚持它的显示方式和位置。

我有两个用于对话框本身的模板(如此处其他地方所建议的那样)

<template name="projectPage">                                                                             

<div class="container">                                                                                   
  <h2>Example of creating Modals with Twitter Bootstrap</h2>                                              
  <div id="example" class="modal fade in show" role="dialog" tabindex="-1" aria-hidden="true">            
    {{> modalInner}}                                                                                      
  </div>                                                                                                  
</div>>                                                                                                   
</template>                                                                                               

<template name="modalInner">                                                                              
<div class="modal-header">                                                                                
  <a class="close" data-dismiss="modal">×</a>                                                             
  <h3>This is a Modal Heading</h3>                                                                        
</div>                                                                                                    
<div class="modal-body" >                                                                                 
  <h4>Text in a modal</h4>                                                                                
  <p>You can add some text here.</p>                                                                      
</div>                                                                                                    
<div class="modal-footer">                                                                                
  <a href="#" class="btn btn-success">Call to action</a>                                                  
  <a href="#" class="btn" data-dismiss="modal">Close</a>                                                  
</div>                                                                                                    
</template> 

使用此代码,模板被渲染,但有一个不透明的背景,因此只是混杂在它下面已经渲染的内容中(它也是全屏而不是示例显示的大小)。

我尝试更改背景以查看 css 发生了什么

.modal {
  //background-color: #f00;                                                                               
  max-width: 50%;                                                                                         
  max-height: 50%;                                                                                        
  //position: relative;                                                                                   
}

并且,如您所见,手动设置了宽度和高度,但这给了我页面左上角的一个红色框,右侧下方有一个空滚动条,但又不是什么示例显示。

有什么想法我在这里出错了吗?

彼得。

【问题讨论】:

    标签: css twitter-bootstrap meteor


    【解决方案1】:

    答案是我缺少两个 div 来让事情开心。

    我需要一个

    <div class="modal-dialog"> 
    <div class="modal-content">
    

    使代码弹出模式对话框。完整的测试代码是

    <template name="projectPage">                                                                                 
    <div class="container">                                                                                   
      <div class="well">
      <h2>Example of creating Modals with Twitter Bootstrap</h2> 
      <a data-toggle="modal" href="#myModal" >My Modal</a>                                                                                                                                                               
    </div>
    </div>
    {{>myModal}}                                                                                                  
    </template>                                                                                               
    
    <template name="myModal">                                                                                 
    <!-- 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">                                                                                
      <a class="close" data-dismiss="modal">×</a>                                                             
      <h3>This is a Modal Heading</h3>                                                                        
    </div>                                                                                                    
    <div class="modal-body" >                                                                                 
      <h4>Text in a modal</h4>                                                                                
      <p>You can add some text here.</p>                                                                      
    </div>                                                                                                    
    <div class="modal-footer">                                                                                
      <a href="#" class="btn btn-success">Call to action</a>                                                  
      <a href="#" class="btn" data-dismiss="modal">Close</a>                                                  
    </div>  
    </div>
    </div>
    </div>
    

    感谢 youtube 视频(Bootstrap 3 教程 - #6 - 模态(弹出框))将其放在路径上...(由于某种原因无法在此处嵌入链接)。

    感谢各位的帮助。彼得

    【讨论】:

      【解决方案2】:

      尝试将整个模态作为模板,而不仅仅是内部。比如:

      <template name="projectPage">                                                                                 
      <div class="container">                                                                                   
        <h2>Example of creating Modals with Twitter Bootstrap</h2> 
        <a data-toggle="modal" href="#myModal" >My Modal</a>                                                                                                                                              
      </div>
      {{>myModal}}                                                                                                  
      </template> 
      
      <template name="myModal">
      <!-- Modal -->
      <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
       <div class="modal-header">                                                                                
        <a class="close" data-dismiss="modal">×</a>                                                             
        <h3>This is a Modal Heading</h3>                                                                        
      </div>                                                                                                    
      <div class="modal-body" >                                                                                 
        <h4>Text in a modal</h4>                                                                                
        <p>You can add some text here.</p>                                                                      
      </div>                                                                                                    
      <div class="modal-footer">                                                                                
        <a href="#" class="btn btn-success">Call to action</a>                                                  
        <a href="#" class="btn" data-dismiss="modal">Close</a>                                                  
      </div>  
      </div><!-- /.modal -->
      </template>
      

      【讨论】:

      • 感谢土地的输入。不幸的是,这段代码显示了完全相同的行为。生成的模态对话框占据了整个页面。
      • 您是否尝试删除您添加的 css?你也有任何可能与 css 混淆的包或库吗?这看起来不错,我在流星中没有遇到任何问题,尽管我以前因为其他库而遇到过模态问题。
      • 是的,不幸的是,我确实摆脱了 css 并没有什么不同。我在这个项目中安装了 bootsrap-3、iron-router 和角色。据我所知,我没有使用任何其他库(但可能是非常新的)。
      【解决方案3】:

      你是怎么开始的?

      我做了以下,没有任何问题:

      meteor create bootstrap
      mrt add bootstrap
      
      <head>
        <title>Bootstrap Modal</title>
      </head>
      
      <body>
      <br />
          <div class="container">
          <div class="well">
          {{> projectPage}}
          </div>
          </div>
      </body>
      
      <template name="projectPage">                                                                             
      
      <div class="container">                                                                                   
        <h2>Example of creating Modals with Twitter Bootstrap</h2>                                              
        <div id="example" class="modal fade in show" role="dialog" tabindex="-1" aria-hidden="true">            
          {{> modalInner}}                                                                                      
        </div>                                                                                                  
      </div>>                                                                                                   
      </template>                                                                                               
      
      <template name="modalInner">                                                                              
      <div class="modal-header">                                                                                
        <a class="close" data-dismiss="modal">×</a>                                                             
        <h3>This is a Modal Heading</h3>                                                                        
      </div>                                                                                                    
      <div class="modal-body" >                                                                                 
        <h4>Text in a modal</h4>                                                                                
        <p>You can add some text here.</p>                                                                      
      </div>                                                                                                    
      <div class="modal-footer">                                                                                
        <a href="#" class="btn btn-success">Call to action</a>                                                  
        <a href="#" class="btn" data-dismiss="modal">Close</a>                                                  
      </div>                                                                                                    
      </template> 
      

      您使用的是引导程序 2.3 吗?还是引导程序 3?

      【讨论】:

      • 嗨 Varun,我正在使用 bootstrap 3(bootstrap-3 软件包)。
      • 看起来一定是 boostrap-3 问题。上面的代码,但使用 mrt add bootsrap-3 而不是 bootstrap 完成,产生了我在我的应用程序中得到的确切效果。覆盖在整个页面上。
      • 如果我将 id div 的类更改为弹出而不是模式,我得到的东西接近我所追求的(它现在不覆盖整个页面)但它替换了页面在下面而不是在上面显示(如果有意义的话)。
      猜你喜欢
      • 2013-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-10
      相关资源
      最近更新 更多