Tıklandığında X işaretine dönüşen hamburger menü
<style>
.hamburger {
width: 40px;
height: 30px;
position: relative;
cursor: pointer;
}
.hamburger span {
display: block;
position: absolute;
height: 4px;
width: 100%;
background: #333;
border-radius: 4px;
transition: .25s ease-in-out;
}
.hamburger span:nth-child(1) {
top: 0px;
}
.hamburger span:nth-child(2), .hamburger span:nth-child(3) {
top: 13px;
}
.hamburger span:nth-child(4) {
top: 26px;
}
.hamburger.active span:nth-child(1) {
top: 13px;
width: 0%;
left: 50%;
}
.hamburger.active span:nth-child(2) {
transform: rotate(45deg);
}
.hamburger.active span:nth-child(3) {
transform: rotate(-45deg);
}
.hamburger.active span:nth-child(4) {
top: 13px;
width: 0%;
left: 50%;
}
</style>
<div class="hamburger">
<span></span>
<span></span>
<span></span>
<span></span>
</div>
<script>
document.querySelector(".hamburger").addEventListener("click", function() {
this.classList.toggle("active");
});
</script>
<head>
bölümüne CSS kodlarını ekleyin</body>
etiketinden önce ekleyin