html - 如何将 html 复选框变成图标

标签 html css

我想使用 HTML 和 CSS,不使用 JavaScript。所以我放了一个 input type="checkbox" , 写 ul列出,让它变得漂亮漂亮,我就完成了。现在,我还必须至少使用一个 FontAwesome 图标,嘿,显然是每个人都使用的 3 个栏,而不是旧的丑陋的复选框,对吧?我以为我可以写 <label for="menu_button" class="fas fa-bars (the icon class)"></label>并完成它,但当然即使它在那里,它也没有做任何事情,而且......好吧,我不知道该怎么做。

.menu_items {
  max-height: 0px;
  font-family: "IBM Plex Mono";
  font-size: 16px;
  color: #ffffff;
  letter-spacing: 0;
  line-height: 28px;
  background-color: #0000EC;
  list-style-type: none;
}

.menu_button:checked~.menu_items {
  max-height: 224px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.min.css" rel="stylesheet" />

<div id="navbar">
  <img src="./images/logo.svg" alt="logo">
  <div class="hamburger-menu">
    <input type="checkbox" class="menu_button">
    <label for="menu_button" class="fas fa-bars"></label>
    <ul class="menu_items">
      <li href="#episodios">EPISODIOS</li>
      <li href="#nosotros">NOSOTROS</li>
      <li href="#entrevistas">ENTREVISTAS</li>
      <li href="#topicos">TÓPICOS</li>
    </ul>
  </div>
</div>

最佳答案

input 可以通过 idfor 属性链接到 label,而不是 属性;)。它可以随心所欲地隐藏起来。

例子

.menu_items {
  max-height: 0px;
  font-family: "IBM Plex Mono";
  font-size: 16px;
  color: #ffffff;
  letter-spacing: 0;
  line-height: 28px;
  background-color: #0000EC;
  list-style-type: none;
  transition:0.2s;
}

#burger:checked~.menu_items {
  max-height: 224px;
}
#burger {position:absolute;right:100vw;}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.min.css" rel="stylesheet" />

<div id="navbar">
  <img src="./images/logo.svg" alt="logo">
  <div class="hamburger-menu">
    <input type="checkbox" class="menu_button" id="burger">
    <label for="burger" class="fas fa-bars"></label>
    <ul class="menu_items">
      <li href="#episodios">EPISODIOS</li>
      <li href="#nosotros">NOSOTROS</li>
      <li href="#entrevistas">ENTREVISTAS</li>
      <li href="#topicos">TÓPICOS</li>
    </ul>
  </div>
</div>

关于html - 如何将 html 复选框变成图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59556704/

相关文章:

html - 如何避免大量 @import CSS 但无法在一个巨大的 CSS 文件中工作

html - 响应式设计 : Float text over image

jquery - QTip2 工具提示的提示位置不正确

javascript - 在切换时反转多个 CSS 关键帧动画

html - 这个导航可以完全用CSS完成吗

javascript - 为什么在我使用 getElementById Removed Script for other ID 时附加主体 div 被删除

javascript - 是否可以使用 ICE 直接连接,然后在 WebRTC 中直接进行点对点信令?

python - table-striped 类没有给我替代颜色

php - 在索引页上从数据库中调用图像

CSS - 淡入淡出动画 - 元素显示然后做动画