The placement of the button is not correct and should be adjusted to the proper position

I have created a webpage with two distinct sections, each occupying the height of the viewport. The first section contains a 'work' button in the center. Upon clicking this button, it disappears and is replaced by some links. The same functionality applies to the second section as well.

Now, I am attempting to implement a reset function that removes the links and adds back the buttons. Initially, I tried to make one universal reset button for all sections, but since that didn't work as expected, I am now focusing on creating individual reset buttons for each section.

The issue I am facing is that the second section's reset button appears in the same location as the first section's button. Ideally, they should be positioned at the bottom right corner of their respective sections.

function openSites(categoryType) {
  if (categoryType == "work") {
    var sites = document.getElementById("workSites");
    var button = document.getElementById("workButton");
  } else if (categoryType == "other") {
    var sites = document.getElementById("otherSites");
    var button = document.getElementById("otherButton");
  }
  sites.classList.add("show");
  sites.classList.remove("hide");
  button.classList.add("hide");
}

function reset(categoryType) {
  if (categoryType == "work") {
    var sites = document.getElementById("workSites");
    var button = document.getElementById("workButton");
  } else if (categoryType == "other") {
    var sites = document.getElementById("otherSites");
    var button = document.getElementById("otherButton";
  }
  sites.classList.remove("show");
  sites.classList.add("hide");
  button.classList.remove("hide");
}

function betterReset() {
  for (category in document.getElementsByClassName("category-container")) {
    document.write(category);
  }
}
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.page {
  display: inline-block;
  overflow: hidden;
  width: 100%;
  height: 100vh;
}

#page-1 {
  display: block;
  background-color: #3faae4;
}

#page-2 {
  display: block;
  background-color: #ffffff;
}

.pointer {
  cursor: pointer;
}

#work {
  height: 100%;
  width: 100%;
}

#other {
  height: 100%;
  width: 100%;
}

#workSites {
  height: 100%;
  width: 100%;
}

#otherSites {
  height: 100%;
  width: 100%;
}

.sites {
  list-style-type: none;
  height: 100%;
}

.site {
  padding: 50px 0px;
  flex-grow: 1;
  text-align: center;
}

.center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.category-container {
  height: 100%;
}

.category-button {
  border: solid 0.5px;
  padding: 60px;
}

.buttonClose {
  position: absolute;
  border: solid 0.5px;
  border-radius: 5px;
  right: 3px;
  bottom: 0px;
  width: 70px;
  height: 35px;
}

.show {
  display: block;
}

.hide {
  display: none;
}
<!DOCTYPE html>
<html>
<head>
  <title>Nick's site</title>
  <link rel="stylesheet" type="text/css" href="./styles3.css">
  <meta name="viewport" content="width= device-width, inital-scale=1">
</head>
<body>
  <div id="page-1" class="page">
    <div id="work">
      <div id="workButton" class="category-container center">
        <a class="category-button pointer" onclick="openSites('work')">Work</a>
      </div>
      <div id="workSites" class="hide">
        <ul class="sites center">
          <li class="site"><a class="pointer" href="#">Printfactory</a></li>
          <li class="site"><a class="pointer" href="#">Henry's Site</a></li>
        </ul>
        <button onclick="reset('work')" class="buttonClose pointer" style="z-index: 2;">
         Reset
       </button>
      </div>
    </div>
  </div>
  <div id="page-2" class="page">
    <div id="other">
      <div id="otherButton" class="category-container center">
        <a class="category-button pointer" onclick="openSites('other')">Other</a>
      </div>
      <div id="otherSites" class="hide">
        <ul class="sites center">
          <li class="site"><a class="pointer" href="#">#</a></li>
          <li class="site"><a class="pointer" href="#">#</a></li>
          <li class="site"><a class="pointer" href="#">#</a></li>
        </ul>
        <button onclick="reset('other')" class="buttonClose pointer" style="z-index: 2;">
          Reset2
        </button>
      </div>
    </div>
  </div>
</body>
</html>

Answer №1

By assigning the position:absolute property to your reset buttons, they are taking on the values of right and bottom relative to the next parent element with a position:relative declaration - in this case, the body tag.

To resolve this issue, you can add the position:relative style rule to your parent divs as shown below:

#workSites,
#otherSites {
  position: relative;
}

I hope this information proves helpful! :)

function openSites(categoryType) {
                if (categoryType == "work") {
                    var sites = document.getElementById("workSites");
                    var button = document.getElementById("workButton");
                } else if (categoryType == "other") {
                    var sites = document.getElementById("otherSites");
                    var button = document.getElementById("otherButton");
                }
                sites.classList.add("show");
                sites.classList.remove("hide");
                button.classList.add("hide");

            }
            function reset(categoryType) {
                if (categoryType == "work") {
                    var sites = document.getElementById("workSites");
                    var button = document.getElementById("workButton");
                } else if (categoryType == "other") {
                    var sites = document.getElementById("otherSites");
                    var button = document.getElementById("otherButton");
                }
                sites.classList.remove("show");
                sites.classList.add("hide");
                button.classList.remove("hide");
            }
            function betterReset() {
                for (category in document.getElementsByClassName("category-container")){
                    document.write(category);
                }
            }
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
.page {
    display: inline-block;
    overflow: hidden;
    width: 100%;
    height: 100vh;
}
#page-1 {
    display: block;
    background-color: #3faae4;
}
#page-2 {
    display: block;
    background-color: #ffffff;
}
.pointer {
    cursor: pointer;
}
#work {
    height: 100%;
    width: 100%;
}
#other {
    height: 100%;
    width: 100%;
}
#workSites {
    height: 100%;
    width: 100%;
}
#otherSites {
    height: 100%;
    width: 100%;
}
.sites {
    list-style-type: none;
    height: 100%;
}
.site {
    padding: 50px 0px;
    flex-grow: 1;
    text-align: center;
}
.center {
    display: flex;
    align-items: center;
    justify-content: center;
}
.category-container {
    height: 100%;
}
.category-button {
    border: solid 0.5px;
    padding: 60px;
}
.buttonClose {
    position: absolute;
    border: solid 0.5px;
    border-radius: 5px;
    right: 3px;
    bottom: 0px;
    width: 70px;
    height: 35px;
}
.show {
    display: block;
}
.hide {
    display: none;
}

#workSites,
#otherSites {
  position: relative;
}
<!DOCTYPE html>
<html>
    <head>
        <title>Nick's site</title>
        <link rel="stylesheet" type="text/css" href="./styles3.css">
        <meta name="viewport" content="width= device-width, inital-scale=1">
    </head>
    <body>
        <div id="page-1" class="page">
            <div id="work">
                <div id="workButton" class="category-container center">
                    <a class="category-button pointer" onclick="openSites('work')">Work</a>
                </div>
                <div id="workSites" class="hide">
                    <ul class="sites center">
                        <li class="site"><a class="pointer" href="#">Printfactory</a></li>
                        <li class="site"><a class="pointer" href="#">Henry's Site</a></li>
                    </ul>
                    <button onclick="reset('work')" class="buttonClose pointer" style="z-index: 2;">
                        Reset
                    </button>
                </div>
            </div>
        </div>
        <div id="page-2" class="page">
            <div id="other">
                <div id="otherButton" class="category-container center">
                    <a class="category-button pointer" onclick="openSites('other')">Other</a>
                </div>
                <div id="otherSites" class="hide">
                    <ul class="sites center">
                        <li class="site"><a class="pointer" href="#">#</a></li>
                        <li class="site"><a class="pointer" href="#">#</a></li>
                        <li class="site"><a class="pointer" href="#">#</a></li>
                    </ul>
                    <button onclick="reset('other')" class="buttonClose pointer" style="z-index: 2;">
                        Reset2
                    </button>
                </div>
            </div>
        </div>
    </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

An error occurred when attempting to run the command npm run compile:sass, displaying the message: npm ERR! missing script:

Everything seems to be in place with the sass folders and files, so what could be the issue? I have my package.json file set up correctly with the following code: { "name": "starter", "version": "1.0.0", " ...

End the HTML page once the Flash (SWF) animation comes to a close

I have successfully exported my flash file to an HTML page. How can I make the page close automatically once the flash animation is finished? While I can use actionscript to stop the animation, I need the entire page to shut down on its own. I attempted u ...

Exploring the Power of Laravel 5.5 and Vue.js 2.x for Efficient API Calls

Currently, I am working on a Laravel 5.5 project locally that incorporates Vue.js 2.5.9 with XAMP Server. One of the tasks I have is to load certain information onto the DOM and then refresh it upon clicking the "Refresh" button. However, there seems to ...

Unable to retrieve JSON data for the JavaScript object

I have been working on creating a JS object in the following manner var eleDetailsTop = new Array(); var j = 0; var id = "ele"+j; eleDetailsTop[id] = {id: id, size : "40%", sizeLabel : 12, type : "image", title : "Image& ...

What is the explanation for the outcome "-9 >> 2 = -3"?

What is the reason behind 9 >> 2 = 2 compared to -9 >> 2 = -3 ? Wouldn't it make more sense for it to be -2 instead? ...

Discovering details regarding cookies established by an external domain

Is it possible to retrieve the host address of the domain that created a cookie on my webpage? Here is the scenario I am facing: I am on "domain A" and have a script linked from "domain B". A method on "domain B" sets a cookie on my "domain A". How can ...

Issue arises when trying to implement sidebar navigation in Angular with Materialize CSS

Just starting my Angular journey and running into some trouble trying to set up a practical and responsive menu using SidebarNav and Dropdown. I used CLI to install and configure angular2-materialize and materialize-css. To create the menu, I made a comp ...

If the parent class in HTML has a class of "active," then use jQuery to

I have attempted this, but unfortunately did not achieve the desired result. I am just brainstorming my ideas here. HTML <html> <div> <div class="spinner"> </div> </div> </html> Jquery if (".spinner"){ th ...

What is the best way to change the value of a boolean array in React?

In my component, I maintain an array of boolean values as a state. When the value is false, I need to change it to true. this.state = { checkedPos: [] } handleChange(index, reaction) { if (!this.state.checkedPos[index]) { this.state.ch ...

Eliminate Quotation Marks and Commas in String Data Using React

I created a code snippet to input data into a table and added a button function for downloading the entire table. However, when I open the downloaded file using notes or a text editor, it shows multiple double quotes and commas that I need to eliminate. He ...

Is Span responsible for creating a new line in this particular sentence?

I am struggling with aligning the following line of text that includes percentages like 100% and 99.8%. Is there a way to display all these elements in one line, side by side? <span style="font-size:12px;font-weight:bold;padding-left:800px;">99%& ...

I'm having trouble with my basic routing set up and I'm struggling to understand why it's not working

I'm currently working on a node tutorial and facing some challenges with my routes.js file. Previously, everything was functioning well today as the Node server was able to read the file. However, it seems to be ignoring it now for some unknown reaso ...

Issues with properly triggering re-clicking events in AngularJS when using Bootstrap modal

I am currently utilizing Angular JS in combination with Bootstrap modal. Below is the Anchor link I am referring to: <li><a href="#" data-toggle="modal" data-target="#inviteFriendModal" ><span class="frndInvt"></span>Invite Friends ...

Checkbox column within GridView allows users to select multiple items at once. To ensure only one item is selected at a

Currently, I am facing a challenge with dynamically binding a typed list to a GridView control within an asp.net page that is wrapped in an asp:UpdatePanel for Ajax functionality. One of the main requirements is that only one checkbox in the first column c ...

How can I use Ajax to show only one div on the entire page while keeping the CSS and other header content intact

One of my clients is looking to integrate a merch shop into their website. The existing merch page is not visually appealing and doesn't match the aesthetic of the client's site. I am considering using AJAX GET to fetch the content of the merch p ...

A guide on wrapping text within a Material-UI MenuItem

I am struggling to display text in a popover in multiple lines for UI reasons. I have tried updating the code but so far, I have not been successful. Any suggestions? <Popover anchorEl={target} open={open} anchorOrigin={{ horizontal: 'middle& ...

Triggering the retrieval of complete HTML content by clicking a button in order to load extra elements using Selenium

My goal is to scrape a webpage and gather all the links present on it. The page displays 30 entries and to access the complete list, one must click on a "load all" button. Below is the Python code snippet I'm currently using for this task: from sele ...

How can I make my Background change on click using hexadecimal color codes?

I am struggling with changing the background color of an html document using a button click. While colors like "yellow, "blue", and "red" work perfectly, I encounter an issue when trying to use hexadecimal colors such as "#000000". The if-condition doesn ...

The React class component is throwing an unexpected error with the keyword 'this'

I encountered an error stating "Unexpected keyword 'this'" while attempting to update the React state using Redux saga. Could someone shed light on what's wrong with the code below and how I can fix it? class Welcome extends React.Component ...

Can you explain the connection between CSS and WebKit?

Lately, the tag "webkit" has caught my eye on various questions. These inquiries typically pertain to web-related topics like CSS, jQuery, website layouts, and cross-browser compatibility problems... But what exactly is "webkit" and how does it interact w ...