我有一个代码,我需要将"a"标签更改为"li"。当我这样做时,css动画停止工作



我想将 (a( 标签更改为 (li(。当我这样做时,css 动画停止工作。为什么?这不是我第一次将 (a( 标签更改为 (li(,但我从来没有遇到过这样的问题。当然,您需要在css中进行操作,但是这次我无法解决此问题。如何更改它?

<div class="panel" id="slice">
   <div class="panel__content">
     <a href="#home">Close me.</a>
   </div>
</div>
<div class="menu">
 <a class="menu__link" href="#slice" data-hover="Slice">Slice</a>
</div>
     .menu {
     position: fixed;
     width: 100vw;
     pointer-events: none;
     margin-top: 10vh;
     text-align: center;
     z-index: 2; }
    .menu__link {
     display: inline-block;
     text-decoration: none;
     border: 2px solid #263238;
     color: #263238; 
     pointer-events: auto;
     line-height: 40px; 
     position: relative;
     padding: 0 50px; 
     box-sizing: border-box;
     margin: 0;
     user-select: none;
     overflow: hidden;
     border-radius: 50px;
     .panel {
     display: flex;
     align-items: center;
     justify-content: center;
     flex-direction: column;
     position: absolute;
     top: 0;
     bottom: 0;
     left: 0;
     right: 0;
      overflow: auto;
     z-index: 999;
     color: #000;
     box-sizing: border-box;
     background-color: #ECEFF1; }
    .panel__content {
    opacity: 0;
    will-change: margin-top;
    transition: all 700ms; 
    transition-delay: 600ms;
    padding: 100px 200px;
    margin-top: -5%; }
    .panel:target .panel__content {
    opacity: 1;
    margin-top: 0; }
    .panel#slice {
    background-color: #E53935;
    transition: all 800ms cubic-bezier(0.190, 1.000, 0.560, 1.000);
    transform: translate3d( 0, -100%, 0 ); }
    .panel#slice:target {
    transform: translate3d( 0, 0, 0 ); }

您必须重新设置无序列表的间距样式,但也许不是直接用<li>替换菜单的<a>元素,而是可以在生成的列表项中包含<a>元素。

这将保留所有:target功能并为您提供列表(用于语义?

编辑:当然,如果您的菜单只能包含<li>,这根本行不通。

/* basic style definition */
/* •••••••••••••••••••••••••••••••• */
body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-family: 'Roboto Slab', serif;
}
h1 {
  margin: 0;
  user-select: none;
  text-align: center;
  font-weight: 300;
}
p,
{
  font-weight: 300;
  color: #546E7A;
  user-select: none;
  text-align: center;
  margin: 0;
}
a {
  text-align: center;
  text-decoration: none;
  color: #FFF;
}
/* Navigation menu */
/* •••••••••••••••••••••••••••••••• */
.menu {
  position: fixed;
  width: 100vw;
  pointer-events: none;
  margin-top: 10vh;
  text-align: center;
  z-index: 2;
}
/* Menu link item */
.menu__link {
  display: inline-block;
  text-decoration: none;
  border: 2px solid #263238;
  color: #263238;
  pointer-events: auto;
  line-height: 40px;
  position: relative;
  padding: 0 50px;
  box-sizing: border-box;
  margin: 0;
  user-select: none;
  overflow: hidden;
  border-radius: 50px;
  &::before {
    content: attr(data-hover);
    background-color: #263238;
    color: #FFF;
    position: absolute;
    top: 100%;
    bottom: 0;
    left: 0;
    transition: all 300ms cubic-bezier(0.190, 1.000, 0.560, 1.000);
    right: 0;
  }
  &:hover::before {
    top: 0;
  }
}
/* Panels Style*/
/* •••••••••••••••••••••••••••••••• */
/* Common panel style */
.panel {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  overflow: auto;
  z-index: 999;
  color: #000;
  box-sizing: border-box;
  background-color: #ECEFF1;
}
/* panel content (only for animation delay after open) */
.panel__content {
  opacity: 0;
  will-change: margin-top;
  transition: all 700ms;
  transition-delay: 600ms;
  padding: 100px 200px;
  margin-top: -5%;
}
/* Panel content animation after open */
.panel:target .panel__content {
  opacity: 1;
  margin-top: 0;
}
/*  Specific "Home "panel */
/* •••••••••••••••••••••••••••••••• */
.panel#home {
  z-index: 1;
  background: radial-gradient(ellipse at center, rgba(255, 255, 255, 1) 0%, #CFD8DC 100%);
}
/*  Specific panel "Slice" */
/* •••••••••••••••••••••••••••••••• */
.panel#slice {
  background-color: #E53935;
  transition: all 800ms cubic-bezier(0.190, 1.000, 0.560, 1.000);
  transform: translate3d( 0, -100%, 0);
}
.panel#slice:target {
  transform: translate3d( 0, 0, 0);
}
/*  Specific panel "Fade" effect */
/* •••••••••••••••••••••••••••••••• */
.panel#fade {
  background-color: #00C853;
  opacity: 0;
  transition: all 800ms;
  pointer-events: none;
}
.panel#fade:target {
  opacity: 1;
  pointer-events: auto;
}
<!-- Home Panel  -->
<div class="panel" id="home">
  <h1>Pure CSS panels</h1>
  <p>by Mattia Astorino</p>
</div>
<div class="panel" id="slice">
  <div class="panel__content">
    <a href="#home">
            Close me.
        </a>
  </div>
</div>
<div class="panel" id="fade">
  <div class="panel__content">
    <a href="#home">Close me.</a>
  </div>
</div>
<!-- Navigation -->
<div class="menu">
  <ul>
    <li>
      <a class="menu__link" href="#slice" data-hover="Slice">Slice</a>
    </li>
    <li>
      <a class="menu__link" href="#fade" data-hover="Fade">Fade</a>
    </li>
  </ul>
</div>

最新更新