不要显示模态消息

时间:2017-06-12 01:38:21

标签: html css modal-dialog simplemodal

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



Posted on <span style="font-style: italic;">
          <time datetime="<?php strftime(date('Y-m-d', strtotime($posts->Time)));?>" 
    title="<?php strftime(date( 'Y', strtotime($posts->Time)) == date('Y') ? TIMEBEFORE_FORMAT : TIMEBEFORE_FORMAT_YEAR,strtotime($posts->Time))?>">
    <?php echo time_ago($posts->Time);?>
    </time>
&#13;
$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);
  }
&#13;
&#13;
&#13;

PS:如果你试图删除它的分裂它可以工作,但我不知道为什么!

2 个答案:

答案 0 :(得分:1)

+中使用的.scopri:focus + .modalita {符号是Adjacent sibling selector,只能应用于兄弟元素。

.scopri按钮嵌套在.box div中,因此.scopri.modalita不是兄弟姐妹。

如果您将.scopri按钮移到.box div之外,请执行以下操作:

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

然后你的代码应该按照预期的那样工作。

答案 1 :(得分:1)

在这种情况下使用伪类,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 -->