"Enhance user interaction by making all rotated elements within a div clickable

I have created a unique hamburger menu that, when clicked, rotates two of its children and hides one. The dimensions of the hamburger are 30px in width and 13px in height. However, there is an issue where only the central area of the "X" is clickable due to the increased height after rotation.

How can I ensure that the entire "X" remains clickable?

var hamburger = document.getElementById("menu-icon-css");
var menuMobile = document.getElementById("menu-links");

hamburger.addEventListener("click", function open() {
  hamburger.classList.toggle("rotate");
})
#menu-icon-css {
  z-index: 50;
  margin-top: 50px;
  width: 30px;
  height: 13px;
  position: relative;
  cursor: pointer;
  display: block;
}
#menu-icon-css span {
  transition: 0.3s all ease-in-out;
  height: 3px;
  background-color: #000;
  position: absolute;
  width: 100%;
}
#menu-icon-css span:nth-child(1) {
  top: 0;
}
#menu-icon-css span:nth-child(2) {
  top: 6px;
  width: 70%;
  right: 0;
}
#menu-icon-css span:nth-child(3) {
  top: 12px;
}
@media screen and (min-width: 920px) {
  #menu-icon-css {
    display: none;
  }
}

#menu-icon-css.rotate span:nth-child(1) {
  transform: rotate(135deg);
  top: 6px;
}
#menu-icon-css.rotate span:nth-child(2) {
  opacity: 0;
  transition: 0.1s all ease-in-out;
}
#menu-icon-css.rotate span:nth-child(3) {
  transform: rotate(-135deg);
  top: 6px;
}
<div id="menu-icon-css">
  <span></span>
  <span></span>
  <span></span>
</div>

I will provide a screenshot of the issue using Inspect.

https://i.sstatic.net/xjpuA.png

Thank you!

Answer №1

Make some adjustments to the top margin, height of the menu-icon-css div, and positioning of child elements with these suggestions below. (I have made changes to certain lines in your code by commenting them out and replacing them with my modifications.)

#menu-icon-css {
    z-index: 50;
    //margin-top: 50px;
    margin-top: 42px;
    width: 30px;
    //height: 13px;
    height: 30px;
    position: relative;
    cursor: pointer;
    display: block;
}
#menu-icon-css span {
    transition: 0.3s all ease-in-out;
    height: 3px;
    background-color: #000;
    position: absolute;
    width: 100%;
}
#menu-icon-css span:nth-child(1) {
    top: 0;
}
#menu-icon-css span:nth-child(2) {
    top: 6px;
    width: 70%;
    right: 0;
}
#menu-icon-css span:nth-child(3) {
    top: 12px;
}
@media screen and (min-width: 920px) {
    #menu-icon-css {
    display: none;
  }
}

#menu-icon-css.rotate span:nth-child(1) {
    transform: rotate(135deg);
    //top: 6px;
    top: 14px;
}
#menu-icon-css.rotate span:nth-child(2) {
    opacity: 0;
    transition: 0.1s all ease-in-out;
}
#menu-icon-css.rotate span:nth-child(3) {
    transform: rotate(-135deg);
    //top: 6px;
    top: 14px;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The default value of the input color in HTML/NextJS does not update when changed

Issue: The color input does not change when the default value (#ffffff) is declared. https://i.sstatic.net/BpqUj.png However, it works normally if I don't declare a default value. https://i.sstatic.net/0dBd6.png Note: Using NextJS framework. <i ...

I'm looking for a way to have an element shift in a particular direction only when two keys are pressed simultaneously

Having trouble moving a square diagonally when two keys are pressed simultaneously. Trying to create an if statement that detects both key presses at the same time and triggers the movement. However, all attempts have failed so far, leaving uncertainty abo ...

Vanishing border around the sticky table header

While working on creating a table in an excel style using html and css with a sticky header, I noticed that the borders on the table head appeared strange. Take a look at the code snippet below: table { border-collapse: collapse; position: relative ...

With the simple click of a button, I aim to refresh and enhance the appearance of a polygon

My goal is to create a button that, when clicked, causes the gray stripe in the middle to transition to the right. I am not very familiar with HTML, CSS, and JavaScript so I could use some help figuring out how to achieve this effect. Here is a quick illus ...

Is it possible to set a foreign key in Django as read-only and still successfully submit the form without encountering any errors?

I have been attempting to set a foreign key as read-only in my Django forms. I am developing a web application with system management capabilities and I need to prevent specific users from altering a certain field after it has been submitted. class Approv ...

Incorporate a tall button on the right edge of the division

I have successfully implemented a sidebar with the ability to hide or display it using this link. Now, I am looking to add a clickable bar on the right side of the div that can also trigger the hide/show functionality. After experimenting, I discovered th ...

Discovering visible ID numbers on the screen

My content includes the following: <div id="sContainer"> <div class="message0" id="l0">Initial Content 111</div> <div class="message1" id="l1">Initial Content 222</div> <div class="message2" id="l2">Initial ...

Utilizing locally hosted JavaScript in an HTML document

Hi everyone, I am an extreme beginner in HTML and JavaScript so I would appreciate explanations to be as simple as possible. Despite reading various versions of this problem, I am still struggling to figure it out. Any help is greatly welcomed. My goal is ...

Tips for coloring just the letters and excluding the Bengali Kar symbol

The Bengali language consists of 40 consonants, including ক, খ, গ, ঘ, ঙ, চ, ছ, জ, ঝ, ঞ, and more. Additionally, there are 10 vowels in the form of Kars, such as া, ি, ী, ু, ূ, ৃ, ে, ৈ, ো, and ৌ. My goal is to highli ...

Table with a fixed header and scrolling body in Bootstrap 4

https://i.sstatic.net/YasoT.pnghttps://i.sstatic.net/ubmHZ.png I'm new to the world of front-end development and I'm currently working on a table layout. Here's the code snippet of the table I've created: <div className="table ...

Accessing JavaScript cookie within .htaccess file to establish redirection parameters according to cookie content

Is there a way to modify the rules within my .htaccess file so that it can properly read a user-side cookie and redirect based on its content? The scenario is this: I have a cookie called userstate which contains an abbreviation of US states, such as AL ( ...

How can I force CSS to return to the unvisited style once the user leaves a visited page with an <a> tag?

a.navigation:link {color: white; text-decoration: none; padding: 20px 20px 20px 20px; border: 0.5px solid white; border-radius: 70px 70px;} a.navigation:visited {color: lightgreen; padding: 20px 20px 0px 20px; border: 0.5px solid li ...

Popup windows are struggling to close correctly

Having an issue with multiple popups not closing properly when clicking another link. The popups keep stacking up even though the close function has been specified in the code. $(document).ready(function() {//$('a.poplight[href^=#]').click(funct ...

Exploring the versatility of Bootstrap 4's grid system with varying column widths

I am encountering an issue with div alignment in my code. The first two col-3 classes seem to have different widths than the next two col-3 classes, causing elements to appear unaligned. Here is the code snippet: <link href="https://stackpath.bootstr ...

Connecting with a php anchor and hash symbol in a website URL

Looking to include a PHP anchor along with a hash anchor in an HTML link. <?php echo '<a href="test.php?page='.$i.'#hash">'.$i.'</a>'; ?> The PHP code successfully echoes the link, but upon clicking it, th ...

My div remains stationary despite keyframes

I've been attempting to create a div that moves up and down using CSS3, but unfortunately it's not working properly. <div class="globo"></div> @-webkit-keyframes mover { 0%, 100% { top: 0%;} 50% { top: 5%; } } @-moz-keyframe ...

Stop vuetify from cluttering the global style scope

Seeking to embed a Vue component into another from an external source without using a Vue Plugin. The components are mounting correctly, but the embedded component's use of Vuetify is affecting the parent application's style. Visual examples can ...

Every time I attempt to create a detail page for a table, I am consistently greeted with an error message

Error: Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /var/www/2909kher/entabell/detaljer.php on line 23 <!doctype ...

Ways to retrieve a specific item from a constantly changing knockout observableArray without employing a foreach loop

Why can I only access one property ('member_A') of an Element in an observableArray using an HTML <input>? I am attempting to add a new object of type abc() to the observableArray "list_of_abc" when the button "ADD To List of abc" is click ...

Align a flex item at the center of its parent when the parent has a flex direction of column

My challenge is aligning a flex item vertically within the remaining space allocated to it. This is my current code snippet: <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="82e0e ...