如何在不损坏 css 的情况下删除锚元素并用按钮替换它?

问题描述 投票:0回答:0

所以,我目前有一个 html 列表,最初是作为超链接编写的,但我想用按钮替换它们,而不会将整个 css 搞乱。我放置了一个临时按钮元素,该元素仅适用于列表元素内的选定文本,但我希望它适用于整个元素。

HTML:

<ul class="nav-list">
        <li>
          <a href="#">
            <i class="bx bx-grid-alt"></i>
            <button
              class="links_name navlist-btn-dashboard"
              onclick="displayCurrentTab('dashboard')"
            >
              Dashboard
            </button>
          </a>
          <span class="tooltip">Dashboard</span>
        </li>
</ul>

CSS:

.sidebar i {
  color: #fff;
  height: 60px;
  min-width: 50px;
  font-size: 28px;
  text-align: center;
  line-height: 60px;
}
.sidebar .nav-list {
  margin-top: 20px;
  height: 100%;
}
.sidebar li {
  position: relative;
  margin: 8px 0;
  list-style: none;
}
.sidebar li .tooltip {
  position: absolute;
  top: -20px;
  left: calc(100% + 15px);
  z-index: 3;
  background: #fff;
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.3);
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 15px;
  font-weight: 400;
  opacity: 0;
  white-space: nowrap;
  pointer-events: none;
  transition: 0s;
}
.sidebar li:hover .tooltip {
  opacity: 1;
  pointer-events: auto;
  transition: all 0.4s ease;
  top: 50%;
  transform: translateY(-50%);
}
.sidebar.open li .tooltip {
  display: none;
}
.sidebar li a {
  display: flex;
  height: 100%;
  width: 100%;
  border-radius: 12px;
  align-items: center;
  text-decoration: none;
  transition: all 0.4s ease;
  background: #11101d;
}
.sidebar li a:hover {
  background: #fff;
}
.sidebar li a .links_name {
  color: #fff;
  font-size: 15px;
  font-weight: 400;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: 0.4s;
}
.sidebar.open li a .links_name {
  opacity: 1;
  pointer-events: auto;
}
.sidebar li a:hover .links_name,
.sidebar li a:hover i {
  transition: all 0.5s ease;
  color: #11101d;
}
.sidebar li i {
  height: 50px;
  line-height: 50px;
  font-size: 18px;
  border-radius: 12px;
}

我试过每一步都插入一个按钮元素,但所有尝试都以失败告终,因为按钮元素不起作用。

html css button
© www.soinside.com 2019 - 2024. All rights reserved.