简体   繁体   English

模态显示在数据表后面

[英]Modal displaying behind datatable

SEE EDIT: 查看编辑:

I have a modal which I'm trying to loop through and display each time in a loop. 我有一个模态,我试图遍历并在每次循环中显示。 I have the following code so far, I am attempting to get the modal to display on a button click. 到目前为止,我有以下代码,我正在尝试使模式显示在按钮单击上。 So far it does not act as a modal and instead is displayed right under the button. 到目前为止,它还不充当模式,而是显示在按钮正下方。 I feel like I am probably missing javascript but I can't seem to find the right thing online to use. 我觉得我可能缺少javascript,但似乎找不到在线使用的正确东西。 I think this is probably pretty easy and I'm just missing something. 我认为这可能很容易,而且我只是想念一些东西。 Any help would be great, I'm still new to this! 任何帮助都会很棒,我仍然是新来的! Thank you! 谢谢!

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

EDIT : I have figured out how to get the modal working, but now it displays behind the datatable I am using, rather than over it/in front of it. 编辑 :我已经想出了如何使模态工作,但现在它显示在我正在使用的数据表的后面,而不是在它上面/前面。 Is there a property I can change that will bring the modal to the front? 是否有我可以更改的属性,可以使模式出现在最前面?

Here is my css: 这是我的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;
  }
}

Wrapp your div modal inside another div otherwise the other buttons in the loop will not appear. 将您的div模态包装到另一个div中,否则循环中的其他按钮将不会出现。

Make sure load the bootstrap css and bootstrap js. 确保加载引导css和引导js。

In your gem file have this. 在您的gem文件中有这个。

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

And in your application.css 并在您的application.css中

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

And your application.js should see like this 而且您的application.js应该看起来像这样

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

Try this and restart the server. 试试这个,然后重新启动服务器。

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

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