"Revamping CSS Slideshows with Custom Backgrounds

For my page layout design, I referenced the following examples:

http://jsfiddle.net/nimbu/KEqSF/?utm_source=website&utm_medium=embed&utm_campaign=KEqSF

I am trying to create different backgrounds for each slide in order to have a unique background displayed with each slide transition. However, I am facing an issue where only one background can be set and subsequent slides inherit the same background image. I tried changing the background image for each slide individually:

#i1 { background-image: url("images/bg1.jpg") no-repeat center center fixed;}
#i2 { background-image: url("images/bg2.jpg") no-repeat center center fixed;}
#i3 { background-image: url("images/bg3.jpg") no-repeat center center fixed;} 

This method did not work as expected. I also attempted to add an image to each slide and use it as the background:

<!-- First Page #a1 -->
            <div id="i1" class="page">
                    <img src ="images/bg1.jpg" id="bg" alt="">
<!-- Second Page #a2 -->
            <div id="i2" class="page">
                    <img src ="images/bg2.jpg" id="bg" alt="">
<!-- Third Page #a3 -->
            <div id="i3" class="page">
                    <img src ="images/bg1.jpg" id="bg" alt="">

With the following CSS:

img {
max-width: 100%;
}

#bg { position: fixed;
z-index: 0;
top: 0;
left: 0; }

.bgwidth { width: 100%; }
.bgheight { height: 100%; }

Unfortunately, this approach also resulted in a similar error. I'm uncertain about how to proceed further as I continue to learn CSS/HTML. Any guidance would be greatly appreciated! Thank you in advance!!!

EDIT: I have shared my current js fiddle link in the comments section. My goal is to display a different background on the contact slide while keeping the gallery slide with a solid color background. Unfortunately, I haven't been successful in achieving this yet!

Answer №1

Take a look at this demo on Fiddle: http://jsfiddle.net/9sk2hb8p/

I modified your script to use "background" in place of "background-image":

#img1 { background: url("http://lorempixel.com/800/600/nature") no-repeat center center fixed;}
#img2 { background: url("http://lorempixel.com/800/600/city") no-repeat center center fixed;}
#img3 { background: url("http://lorempixel.com/800/600/people") no-repeat center center fixed;}

(Your syntax wasn't accurate for background-image, but it was correct for background)

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

access pictures from a different directory using JavaScript

I am working with an images array that contains three jpg files. I am trying to set the background image of a class called pic using images from the array. The issue I'm facing is that the images are stored in an images folder with the URL images/. I ...

Implementing dynamic dependencies for form fields using JavaScript

I'm currently developing an application using Django that incorporates dependent fields in forms. My intention is to integrate the plugin provided by this resource. However, the specific field dependencies may differ based on the selections made by us ...

Prevent button interaction until completion of modal animation using Bootstrap 4

I have incorporated a Bootstrap 4 modal in my website to display a large navigation menu. The navigation is triggered by a toggle button with a CSS animation that transforms a hamburger icon into an X. However, I encountered an issue where if the button i ...

React-Router Refreshes Component When Moving To Another Route

I am currently in the process of familiarizing myself with React and Redux. My current setup involves the following: Within the store's state, there is a property named 'activeAction' which stores a number value. The 'activeAction&apos ...

formatting a JSON response in an HTML document

Can someone assist me with formatting the json return in html from my jquery json result? Please see below for my html code: $("document").ready(function(){ $(".js-ajax-php-json").submit(function(){ var data = { "action": "testerer" }; ...

``Is there a way to retrieve only a specific portion of an HTML

Greetings everyone! Here is a snippet of my sample code: <?php $html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/x ...

Incapable of stacking one canvas on top of another

I'm new to javascript and looking for help with positioning a canvas element behind another. The code I have may be a bit messy, so any assistance is greatly appreciated. My goal is to have the canvas named "myCanvas" appear behind "coinAnimation". Th ...

Issue with the parent element size when containing an image smaller than 100% width

This is the default appearance with all images set to 100% width: image description here These images must maintain their aspect ratio, so I can only use percentages for sizing. When the image width is set to 60%, it looks like this: image description ...

Leveraging the back button in an AngularJS Mobile SPA

Utilizing AngularJS for my Single Page App (SPA), I am currently exploring the most effective way to handle the back button functionality on mobile devices. My setup involves a single JavaScript file, one HTML page, and no partials. The content is reveale ...

Transforming a Multi-Dimensional Array into an HTML Table

Experimenting with a new idea. I hope the solution is straightforward; I just can't seem to figure it out. Imagine I have an array like this: var items = [[1,2,3],[4,5,6],[7,8,9],[10,11,12]]; My goal is to rearrange the data so that it looks like t ...

Identifying the Ajax request URL

I am working on a project where I have an HTML document that retrieves content from a PHP file using an AJAX call. The key portion of my code can be seen below: default.html : /*more code above*/ var PHP_URL = "content.php"; var Content = document.getEle ...

"Conceal or reveal content with a toggle

Struggling to implement a simple hide and reveal effect in my JavaScript learning journey. Currently, the effect is only cancelled by clicking on another div with the same reference. Take a look at my JavaScript code: var $ = jQuery; $(document).ready(f ...

Is there a problem with the Drag and Drop API?

So here's the deal: I've encountered a problem with the HTML5 Drag and Drop API. In short, besides the essential dragstart, dragover, and drop events, there are three more events - mousedown, mouseup, and mouseleave - that are crucial for achiev ...

Tips for securely saving your login information on social media apps

Currently, I am developing an Android Social Media application. The framework is in Java and the main data is displayed through a WebView of the mobile version of my social media website. One question I have is related to saving a user's password. Is ...

Creating a collapsible accordion feature with jQuery using a specific HTML layout: wanna learn how?

I am looking to create an accordion effect with the structure provided below. The goal is to have the corresponding article toggle when clicking on .booklist>li>a, allowing only one article to be open at a time. Can someone assist me with writing thi ...

difficulties switching content between different screen sizes

Having trouble with hidden-xs and visible-xs-* classes not working as expected. Even a simple code snippet like the following doesn't hide the content: <div class="hidden-xs"> test test test </div> Even when scaling down my window to ...

The issue of stuttering arises in Safari when using a combination of size and translate transitions

When applying transitions to an element and adjusting the width and/or height along with -webkit-transform:translate3d, there is a noticeable stutter in the transition animation. It seems like the width/height change is animated first, then partially trans ...

Minimize white spaces when validating input fields in a form using Javascript

I'm currently facing a challenge with JavaScript, specifically regarding achieving five tasks without using jQuery. Despite trying various RegExp codes, none have successfully worked for me so far. Let's begin with the first task (number 1): El ...

Position the Bootstrap Button on the right side of the navbar

Hey there, I'm completely new to the world of HTML/CSS and this is my first project ever. I welcome any constructive criticism that can help me improve in the future. Now onto my current dilemma: I've decided to use Bootstrap because it seems u ...

Adaptable filler text

I am looking for a placeholder that can hold changing values: <input type="text" placeholder="Search by Name, Order Number and Location" style="width: 300px" /> <input type="text" placeholder="Search by Name" style="width: 300px" /> My goal ...