【问题标题】:Modal displaying behind datatable数据表后面的模态显示
【发布时间】:2015-08-05 15:10:04
【问题描述】:

查看编辑:

我有一个模式,我试图循环并在每次循环中显示。到目前为止,我有以下代码,我试图让模式在按钮单击时显示。到目前为止,它还没有作为模式,而是显示在按钮的正下方。我觉得我可能缺少 javascript,但我似乎无法在网上找到合适的东西来使用。我认为这可能很容易,我只是错过了一些东西。任何帮助都会很棒,我还是新手!谢谢!

  <label class="btn" for="modal-x">Add Map</label>

  <input class="modal-state" id="modal-x" type="checkbox" />
    <div class="modal">
      <label class="modal__bg" for="modal-x"></label>
      <div class="modal__inner">
        <label class="modal__close" for="modal-x"></label>
        <h1>Add Mapfile</h1>
        <%= form_for(@posts, multipart: true) do |f| %>
          <div class="field">
            <%= f.hidden_field :location_id, :value => @location.id%>
          </div>
          <div class="field">
            <%= f.file_field :mapfile %>
          </div>
          <p></p>
          <div class="actions" id="submit-map">
            <%= f.submit 'Submit' %>
          </div>
        <%end %>
      </div>
    </div>

编辑: 我已经想出了如何让模态工作,但现在它显示在我正在使用的数据表后面,而不是在它上面/前面。是否有我可以更改的属性将模态带到最前面?

这是我的 CSS:

.modal {
  opacity: 0;
  visibility: hidden;  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  text-align: left;
  background: rgba(0,0,0, .9);
  transition: opacity .25s ease;
}

.modal__bg {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  cursor: pointer;
}

.modal-state {
  display: none;
}

.modal-state:checked + .modal {
  opacity: 1;
  visibility: visible;
}

.modal-state:checked + .modal .modal__inner {
  top: 0;
}

.modal__inner {
  transition: top .25s ease;
  position: absolute;
  top: -20%;
  right: 0;
  bottom: 0;
  left: 0;
  width: 50%;
  margin: auto;
  overflow: auto;
  background: #fff;
  border-radius: 5px;
  padding: 1em 2em;
  height: 50%;
}

.modal__close {
  position: absolute;
  right: 1em;
  top: 1em;
  width: 1.1em;
  height: 1.1em;
  cursor: pointer;
}

.modal__close:after,
.modal__close:before {
  content: '';
  position: absolute;
  width: 2px;
  height: 1.5em;
  background: #ccc;
  display: block;
  transform: rotate(45deg);
  left: 50%;
  margin: -3px 0 0 -1px;
  top: 0;
}

.modal__close:hover:after,
.modal__close:hover:before {
  background: #aaa;
}

.modal__close:before {
  transform: rotate(-45deg);
}

@media screen and (max-width: 768px) {

  .modal__inner {
    width: 90%;
    height: 90%;
    box-sizing: border-box;
  }
}

【问题讨论】:

  • 尝试将class="modal fade"更改为class="modal hide fade"
  • 如果你想访问大量现成的模态功能,那么你可以使用bootstrap:getbootstrap.com/javascript
  • @MaxWilliams 尽可能避免引导
  • @Pavan 运气不好

标签: javascript jquery html ruby-on-rails modal-dialog


【解决方案1】:

将您的 div 模态包装在另一个 div 中,否则循环中的其他按钮将不会出现。

确保加载引导 css 和引导 js。

在你的 gem 文件中有这个。

gem 'bootstrap-sass', '~> 3.3.5'

在你的 application.css 中

@import "bootstrap-sprockets";
@import "bootstrap";

你的 application.js 应该是这样的

//= require jquery
//= require jquery_ujs
//= require bootstrap-sprockets
//= require turbolinks
//= require_tree .

试试这个并重新启动服务器。

【讨论】:

  • 我试过了,按钮仍然显示,但模式不在屏幕上,这很好,但是当我点击按钮时没有任何反应。另外,我不想使用引导程序,我已经更改了按钮 ID
  • 你加载了 bootstrap js?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-19
  • 1970-01-01
  • 2014-09-30
  • 1970-01-01
  • 2016-05-04
  • 1970-01-01
相关资源
最近更新 更多