Home > Mobile >  Dropdown menu html css without JavaScript
Dropdown menu html css without JavaScript

Time:01-26

Hello could someone please tell me why my menu does not go from page to page. Dropdown works but when I click it doesn't go to the subpage. Anticipating the question, I don't want to use JavaScript. Buttons without dropdown menu works. If this cannot be fixed, could someone sent me a menu in similar style without JavaScript.

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background-color: #333;
}

hr {
  border-top: 2px dashed white;
  border-bottom: none;
}

a {
  text-decoration: none;
  color: black;
}

.center {
  display: block;
  margin-left: auto;
  margin-right: auto;
}

.navbar {
  height: 6vh;
  display: flex;
  justify-content: space-around;
  align-items: center;
  width: 60%;
  margin: auto;
}

.dropdown {
  position: relative;
}

.dropdown ul {
  position: absolute;
  background: #bebebe;
  margin-top: 10px;
  width: 200px;
  height: 200px;
  display: flex;
  justify-content: space-around;
  align-items: center;
  flex-direction: column;
  list-style: none;
  border-radius: 5px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-10px);
  transition: all 0.6s ease;
  left: 0px;
}

.dropdown li {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.dropdown li:hover {
  background-color: darkslategray;
}

.navbar button,
.deco {
  background: none;
  border: none;
  color: black;
  text-decoration: none;
  font-size: 18px;
  cursor: pointer;
}

.navbar button:hover,
.deco:hover {
  color: darkslategray;
}

.dropdown button:focus ul {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0px);
}

.top {
  text-decoration: none;
  background: yellow;
  border: none;
  color: black;
  font-size: 48px;
  cursor: pointer;
  border-radius: 5px;
  width: 45px;
  height: 45px;
  align-items: center;
  right: 0;
  bottom: 0;
  position: fixed;
}

.autor {
  color: #bebebe;
  font-size: 16px;
}

.printButton {
  border: none;
  font-size: 18px;
  border-radius: 5px;
  width: 80px;
  height: 20px;
  cursor: pointer;
  color: black;
  background: darkslategray;
}

@media print {
  .noPrint {
    display: none;
  }
}
<header >
  <a href="index.html"><img src="https://via.placeholder.com/80" alt="Logo strony" ></a>
  <div >
    <button><a href="index.html" >Główna</a></button>
    <div >
      <button>Ciasta</button>
      <ul>
        <li><a href="biszkopt.html">Biszkopt</a></li>
        <li><a href="beza.html">Beza</a></li>
        <li><a href="makowiec.html">Makowiec</a></li>
      </ul>
    </div>
    <div >
      <button>Pieczywo</button>
      <ul>
        <li><a href="chleb.html">Chleb</a></li>
        <li><a href="bulki.html">Bułki</a></li>
        <li><a href="bulkiNaSlodko.html">Bułki na słodko</a></li>
      </ul>
    </div>
    <button><a href="informacje.html" >Informacje</a></button>
  </div>
</header>

CodePudding user response:

I'm not sure what you want but is it like this?

.dropdown {
    position: relative;
    display: inline-block;
}
.dropdown > .dropdown-text {
    padding: 10px 20px;
    position: relative;
}
.dropdown > input {
    top: 0;
    opacity: 0;
    display: block;
    padding: 0;
    margin: 0;
    position: absolute;
    height: 100%;
    width: 100%;
    cursor: pointer;
}
.dropdown > input:checked ~ .dropdown-container {
    transform: scaleY(1);
}
.dropdown > .dropdown-container {
    display:block;
    position: absolute;
    background-color: #ffffff;
    transform: scaleY(0);
    left:0;
    width: 250px;
    top: 38px;
    box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.3);
}
.dropdown > .dropdown-container > a {
    display: block;
    position: relative;
    text-decoration: none;
    padding: 10px;
    background-color: #ffffff;
    color: #000000;
}
<div >
    <div >THIS IS A DROPDOWN</div>
    <input type="checkbox">
    <div >
        <a href="/link1">Item 1</a>
        <a href="/link2">Item 2</a>
        <a href="/link3">Item 3</a>
    </div>
</div>

  •  Tags:  
  • Related