html - 不显示模态消息

标签 html css modal-dialog simplemodal

我试图在用户单击仅使用 css 的按钮时显示模态消息。当我尝试将此按钮添加到一个部门时,该按钮不再起作用。为什么?

$colore = #2767ce

html, body {
  width: 100%;
  height: 100%;
  text-align: center;
  float: center;
}

.box {
  width: 220px;
  float: center;
  text-align: center;
  margin: 0 auto;
  margin-right: 10px;
  margin-left: 10px;
  border: 3px solid $colore;
  padding: 10px;
}

.box p {
  font-family: sans-serif;
  font-size: 15px;
  margin-bottom: 40px;
  margin-top: 40px;
}
  
.scopri {
  display: block;
  padding: 1em 2em;
  background: $colore;
  color: #fff;
  border: 3px solid $colore;
  outline: 0;
  float: center;
  margin: 0 auto;
  text-transform: uppercase;
  cursor: pointer;
  transition: .6s ease;
  -webkit-appearance: none;
  
  &:hover {
    background: white;
    color: $colore;
    border: 3px solid $colore;
  }
  }
  
.modalita {
  opacity: 0;
  visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.7);
  transition: .3s ease-in-out;
  
  &_box {
    padding: 1em;
    background: white;
    box-shadow: 0 0 10px 0 rgba(0,0,0,0.2);
    text-align: center;
    transition: all .3s cubic-bezier(.20,.90,.30,1.5);
    transform: rotate(5deg) translate(-1em,1em);
    border-top: 5px solid $colore;
    border-bottom: 5px solid #ddd;
  }
}
  
/* modal magic */
.scopri:focus + .modalita {
  opacity: 1;
  visibility: visible;
}
  
  .modalita_box {
    transform: rotate(0deg) translate(0,0);
  }
<div class="box">
  <h2>HUB</h2>
  <p>test</p>
<button class="scopri"> more </button>
</div>

<div class="modalita">
  <div class="modalita_box">
    <p> try </p>
  </div>
</div>

PS:如果您尝试删除除法,它会起作用,但我不知道为什么!

最佳答案

在这种情况下使用伪类,modalita 需要是具有伪类(在这种情况下为 scopri)的元素的直接或间接兄弟。那是因为 CSS 子级/兄弟级选择器相当严格。

你可以这样使用它:

<div class="box">
    <h2>HUB</h2>
    <p>test</p>
<button class="scopri"> more </button>

<div class="modalita">
    <div class="modalita_box">
        <p> try </p>
    </div>
</div>

</div> <!-- closing .box -->

关于html - 不显示模态消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44490306/

相关文章:

文本自动换行后的 HTML/CSS 背景颜色

html - 如何垂直对齐div

javascript - JS组件可以继承CSS样式吗?

没有 jquery 的 style\classes 的 jquery 对话框

cocoa - 模态表和模态返回值

javascript - CSS模态跳到底部

html - Flex 容器上的 Div 类?

html - 背景不在屏幕区域之外

css - 导航菜单在 ie7 中隐藏在 div 后面,但在 ie8 中有效

javascript - 设置CSS的背景图片:before tag programatically