When CSS and HTML are the only tools used, the content tends to jump upon loading

I have a unique internal ticketing system that has restrictions on using JavaScript and limited CSS tags. Due to this limitation, I needed to explore different methods of creating a simple CSS slider for images using only HTML and CSS.

However, I encountered an issue where clicking on the Next/Prev button causes a jump effect before loading the next image. I've tried using max-width: 100%; height: auto;, but so far, it hasn't solved the problem.

Does anyone have any advice on how to prevent the picture from moving when the next image is loaded? Any help would be greatly appreciated!

<style> 
  #slidepicswrap {
     width:640px;
     height:450px;
     margin:0 auto;
     position:relative;
     font-family:verdana, arial, sans-serif;
 } 

 #slidepicswrap #slides {
     position:absolute;
     left:0;
     top:0;
     height:450px;
     width:640px;
     overflow:hidden;
     text-align:center;
 } 

 #gallerywrapper #gallery div {
     width:640px; height:900px; 
     padding-top:10px; 
     position:relative;
 } 

 #gallerywrapper #gallery div img {
     clear:both; 
     display:block; 
     margin:0 auto; 
     border:0;
 } 

 #gallerywrapper #gallery div h3 {
     padding:10px 0 0 0; 
     margin:0; 
     font-size:18px;
 } 

 #gallerywrapper #gallery div p {
     padding:5px 0; 
     margin:0; 
     font-size:12px; 
     line-height:18px;
 } 
a {
  text-decoration: none;
  display: inline-block;
  padding: 8px 16px;
}

a:hover {
  background-color: #ddd;
  color: black;
}

.previous {
  background-color: #f1f1f1;
  color: black;
  display:inline;
  float:left;
  margin-left:80px;
}

.next {
  background-color: #4CAF50;
  color: white;
  display:inline;
  float:right;
  margin-right:80px;<span id="CmCaReT"></span>
  text-decoration:none;
}

.round {
  border-radius: 50%;
}
</style>
<div id="slidepicswrap">
<div id="slides">
<div id="pic1"><img src="https://unsplash.it/g/500/350?random" alt="Image 1" width="500" height="350" /> <a class="previous" href="#pic5" rel="nofollow">&lt;</a> <a class="next" href="#pic2" rel="nofollow">&gt;</a>
<h3>Image 1</h3>
<p>Text of image 1.</p>
</div>
<div id="pic2"><img src="https://unsplash.it/g/500/350" alt="Image 2" width="500" height="350" /> <a class="previous" href="#pic1" rel="nofollow">&lt;</a> <a class="next" href="#pic3" rel="nofollow">&gt;</a>
<h3>Image 2</h3>
<p>Text of image 2.</p>
</div>
<div id="pic3"><img src="https://unsplash.it/g/500/350?random" alt="Image 3" width="500" height="350" /> <a class="previous" href="#pic2" rel="nofollow">&lt;</a> <a class="next" href="#pic1" rel="nofollow">&gt;</a>
<h3>Image 3</h3>
<p>Text of image 3.</p>
</div>
</div>
</div>

Answer №1

It seems that your image is jumping around due to the padding-top not being fixed, causing the total height of #slide to change.

<div id="slidepicswrap">
        <div id="slides">
            <div id="pic1">
                <img src="https://unsplash.it/g/500/350?random" alt="Image 1" width="500" height="350" />
                <div>
                    <a class="previous" href="#pic5" rel="nofollow">&lt;</a>
                    <a class="next" href="#pic2" rel="nofollow">&gt;</a>
                </div>

                <h3>Image 1</h3>
                <p>Text of image 1.</p>
            </div>
            <div id="pic2"><img src="https://unsplash.it/g/500/350" alt="Image 2" width="500" height="350" />
                <div>
                    <a class="previous" href="#pic1" rel="nofollow">&lt;</a>
                    <a class="next" href="#pic3" rel="nofollow">&gt;</a>
                </div>
                <h3>Image 2</h3>
                <p>Text of image 2.</p>
            </div>
            <div id="pic3"><img src="https://unsplash.it/g/500/350?random" alt="Image 3" width="500" height="350" />
                <div>
                    <a class="previous" href="#pic2" rel="nofollow">&lt;</a>
                    <a class="next" href="#pic1" rel="nofollow">&gt;</a>
                </div>
                <h3>Image 3</h3>
                <p>Text of image 3.</p>
            </div>
        </div>
    </div>

<style>
        #slidepicswrap {
            width: 640px;
            height: 450px;
            margin: 0 auto;
            position: relative;
            font-family: verdana, arial, sans-serif;
            /* background: violet; */
            overflow: hidden;
        }
        
        #slidepicswrap #slides {
            position: absolute;
            left: 0;
            top: 0;
            height: 450px;
            width: 640px;
            overflow: hidden;
            text-align: center;
        }
        
        #gallerywrapper #gallery div {
            width: 640px;
            height: 920px;
            padding-top: 10px;
            position: relative;
        }
        
        #gallerywrapper #gallery div img {
            clear: both;
            display: block;
            margin: 0 auto;
            border: 0;
        }
        
        #gallerywrapper #gallery div h3 {
            padding: 10px 0 0 0;
            margin: 0;
            font-size: 18px;
        }
        
        #gallerywrapper #gallery div p {
            padding: 5px 0;
            margin: 0;
            font-size: 12px;
            line-height: 18px;
        }
        
        a {
            text-decoration: none;
            display: inline-block;
            padding: 8px 16px;
        }
        
        a:hover {
            background-color: #ddd;
            color: black;
        }
        
        .previous {
            background-color: #f1f1f1;
            color: black;
            display: inline;
            float: left;
            margin-left: 80px;
        }
        
        .next {
            background-color: #4CAF50;
            color: white;
            display: inline;
            float: right;
            margin-right: 80px;
            text-decoration: none;
        }
        
        .round {
            border-radius: 50%;
        }
        
        img {
            padding-top: 10px;
        }
    </style>

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

Dropping and dragging in the Dojo for the nested lists

Within my HTML code, I am using the Dojo drag and drop feature to sort attributes and move them to another section. However, I am having trouble figuring out how to sort the sections themselves. Here is the structure that I have created: <ul accept=" ...

Using $_POST method to navigate within the same web page

<!doctype html> <html> <head> <meta charset="UTF-8"> <title>PHP links</title> <?php echo '<div style="background-color:#ccc; padding:20px">' . $_POST['message'] . '</div>'; ...

"Access Denied: Error 403 - Forbidden" encountered during the CSS minification and bundling process in ASP.NET Web Forms

After migrating my ASP.NET web forms application from a managed VPS to AWS EC2 using AWS Elastic Beanstalk, I encountered an issue with CSS bundling and minification. While the JavaScript was successfully bundled and minified on the Amazon server, the CSS ...

Attempting to insert an image logo within a Bootstrap logo design

Trying to customize my nav bar with a logo instead of text, but my attempts have been unsuccessful so far. Here is what I have tried: <li class="nav-item"> <a class="nav-link active" aria-current="page" img src=&q ...

What is the best method for accessing and showcasing images in an ionic app?

Having trouble displaying images after executing the following command: ionic run ios The default ionicframework template is being used with the sidemenu, and no changes have been made to the app directory structure. An inline css is being used to speci ...

Retrieving chosen items from dynamically generated checkboxes using Angular 2+

I have a piece of HTML code where I am trying to capture the value of all selected checkboxes whenever any checkbox is checked or unchecked, triggering the (change) event. <div class="checkbox checkbox-primary" *ngFor="let category of categories; let i ...

Retrieve the content of each div element based on its text value

In this particular structure, I have: <table id="thetable"> <tr> <td> <div> <div>some text</div> <div> <div></div> ...

How can I remove the gaps between Bootstrap panels on a website?

The Issue https://i.stack.imgur.com/I5EFR.png My problem is with the spacing between the panels, highlighted in red. I've attempted to remove them by using the following CSS: .panel { margin-top: 0; margin-bottom: 0; padding-top: 0; ...

Arrange the image in a way that flows smoothly with the text

I want to achieve the effect of having a picture of a Pen positioned behind the text "Create" on the left side. It looks good at full size, but the positioning gets messed up when the screen size is adjusted. How can I make it responsive so that the image ...

Select the M3 element in a ul using CSS targeting

I am working with a ul containing some li elements, here is an example: <ul class="M199 WIDTHBOX1 5ColumnBox"> <li class="M2"> <a class="M2" href="about-1561.aspx" target="">About</a> <div class="WIDTHBOX2" s ...

What is the best way to position text messages at the bottom of a chat window?

I am currently working on a chat window, and while setting the height to 100% works perfectly, I am facing difficulty in making the messages appear at the bottom. HTML: <div class="d-flex justify-content-center"> <div class="container containe ...

Guide to updating a SQL value via a button click using PHP

Unsure of the amount of code required for my project, so any guidance is appreciated! I am currently working on the admin-end of a PHP project that utilizes SQL. The admin has the ability to update, remove, and promote normal users to administrators (some ...

Issue with Android date input field not resetting the value

When testing in Android Tablet (version 4.1.2), I encountered a strange issue with an input date field that looks like this: <input type="date" value="2013-06-10"/>. Upon clicking on the field and trying to set a new date, instead of replacing the o ...

Tips for filling in the empty space next to an image with a negative left margin using text

Our goal is to create a layout where an image overflows from its container, leaving space for text to fill in the gap created by the offset image on the left side. https://i.sstatic.net/2dvLa.jpg Currently, our structure looks like this: <div class=" ...

Prevent selection of specific weekdays in Kendo grid calendar

When editing a record in a Kendo grid with a date field, is there a way to only allow the selection of Monday and disable all other days of the week? ...

Tips on creating a post that can be viewed exclusively by one or two specific countries

I'm stumped on how to create a post that is visible only to specific countries. How can I code it to determine the user's country without requiring them to make an account? Any advice or hints would be greatly appreciated. ...

Error: The use of import statement is not allowed outside a module in JavaScript due to a Syntax

I'm just beginning my journey with React, starting from scratch without setting up all the necessary dependencies. Initially, I used CDNs in my html file but now I want to learn how to import React and ReactDOM into my local setup and also link CSS fi ...

Leveraging JSON for fetching distinct identifiers from a database

When a user hovers over a parent span containing an empty img tag, I use JSON and jQuery to retrieve the src of the image from the database. The issue arises when the retrieved src is applied to all looped span images on the same page, instead of each imag ...

Looking to leverage iframes in your Javascript code?

Currently, I am implementing a JSP popup window using JavaScript with an iframe to display a table of multiple records. However, when I disable the table of multiple records, it does not prevent the onclick function (hyperlink). The code snippet is provid ...

Issue with Caching during Javascript Minification

I Have ASP.Net MVC 3 App. Utilizing YUICompressor.Net for compressing Javascript and CSS files post build with MSBuild. The minimized javascript file is named JSMin.js and the CSS file is CssMin.css. In my master page, I reference these files as shown bel ...