【发布时间】: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