Issue with pop-up functionality on web page using HTML, CSS, and JavaScript

Recently, I created a unique popup using HTML. You can see the complete code (excluding CSS) here: https://codepen.io/nope99675/pen/BawrdBX. Below is the snippet of the HTML:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <link rel="stylesheet" href="./homepage.css" />
        <script src="./homepage.js" defer></script>
      </head>
      <body>
        <div>
          <div class="popup" id="popup-1">
            <div class="overlay"></div>
              <div class="content">
                <div class="closebtn" onclick="togglePopup()">&times;</div>
                  <h2>What do you want to make?</h2>
          </div>
              </div>
            <button type="button" class="Create" onclick="togglePopup()"> Create
              <span class=button__icon>
                <ion-icon name="add-outline"></ion-icon>

              </span>
            </button>
            <button type="button" class="settings"> Settings
              <span class="button__icon">
                <ion-icon name="cog-outline"></ion-icon>
              </span>
            </button>
            <button type="button" class="del"> Delete
              <span class=button__icon>
                <ion-icon name="trash-outline"></ion-icon>
              </span>
            </button>
            <button type="button" class="feed"> Feedback
              <span class="button__icon">
                <ion-icon name="chatbubble-ellipses-outline"></ion-icon>
              </span>
            </button>
        </div>
        <script type="module" src="https://unpkg.com/ionicons@5/dist/ionicons/ionicons.esm.js"></script>
        <script nomodule src="https://unpkg.com/ionicons@5/dist/ionicons/ionicons.js"></script>
      </body>
</html>

Additionally, I wrote some JavaScript for handling the pop-up functionality:

function togglePopup() {
    document.getElementById("popup-1").classList.toggle(active);
    
};

However, there are a couple of issues with the current implementation. The popup is not appearing only when the designated button is clicked, and it's missing the desired background color (#fff). Furthermore, the close button in the corner isn't styled as intended. It should have a white text color against a black background. Can someone please assist with resolving these problems?

Answer №1

After some tweaking in the CSS and JS, I have managed to get it working perfectly.

function showPopup() {
  debugger;
    document.getElementById("popup-1").classList.toggle("active");
}
@import url("https://fonts.googleapis.com/css2?family=Noto+Sans&display=swap");

.popup .overlay {
    position: fixed;
    top:0px;
    left: 0px;
    width: 100vw;
    height: 100vh;
    z-index: 1;
    background: rgba(0,0,0,0.7);
    display: none;
}


.popup .content {
    position: absolute;
    top: 50%;
    left:50%;
    transform: translate(-50%, -50%) scale(0);
    background-color: #fff;
    width: 450px;
    height:220px;
    z-index: 2;
    text-align:center;
    padding: 20px;
    box-sizing: border-box
}

.popup .closebtn {
   position: absolute;
   right: 20px;
   top:20px;
   width: 30px;
   height: 30px;
   background:#222;
   color:#fff;
   font-size:25px;
   font-weight: 600;
   line-height: 30px;
   text-align: center;
   border-radius: 50%;
}

.popup.active .overlay {
    display: block;
}

.popup.active .content {
    transition: all 300ms ease-in-out;
    transform: translate(-50%, -50%) scale(1);
}


body {
    --color-primary: #595594;
    --color-other: #1a6b21;
    --color-primary-dark: #3e247a;
    --color-secondary: #252cba;
    --color-error: #990000;
    --color-secondarie: #3cca11;
    --border-radius: 5px;
    --color-better: #34994a;
    --color-setting: #81c2e7;
  
    margin: 0;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    background: url(./homepage.png);
    background-position: center;
  }

.Create {
    font: 500 1.5rem "Noto Sans", sans-serif;
    background-color: var(--color-setting);
    color: #ffffff;
    border-radius: 5px;
    position: relative;
    top: -250px;
    left: -370px;
    margin: 4px 2px;
}

.settings {
    font: 500 1rem "Noto Sans", sans-serif;
    background-color: var(--color-setting);
    color: #ffffff;
    border-radius: 5px;
    position: relative;
    top: -200px;
    left: -490px;
}

.del {
    font: 500 1rem "Noto Sans", sans-serif;
    background-color: var(--color-setting);
    color: #ffffff;
    border-radius: 5px;
    position: relative;
    top: -150px;
    left: -590px;
}

.feed {
    font: 500 1rem "Noto Sans", sans-serif;
    background-color: var(--color-setting);
    color: #ffffff;
    border-radius: 5px;
    position: relative;
    top: -100px;
    left: -686px;
}
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <link rel="stylesheet" href="./homepage.css" />
        <script src="./homepage.js" defer></script>
      </head>
      <body>
        <div>
          <div class="popup" id="popup-1">
            <div class="overlay">
              <div class="content">
                <div class="closebtn">&times;
                  
                </div><h2>What do you want to make?</h2>
              </div>
            </div>
          </div>
            <button type="button" class="Create" onclick="showPopup()"> Create
              <span class=button__icon>
                <ion-icon name="add-outline"></ion-icon>

              </span>
            </button>
            <button type="button" class="settings"> Settings
              <span class="button__icon">
                <ion-icon name="cog-outline"></ion-icon>
              </span>
            </button>
            <button type="button" class="del"> Delete
              <span class=button__icon>
                <ion-icon name="trash-outline"></ion-icon>
              </span>
            </button>
            <button type="button" class="feed"> Feedback
              <span class="button__icon">
                <ion-icon name="chatbubble-ellipses-outline"></ion-icon>
              </span>
            </button>
        </div>
        <script type="module" src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ea8385848389858499aadfc4dfc4d8">[email protected]</a>/dist/ionicons/ionicons.esm.js"></script>
        <script nomodule src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="abc2c4c5c2c8c4c5d8eb9e859e8599">[email protected]</a>/dist/ionicons/ionicons.js"></script>
      </body>
</html>

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

Sort data by checking either multiple or single checkbox options in AngularJS; if none are selected, display all results

My goal is to implement a filter in my AngularJS code that will filter data based on selected checkboxes. If no checkbox is selected, all results should be displayed without any filtering. Currently, the issue I am facing is that the data is only displayed ...

What is the best way to generate a nested object arrangement using a path (series of keys)?

I have a challenge of creating nested objects from arrays of strings to store the sequence of input strings. Originally, I was only generating chains with a depth of 2, but now I need to expand this capability to create higher-depth chains. Essentially, I ...

choosing and identifying the iframes for YouTube videos

I have a webpage that showcases images of YouTube videos, allowing users to choose from them. This is how I am presenting them: <ul> <li> <div class="youtubeMediaContainer"> <img src="video_preview_image1.jpg"& ...

How to smoothly transition a div from one location to another using animations in an Ionic3-Angular4 application

I'm attempting to incorporate some animation into my Ionic 3 mobile app. Specifically, I want to shift a div from one location to another. In the code snippet provided below, I am looking to move the div with the "upper" class after the timeline-item ...

Discontinue playing videos embedded in iframes on Dailymotion

I'm currently working on creating a slider that includes videos from multiple providers, and I need to ensure that the videos stop when changing slides. So far, I've successfully implemented this feature for Vimeo and YouTube without making any a ...

The sendFile function fails to transmit any data

Currently working on integrating the mailChimp API into my project, but facing an issue with the resFile code that handles sending the success response. The current code snippet: async function run(){ try { const res = await mailch ...

How can a div tag and its class be nested using CSS in Angular?

Can someone help me with nesting a div tag with the "error" class in CSS? <div [class]="{error: condition}">{{ message }}</div> I want to know how to have the .error selector inside the div selector in the CSS file. Note: The error ...

Converting HTML to plain text using the DOMDocument class

Is there a way to extract the text content from an HTML page source code, excluding the HTML tags? For example: <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta http-equiv="content-language" content="hu"/> <titl ...

What is the goal of the output file in Webpack?

Currently, I am following the React tutorial at http://www.tutorialspoint.com/reactjs/reactjs_components.htm, and I find myself puzzled about the exact purpose of webpack entry and output filename. In the provided example, they have an index.html file and ...

Align the bottom borders to the lowest content on each line

I am working on designing my homepage using HTML, CSS, JSP, and JavaScript, focusing on the sale of musical instruments and facilitating communication among users. Right now, I am in the process of creating a site-map for my menu configuration chart using ...

Removing the 'div' tag using jQuery in CodeIgniter

I need assistance in removing the added item. $(document).ready(function() { $("#appendex0").click(function() { $(".divcls0").append('<div class="col-sm-10 col-sm-offset-1"><div class="col-sm-3 col-sm-offset-1"><div class="form ...

Unable to get compatibility mode IE to work as intended

I am facing an issue where I need to showcase a webpage in compatibility mode. Despite using the code below: <meta http-equiv="X-UA-Compatible" content="IE=11"> It seems like this code only functions if compatibility mode is already enabled. In tha ...

"Media queries in CSS don't consistently apply all styles when reaching the minimum

The CSS styles I am using are as follows: @media (min-width: 1280px) { .window-padding { padding-top: 20px; padding-bottom: 20px; padding-left: 30px; padding-right: 30px; } } @media (min-width: 769px) { .windo ...

Fetching the jquery variable within an HTML document: A step-by-step guide

Here is the content of my check.js JavaScript file, which includes a function: function fun2(userid) { $.ajax({ type: 'POST', url: 'ex.php', data: {userid: userid}, success: function (data) { ...

What's the reason for my badge being an oval shape?

I am attempting to design a badge that hovers above my cart icon and shows the total number of items currently in the cart. However, I have encountered an issue where the badge appears as an oval shape rather than a perfect circle. Can anyone assist with ...

SCSS files scattered throughout Solution Explorer create disorder in Visual Studio

I currently work with Visual Studio 2013. Typically, in the solution explorer, scss files are displayed with their .css, .css.map, and .min.css files neatly grouped under the main .scss file. However, I'm experiencing a lack of organization as all th ...

Pushing state history causes browser back and forward button failure

I'm currently utilizing jQuery to dynamically load content within a div container. On the server side, the code is set up to detect if the request is being made through AJAX or GET. In order to ensure that the browser's back and forward buttons ...

JQuery Scroll Spy Implementation

I have structured the page with a header at the top and 3 columns below. The left column contains a menu, the middle column is a text container, and the right column is another section. As the page scrolls up, the menu becomes fixed in position which func ...

Show a message notifying the user of an incorrect password input

Hey there, currently I have a script set up which logs into live.com in this manner: WebBrowser1.Document.GetElementById("login").SetAttribute("value", txtUsername.Text) WebBrowser1.Document.GetElementById("passwd").SetAttribute("value", txtPass ...

How can I trigger a row click event while a TextInput is in focus? (react-native)

Whenever I tap on a ListView item, the TouchableOpacity functions properly. However, when a TextInput is in focus, it requires two taps for it to work - the first tap only removes the focus from the TextInput. Is there a way to make it work without havin ...