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

标签 html 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 ); }

最佳答案

您必须重新设置无序列表的样式以获得间距,但也许不是完全替换菜单的 <a>带有 <li> 的元素, 你可以包括 <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>

关于html - 我有一个代码,我需要将 "a"标签更改为 "li"。当我这样做时,CSS 动画停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56623610/

相关文章:

html - 理解css textarea偏移量

html - 如何移动边框底部,使其开始超过文本?

html - 选项卡式导航中 ^ 选择器的含义

php - 在数组中协商数组

css - 为什么行距不一样?

html - 无论浏览器的字体如何,如何拥有固定的字体大小?

html - 带有图像的响应式 div

jquery - 如何在javascript中为菜单添加图片

javascript - Bootstrap - 如何在 JavaScript 中动态添加 <select class ="form-control">?

jquery - 单击子菜单时将 WordPress 菜单设置为事件状态