Overflow-x does not function properly when used with absolutely positioned divs

I am currently working on a slideshow project and have encountered an issue. The divs in my project are positioned absolutely with left: 100%. While this works perfectly on full screen, the absolute positioning breaks when I resize the screen due to the overflow-x: hidden; applied to the body and html tags. How can I resolve this problem?

Below is the code snippet:

html,
body {
  margin: 0 auto;
  overflow-x: hidden;
}

.slides {
  width: 100%;
  height: 100vh;
  position: absolute;
}

.slide-img {
  width: 100%;
  height: 100%;
}

#slide-2 {
  left: 100%;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">

<head>
  <meta charset="utf-8>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Marseille</title>
  <link rel="stylesheet" href="css/main.css">
</head>

<body>
  <div class="slides" id="slide-1">
    <img class="slide-img" src="media/slideshow/image-1.jpg">
  </div>
  <div class="slides" id="slide-2">
    <img class="slide-img" src="media/slideshow/image-2.jpg">
  </div>
  <div class="slides" id="slide-3">
    <img class="slide-img" src="media/slideshow/image-3.jpg">
  </div>
  <div class="slides" id="slide-4">
    <img class="slide-img" src="media/slideshow/image-4.jpg">
  </div>
</body>

</html>

Answer №1

To ensure all three absolutely positioned DIVs are displayed properly, you must specify the left parameter for each of them. If you fail to do so, DIV #3 and 4, which currently have a left: 0 setting, may overlap and cover DIV #1. In the code snippet provided below, I have set the left parameters to 25/50/75% for DIVs 2-4 as an example. You may need to adjust these values to at least 100% or higher based on how you want the elements to slide into view.

html, body {
  margin: 0 auto;
  overflow-x: hidden;
}

.slides {
  width: 100%;
  height: 100vh;
  position: absolute;
}

.slide-img {
  width: 100%;
  height: 100%;
}

#slide-2 {
  left: 25%;
}
#slide-3 {
  left: 50%;
}
#slide-4 {
  left: 75%;
}
  <div class="slides" id="slide-1">
    <img class="slide-img" src="http://placehold.it/800x500/fb8">
  </div>
  <div class="slides" id="slide-2">
    <img class="slide-img" src="http://placehold.it/700x500/bf8">
  </div>
  <div class="slides" id="slide-3">
    <img class="slide-img" src="http://placehold.it/900x500/8bf">
  </div>
  <div class="slides" id="slide-4">
    <img class="slide-img" src="http://placehold.it/600x500/f8b">
  </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

Exploring the wonders of multer in a nodejs application

I am having trouble uploading a file from my webpage to a Node server. Although I can see that the form data is reaching the server's router, No file seems to be saved in the upload folder. What could I be doing wrong? //router section const expr ...

The issue with CSS right alignment not functioning as expected

My attempt to align text to the right using a CSS rule is not working as expected when applied to a font within a cell. Can anyone help me troubleshoot this issue? Take a look at my code snippet below: CSS: .font1 { font-size: 60px; text-align: ...

Customizing Navigation Color on Laravel Websites for Staging and Live Servers

I am seeking a solution to change the color of the Laravel navigation bar depending on whether it is the live or staging server. Our current setup involves testing code on a staging server before pushing it to the live server in production via Bitbucket. ...

An individual in a chat App's UserList experiencing issues with incorrect CSS values. Utilizing Jquery and socketio to troubleshoot the problem

Currently, I am testing a new feature in a chat application that includes displaying a user list for those who have joined the chat. The challenge is to change the color of a specific user's name on the list when they get disconnected or leave the cha ...

Permitting the user to remove an option from the antd select widget

I have integrated the antd select component in my React application and I am looking to add a delete option for users. For more details, please refer to the image below:https://i.sstatic.net/ZP4PP.png This is how I attempted to implement it: {tasks.map( ...

Merge web address when form is sent

I'm currently working on a search application using the Django framework and the Yelp API as my backend, which is functioning properly. However, I am facing some challenges with the frontend development, specifically integrating Leaflet.js. My search ...

Divide the width by half in a CSS grid layout with 3 columns

Is it possible to replicate the layout shown in the image using CSS grid? https://i.sstatic.net/XSoE8.png ...

Troubleshooting Display Problems when Switching Bootstrap Themes in ASP.NET MVC

I recently made changes to my MVC project by switching the default Bootstrap theme to Bootswatch - Cosmos. However, I am facing an issue with the Navbar as shown in the image below: View Header Display Issue Image Initially, I was using Bootstrap 3.0 and ...

Excessive gap underneath the picture

Check out my webcam at this link: For the source code, visit: All the html5, css3 and js are contained in a single file. Recently upgraded from XHTML to HTML5, but now there is an unexpected space below the image. It appears as a yellow line when hoveri ...

Why is the reverse sticky navbar not visible after the position changes from fixed to static?

Scenario In the setup, I've implemented a reverse sticky navbar where it remains in position:fixed at the top. However, once the top of a specific div container touches the bottom of the navbar, I switch it to position:static using jQuery. Challenge ...

setting different iframe widths for desktop and mobile views

I am working with an iframe and facing a challenge. I want to make it full screen width on mobile devices, but only half the screen width on a normal monitor (100% and 50%, respectively). The minimum specification for the mobile device would be iPhone, alt ...

What is the best way to incorporate a highlighting bar below a link for emphasis?

How can I create a highlight effect above a link in the status bar, similar to what is seen on Fiddle sites? The highlight should remain above the active link and move to the link the mouse hovers over. Here is an example image of what I am trying to achie ...

The leftward relocation of 3 boxes is required

Help needed! I created 3 boxes that appear upon clicking a button, but they are not aligned properly. They need to be shifted a bit to the left. My attempt to adjust this using a large div with left:5%; did not work. If you're unsure about the issue, ...

Retrieving Dropdown Value in Bootstrap 5: How to Obtain the Selected Item's Value from the Dropdown Button

I am having a slight issue with my dropdown button where I am trying to display the selected item as the value of the dropdown button. The Flag Icon and Text should be changing dynamically. I have tried some examples but it seems that it is not working as ...

Show a dynamic dropdown box using AJAX if a specific variable is present

I am currently working on implementing an ajax call for a dynamic dropdown box. Once the variable $place is available, it triggers an ajax call to populate the dropdown box. My goal is to pass the variable $place to listplace.php, encode it as JSON data ...

JQuery AJAX click event not triggering

I'm currently working on a project to create a dynamic website where users can update text fields directly from the site. However, I've encountered an issue on the 'admin' page where nothing happens when the button is pressed to set the ...

Latest versions of Bootstrap are facing issues with the functionality of the Carousel feature

I'm struggling to create a basic carousel, but for some reason, it's not functioning properly. I attempted to use the sample code provided by Bootstrap's documentation, but it doesn't behave as expected (slides won't transition and ...

How can we incorporate "req.getParameter" within a "for loop" to store data in the database based on the user-defined quantity provided in another servlet?

Currently, I am working on a system where teachers have the ability to edit exams they have created. However, an issue arises when trying to save the questions and answers, as it depends on the number of questions in the exam. While requesting variables f ...

Unable to change the color of InputBase component's placeholder in React.js

I've been attempting to modify the color of the placeholder in an inputbase. I came across several methods online and tried implementing them, but none have been successful. Below are the codes I have tried. <InputBase id="input-id&quo ...

Mixin for conditional input styles in Sass

I am interested in developing a conditional sass class that can be customized based on an argument provided. I am unsure about the terminology for this feature. For instance: <img class="width-200" .../> I would like to create a sass mixin that tak ...