Slide in overlay and slide out to the left

One of the features on my website is an overlay that slides in from right to left when the user clicks on the "Open" text. Currently, this overlay covers the entire page.

The overlay has a class name of Overlay, and its contents are located under .overlay-content

However, I want to adjust the overlay so that it only covers half of the page.

Below is the code snippet:

function openNav() {
  document.getElementById("myNav").style.left = "50%";
}

function closeNav() {
  document.getElementById("myNav").style.left = "100%";
}
.overlay {
  height: 100%;
  width: 100%;
  position: fixed;
  z-index: 1;
  top: 0;
  left: 100%;
  background-color: rgb(0, 0, 0);
  background-color: rgba(0, 0, 0, 0.5);
  overflow-x: hidden;
  transition: 0.5s;
}

.overlay-content {
  float: left;
  position: relative;
  top: 25%;
  width: 50%;
}

.overlay a {
  padding: 8px;
  text-decoration: none;
  font-size: 36px;
  color: #f1f1f1;
  display: block;
  transition: 0.3s;
}

.overlay a:hover,
.overlay a:focus {
  color: #f1f1f1;
}

.overlay .closebtn {
  position: absolute;
  top: 20px;
  right: 45px;
  font-size: 60px;
}

@media screen and (max-height: 450px) {
  .overlay a {
    font-size: 20px
  }
  .overlay .closebtn {
    font-size: 40px;
    top: 15px;
    right: 35px;
  }
}
... more code snippets ...

Check out the image below for the desired outcome: Expectedoverlay Actual result Overlaywholewidth Any assistance would be greatly appreciated.

Answer №1

I believe this is the information you were seeking...

function openSideMenu() {
  document.getElementById("myNav").style.left = "50%";
}

function closeSideMenu() {
  document.getElementById("myNav").style.left = "100%";
}
.overlay {
  height: 100%;
  width: 50%;
  position: fixed;
  z-index: 1;
  top: 0;
  left: 100%;
  background-color: rgb(0, 0, 0);
  background-color: rgba(0, 0, 0, 0.5);
  overflow-x: hidden;
  transition: 0.5s;
}
/* CSS code continues... */
<html>

<head>
</head>

<body>

  <span style="float:right;" onclick="openSideMenu()">&#8641;open</span>
  <div id="myNav" class="overlay">
    <a href="javascript:void(0)" class="closebtn" onclick="closeSideMenu()">&times;</a>
    <div class="overlay-content">
      <div class="text-block">
        <h1>"Fever" T-shirt</h1>
        <p>Lorem Ipsum text goes here.</p>
      </div>
      <button class="button">Purchase</button>
    </div>
  </div>
  <div id="button"><a href="#">Button 1</a></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

What is the most efficient method for updating dom handlers following the loading of new ajax content?

Currently, I am dealing with a large template that includes charts and other widgets. In addition to that, I manually integrated some ajax tabs. The issue arises when these tabs load new content (charts) because the template scripts in the head tag no long ...

What benefits does React offer that jQuery does not already provide?

What sets ReactJS apart from jQuery? If jQuery can already handle everything, why should we use React? I've tried to research on Google but still don't have a clear answer. Most explanations focus on terms like "views," "components," and "state" ...

Creating dynamic selection options in an HTML select tag using PHP

When retrieving category and sub-category information from an API json file, the API returns category objects with a "parent" attribute. Main category objects have a parent attribute equal to 0, and sub-category objects have the parent attribute equal to t ...

Why isn't offsetTop working for a div within a table in HTML and Javascript?

When using the offsetTop property to get the absolute position of an object, it works fine when the objects are outside of tables. However, if the object is inside a table, it always returns 1. Why does this happen and how can it be avoided? To see an exa ...

Having trouble getting my JavaScript code to function properly on Firefox browser

I have created a script where the cursor automatically moves to the next form field once it reaches its maximum length, in this case 1. Here is the JavaScript code: window.onload=function(){ var container = document.getElementsByClassName("container")[0] ...

Tips on vertically centering a div within another div

Greetings, I wanted to share the code snippet I am currently using: https://jsfiddle.net/hbahar95/27/ .text.ellipsis { position: relative; font-size: 14px; color: black; font-family: sans-serif; width: 250px; /* You can adjust this as needed ...

Unusual phenomenon of overflow and floating point behavior

HTML and CSS Output Example: <div id="float_left"> DIV1 </div> <div id="without_overflow"> DIV2 </div> CSS Styling: #float_left{ float: left; width:200px; background-color: red; } #wit ...

How to create a gelatin-like effect on a rectangle using HTML5 canvas

Currently, I'm working on a platformer game project in JavaScript. The concept involves players as rectangles jumping on and off platforms. While the basic functionality is set up, I'm now aiming to incorporate a unique 'gelatine effect&apos ...

Clicking on "li" to activate and deactivate

Currently utilizing: $('#btnEmpresarial').attr('onclick','').unbind('click'); In order to deactivate a read using javascript.. However, I now require enabling the onclick after the function has completed. Is ther ...

The sendmailR tool has a tendency to insert additional spaces in the HTML body, causing occasional breaks in HTML

I've successfully automated personalized reports for my team, but I'm encountering a minor issue. Some emails contain an extra space in the middle of the HTML body, which can sometimes expose an HTML tag. For instance, "Consul invidunt" may appe ...

transitioning from font-awesome v4 to the latest version, v5

For a while now, I have been utilizing a responsive template. However, I am interested in updating its fa-module from v4 to v5. By downloading the free web package, replacing "font-awesome.min.css" with "all.min.css", and adjusting all references to the ...

Java Script Event Handling Creating Array with Numerous Duplicates

While attempting to recreate the Simon game, I am working on adding click events to an array and testing that Array in a nested function immediately. Initially, everything seems to be functioning correctly. However, after the third run, the array does not ...

The name 'Landbot' cannot be located. Have you meant to type '_landbot' instead?

I'm currently in the process of integrating Landbot into my React.js application with TypeScript. I'm following this [doc] 1. However, I'm facing an issue where the code inside useEffect (new Landbot.Container) is causing an error. 'C ...

Dynamically align text in the center of an image, vertically

I'm trying to create a hover effect where an image and text are displayed in the center of the image when someone hovers over it. Here is how the HTML looks: <article> <div class="entry-content"> <a href="http://www.linktopost.com"> ...

Determine whether the JSON object has been declared

Having trouble determining if the value of values[item]['total'] is defined in a JSON object. The variable item is obtained from the select box value and I am attempting to use an if-else statement to check if values[item]['total'] is ...

"Enhance your user interface with the jQuery UI MultiSelect Widget: Restrict selection to only one option from each optgroup

I'm currently working with a drop-down menu structured like this: <select multiple="multiple"> <optgroup label='category1'> <option value="1">First</option> <option value="2">Second</option> ...

Reset the input field once the message has been successfully sent

My goal is to clear the form message input field after the form is sent. However, it seems to be clearing the data before it has a chance to be sent. Here is the code I'm using: <script> $(function () { $('form#SendForm'). ...

Codeigniter - Ajax request successful in remote server but fails in local server

I am encountering an issue with my web application that makes Ajax requests to a server using Codeigniter-php code. While the Ajax requests work fine on the local server, they do not function properly when the application is hosted on a remote server. The ...

Introduction to Interactive HTML Pinball Game

As a beginner in the realm of computer science, I've recently embarked on creating a simple pinball game. My approach to maneuvering the flippers involves switching between images that depict the flipper in an upwards and downwards position by utilizi ...

dividing a solitary string (plain text only, no HTML) evenly among three separate div containers

Recently, I encountered a frustrating dilemma. I'm trying to split a string between three divs, but they are not equal in height, so I can't divide the string based on character count. To illustrate the issue, I've created a small sketch. ...