Just one div with a unique ID, yet still belonging to the same class as another div

Having an issue with two divs that share the same class but have different IDs. Only the one defined first in the HTML code is visible (see screenshot below showing when leftMenu is created first).

https://i.sstatic.net/5Znvg.png

Below is the HTML layout of the divs:

<body>
    <div class = "sideMenu" id = "leftMenu">
        leftMenu
    </div>
    
    <div class = "sideMenu" id = "rightMenu">
        rightMenu
    </div>
</body>

It seems like my problem may be due to my limited knowledge of cascading stylesheets, so I've included all the relevant code from my .css file:

* {
    background-color: #001005;
    color: #00aa00;
    font-family: consolas;
    margin: 0px;
    overflow: hidden;
    padding: 0px;
    position: relative;
} /* default styling for elements */

.sideMenu {
    background-color: #00200a;
    border: 2px solid #00aa00;
    border-bottom: 0px;
    border-top: 0px;
    min-width: 15vw;
    max-width: 20vw;
    overflow-y: visible;
    width: fit-content;
    height: 100vh;
}  /* shared styling for side menus */

#leftMenu {
    left: 0vw;
    top: 0vh;
} /* styling for the left menu */

#rightMenu {
    left: 100vw;
    top: 0vh;
    transform: translate(-100%, 0%);
} /* styling for the right menu */

Everything appears to be set up correctly, but there's still an issue. Apologies if this is too basic, as it's been quite some time since I worked with HTML, CSS, or JS.

Answer №1

Your current code successfully positions all elements, but it still utilizes the default position: relative, causing the right navigation to appear below the left navigation (and off-screen since the left navigation is set to 100vh)

If you wish for both navigations to be visible at any scroll position on the page, it's advisable to use: position: fixed;

* {
  background-color: #001005;
  color: #00aa00;
  font-family: consolas;
  margin: 0px;
  overflow: hidden;
  padding: 0px;
  position: relative;
}

.sideMenu {
  position: fixed;
  background-color: #00200a;
  border: 2px solid #00aa00;
  border-bottom: 0px;
  border-top: 0px;
  min-width: 15vw;
  max-width: 20vw;
  overflow-y: visible;
  width: fit-content;
  height: 100vh;
}

#leftMenu {
  left: 0vw;
  top: 0vh;
}

#rightMenu {
  left: 100vw;
  top: 0vh;
  transform: translate(-100%, 0%);
}
<body>
  <div class="sideMenu" id="leftMenu">
    leftMenu
  </div>

  <div class="sideMenu" id="rightMenu">
    rightMenu
  </div>
</body>

Answer №2

The problem was solved by applying the position: fixed property to the .sideMenu class, fixing the issue in a punny way. Initially considering using relative which only added confusion.

Just as I discovered this solution, another person had already responded with the same fix including the code snippet, so they will be credited with providing the answer.

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

Why is the div still displaying with the same id and class even after postback in a partial view using MVC?

Encountering a issue where the partial view is repeating after post back, despite the functionality working correctly. Here is the code snippet from the View: @using (Ajax.BeginForm("MarkDefiniteDischargePatient", "PDDD",new { }, new Aja ...

Utilize jQuery Function on Identical Class of <ul> Elements

I have integrated a listview control in my ASPX page. The data is being fetched from the database and displayed in the listview. I have also utilized jQuery script to implement the .fadein() and .fadeout() effects on the listview elements. However, when I ...

Tips for creating dynamic rope animations with canvas and CSS3 styling

Interested in creating a canvas animation, or possibly using CSS3 for the same purpose. Looking to add an automatic rope animation, similar to it swaying gently. I've searched for scripts and other solutions, but haven't found anything suitable. ...

Implementing Dynamic Script Injection in Angular Controllers for Enhanced HTML Functionality

I'm a total beginner when it comes to Angular and frontend development, so please bear with me if my question seems basic: In my controller, I have the following code where I am populating the $window.user data that is being used in the script [2] ad ...

Tips for aligning all elements in-line using Bootstrap CSS

I am trying to make all elements display in a line in my HTML tags. How can I achieve this using Bootstrap? Currently, the page size is displaying on different lines. Thank you, Austin TX <div class="col-xs-12 col-md-8 form-inline"> <span c ...

Use the matrix4() of a different object to alter the properties of another (THREE.js version 84)

My goal is to move a cube based on the movement of another cube that has TransformControls attached using the Matrix4() method exclusively. Unfortunately, all attempts to shift the follower cube have been unsuccessful. It's puzzling why the follower ...

When working with DNN, I attempted to redirect using JavaScript code, but found that I continue to see the same page after the form submission code

Here is the code I am using to submit a form. When the button is clicked, it will trigger the Checkout() function. function postURL(url) { var form = $('<form action="' + url + '" method="post">' + "<input type=& ...

Creating a custom variable assignment in Bootstrap within the custom.scss file

I've been searching for a solution to this problem for half a day now. My goal is to change the value of the $primary variable from the default $blue to the $orange variable. I tried following the instructions in the documentation: $primary: red; @imp ...

In Laravel Blade, you can dynamically add rows and columns based on a certain condition

I'm working on creating a user interface for cinema seats in Laravel Blade. The database includes seat rows and columns, and the rows will be the same for two consecutive rows. For example, the first row could have an id of 1 with seat_row:1 and seat_ ...

Displaying specific data based on selected checkbox values in the dataTable

I am currently working with a table using dataTable. Within this table, there is a filter labeled "All" and "Software Engineer." When I click on the label "Software Engineer," the data displayed is appropriate to the label. However, when I click on the "Al ...

Tips for customizing CSS for the ValidatorCallout Extender in an ajax tool

I am currently attempting to implement the ValidatorCallout Extender feature from the asp.net Ajax website. However, I am struggling with customizing the CSS for the popup validator. ...

Creating a full-width input field with text aligned to the right:

.wrap { white-space: nowrap; } input { width: 100%; } body { /* just so you can see it overflowing */ border: 1px solid black; margin: 40px; padding: 10px; } <span class="wrap"><input type="text">.pdf</span> Observing the cod ...

showcasing a map on an HTML webpage

Seeking advice on integrating a map feature in HTML to mark store locations. Working on an app for a business community and need help with this specific functionality. Your assistance would be greatly appreciated! ...

Having trouble with changing the color of an element when the radio input is checked?

Can someone help me troubleshoot this HTML and CSS code? <label class="radio"> <input type="radio" name="plan" value="plan" required> <span> <h6>Plan</h6> <i class="pe-7s-graph1 ...

Is there a way to fix the noticeable difference in how bold text appears between IE11 and Chrome?

When viewing some of the titles on in Google Chrome, they appear like this: https://i.sstatic.net/bKjNE.png However, when viewed in MSIE11, they look like this: https://i.sstatic.net/SJfKk.png The use of strong/bold/font-weight seems to have no effect ...

What is the best method for creating an HTML table using a JSON object?

Currently, I am in the process of developing an express app that can render a csv file and convert it into a json format. Within my method, I have this json data stored as a variable and my goal is to display it as a table on an HTML page. How can I effect ...

Is it possible for a Bootstrap modal dialog to overlay another dialog window?

<button class="btn" onClick="$('#firstModal').modal('show');">Click Here</button> <!-- Modal --> <div id="firstModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden=" ...

Creating a scrolling effect similar to the Nest Thermostat

After researching countless references, I am determined to achieve a scrolling effect similar to the Nest Thermostat. I came across this solution on this JSFiddle, but unfortunately, the parent element has a fixed position that cannot be utilized within my ...

"Learn how to extract the image URL from the configuration file (config.json) within the assets folder, and then seamlessly display it within

In my Angular project, I have a configuration file located in the assets folder: { "brandConfig": "brand1", "brand1": {"urlPath": "http://192.168.168.60:8081/mantle-services", " ...

Menus that mimic the style of Google Translate's select options

I'm looking to design an HTML select menu using CSS in a similar fashion to Google Translate's style on Google Translate. I've searched for tutorials online, but they all involve jQuery. Is there a way to achieve something similar using only ...