The HTML modal closing button is unresponsive and the contents inside are misaligned, causing functionality issues

I've searched through similar questions, but none of the suggested solutions seem to work for my issue.

The problem I'm facing is that the closing button on my modal isn't functioning properly and the content inside it is not aligning correctly. (Update: After adding a border, I noticed a strange square occupying space below the "X" button, but I still can't figure out why)

It appears that both issues are intertwined, possibly linked with the padding at the top, but I'm unable to resolve it. Any assistance would be greatly appreciated.

https://i.sstatic.net/8C8gF.png

.mobile-menu {
  float: right;
  padding: 1.1em 0.6em 0.1em 0.9em;
  border: 1px solid;
}

.mobile-menu-modal {
  z-index:3;
  display:none;
  padding-top:85px;
  position:fixed;
  left:0;
  top:0;
  width:100%;
  height:100%;
  overflow:auto;
  background-color:rgb(0,0,0);
  background-color:rgba(0,0,0,0.4);
}

.mobile-menu-modal-content{
  margin-right:10%;
  margin-left: auto;
  background-color:#fff;
  position:relative;
  padding:0;
  width:40%;
}

.mobile-menu-a {
  text-align:center;
  display:block;
  font-weight:bold;
  font-size:1.2em;
  border-bottom:1px solid #eee;
  padding: 0.5em;
}
<a class="mobile-menu" onclick="document.getElementById('mobilemenu').style.display='block'">Menu Button
  <div id="mobilemenu" class="mobile-menu-modal">
    <div class="mobile-menu-modal-content">
      <span onclick="document.getElementById('mobilemenu').style.display='none'" style="float:right;font-size:2em;cursor:pointer;">&times;</span>
      <div class="clearfix"></div>
      <div style="padding-top:5em">
        <a class="mobile-menu-a">200K+</a>
        <a class="mobile-menu-a">300K+</a>
        <a class="mobile-menu-a">400K+</a>
        <a class="mobile-menu-a">1M+</a>
      </div>
    </div>
  </div>
</a>

Answer №1

Ensure to properly close your <a> tag after the text is displayed on the main page, and then initiate a new container for content that will appear upon clicking the button. It is recommended to refrain from using inline styles and instead utilize an additional CSS class for styling the close button.

.mobile-menu {
  float: right;
  padding: 1.1em 0.6em 0.1em 0.9em;
  border: 1px solid;
}

.mobile-menu-modal {
  z-index:3;
  display:none;
  padding-top:85px;
  position:fixed;
  left:0;
  top:0;
  width:100%;
  height:100%;
  overflow:auto;
  background-color:rgb(0,0,0);
  background-color:rgba(0,0,0,0.4);
}

.mobile-menu-modal-content{
  margin-right:10%;
  margin-left: auto;
  background-color:#fff;
  position:relative;
  padding:0;
  width:40%;
}

.mobile-menu-a {
  text-align:center;
  display:block;
  font-weight:bold;
  font-size:1.2em;
  border-bottom:1px solid #eee;
  padding: 0.5em;
}

.mobile-menu-modal .close-button {
  float: right;
  font-size: 2em;
  cursor: pointer;
}
<a class="mobile-menu" onClick="document.getElementById('mobilemenu').style.display='block'">Menu Button</a>
  <div id="mobilemenu" class="mobile-menu-modal">
    <div class="mobile-menu-modal-content">
      <span class="close-button" onClick="document.getElementById('mobilemenu').style.display='none'">&times;</span>
      <div class="clearfix"></div>
      <div style="padding-top:5em">
        <a class="mobile-menu-a">200K+</a>
        <a class="mobile-menu-a">300K+</a>
        <a class="mobile-menu-a">400K+</a>
        <a class="mobile-menu-a">1M+</a>
      </div>
    </div>
  </div>

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

Adjust the bootstrap switch component to be in the 'checked' state when the mode is set to Dark

I have stored a theme for my web application in the localStorage and I want to dynamically add the checked value to the Switch component if the mode is set to 'dark', or unchecked if the mode is 'light'. However, whenever I set the them ...

Arrange the navigation bar in a straight line

I am facing an issue with my navigation bar... I want it to be centered but it is not working. I want it to fill from left to right. I have tried using the following CSS: text-align: center in .navbar a text-align: center in navbar. .navbar { backgr ...

Exploring the attributes of div elements with XPath

Currently, I am in the process of familiarizing myself with xpath through the creation of a basic program that will display the list of Premier League fixtures in football from a specific webpage. The page in question can be found at the following link: A ...

Show a brief description alongside multiple post thumbnails

I have successfully uploaded multiple featured images to my WordPress website using the multiple post thumbnail plugin. Now, I want to showcase them all below the content along with their descriptions. While I have managed to display the main featured imag ...

Deleting tasks from the to-do list using Node.js and Express with EJS

Looking to implement functionality where each list item can be removed from a Node.js array by clicking on an HTML button using EJS and Express: I am considering placing an HTML button next to each list element so that the selected element can be removed ...

Tips for utilizing CSS container queries in conjunction with the Material-UI framework

I'm looking to implement CSS container queries with MUI. In my code, I want to change the background color to red if the parent width is less than 300px. Check out the sandbox const StyledItem = styled("div")(({ theme }) => ({ border: ...

The size of the panel header does not seem to be adjusting as expected within the React

I need help adjusting the header size in a React-Bootstrap Panel within a Typescript application. I've tried wrapping the text in <h1> tags as specified in the documentation, but there seems to be no change. Even with attempts to add inline sty ...

Removing data entry from MySQL database table using PDO

I'm facing an issue with deleting a row from my database. Despite trying various methods like PDO and MySQL, the data is not getting deleted, but it shows as if it has been deleted. Can someone please help me identify what might be wrong with my code? ...

Using the float property in IE7 can cause a line break and may result in other divs being pushed down

Hey there, I've encountered a few issues with floats in IE multiple times. Here's an example to illustrate what I mean. Please note that this example functions properly in Firefox and Chrome. index.html <html> <link href="style.css" rel= ...

What is the best way to ensure the hamburger menu stays perfectly centered?

My menu is currently aligned to the right and scrolls with the user profile. I want the menu to always be centered and the profile to stay on the right side. I am working with Angular 12 and Bootstrap 5 for this project. Here is the code I have been usin ...

After examining the width properties in the CSS code, it was discovered that one particular icon is larger in

Is there a way to adjust the width of the first icon in my container using CSS? The first icon appears larger than the others, and I'm having trouble making it the right size. #features { margin-top: 35px; } .grid { display: flex; } #feat ...

Pass along computed style data to the parent component in Vue.js

I am relatively new to VueJS and currently in the process of exploring its features. One specific issue I am facing on my website involves a TopBar component that includes both the logo and the menu. <template> <div id="topBar"> <div ...

Achieve vertical alignment and responsiveness of elements in primefaces using css techniques

In order to vertically align 2 elements inside an outputpanel, I initially used a margin-top of 3em. However, this method proved to be non-responsive, as shown in the following images: https://i.sstatic.net/yMRXc.png In mobile view: https://i.sstatic.net ...

How can we modify this function to interpret multiple selections at once?

For the task of displaying multiple selections from a scrolling list to an alert, I have implemented the following function: var toppings = ""; function displaySelectedToppings() { var topList = document.getElementById('to ...

The following divs are adjacent to each other, with their widths set in percentages, and the paddings

I successfully transformed divs into a column of tables. However, now I am looking to add some padding between the divs. When I attempt to do so like this: <div style="float:left; width:100%;"> <?php foreach ($datas as $rec) { ?> <div ...

Showcasing all elements of an xml through jquery while implementing a filter

Trying to implement a filter on XML using jQuery. The filtered results are showing based on the condition, but facing difficulty in displaying all XML items when the flag is set to 0; meaning that when the flag is zero, all XML items should be displayed ...

Vuetify's data table now displays the previous and next page buttons on the left side if the items-per-page option is hidden

I need help hiding the items-per-page choices in a table without affecting the next/previous functionality. To achieve this, I've set the following props: :footer-props="{ 'items-per-page-options':[10], &apo ...

Is there a way to remove the spacing that browsers automatically add to <input> elements?

Take a look at this example: http://jsfiddle.net/JPQxX/ I tested this in both Chrome and Firefox. In both browsers, there seems to be a small 1-2px margin between the two input elements. I am looking for a solution to make these two elements touch without ...

Book of Tales displaying Emotion Styling upon initial load only

I'm currently working with the styled api provided by emotion in order to create a custom styled button. const StyledButton = styled(Button)` background-color: ${theme.palette.grey['800']}; width: 50; height: 50; &:hover { ba ...

When an image is placed inside a parent div, the link should extend to the entire width of the div, rather than just hovering over

Essentially, I have a div that spans the entire width of its container, inside it is an image link. The image's width is set to adjust automatically with a fixed height of 600px. The link covers the whole width of the div, which in this case is the wi ...