"Looking to spice up your website with a dynamic background-image

I've encountered a problem with my CSS code for the header's background image. Despite trying various methods to create a slideshow, nothing seems to be working. Can someone provide guidance? I have four banner images named banner1, banner2, banner3, and banner4.jpg stored in the IMAGES/banner1.jpg folder.

$(document).ready(function(){
  // Add smooth scrolling to all links
  $("a").on('click', function(event) {

    // Make sure this.hash has a value before overriding default behavior
    if (this.hash !== "") {
      // Prevent default anchor click behavior
      event.preventDefault();

      // Store hash
      var hash = this.hash;

      // Using jQuery's animate() method to add smooth page scroll
      // The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
      $('html, body').animate({
        scrollTop: $(hash).offset().top
      }, 800, function(){
   
        // Add hash (#) to URL when done scrolling (default click behavior)
        window.location.hash = hash;
      });
    } // End if
  });  
});
body
{
background-color: #808080;

}
p
{
!-- 
}
p.homeclassheader
{
font-weight: bold;
font-size: 35px;
font-family: Tahoma, Geneva, sans-serif;
line-height: 150%;
text-align: center;
color: white;
text-shadow: 2px 2px 3px grey;
word-spacing: 3px;
letter-spacing: -1;
font-variant: small-caps;
}
header
{
text-align:center;
text-shadow: 2px 2px 3px grey;
color: silver;
padding: 20px 0px 0px 0px;
border-bottom: #808080;
position: fixed;
border-bottom: 2px solid #00FFF5;
top: -10;
height: 150px;
left: -10;
width: 105%;
z-index:5;
}
header a
{
text-decoration: none;
text-align:center;
text-shadow: 2px 2px 5px grey;
font-weight: bold;
font-size: 40px;
font-family: Tahoma, Geneva, sans-serif;
line-height: 100%;
color: white;
word-spacing: 3px;
letter-spacing: -1;
font-variant: small-caps;

}
hr {
    border: 0;
    height: 2px;
    background-image: linear-gradient(to right, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0));
}
header a:visited
{
text-decoration: none;
text-align:center;
text-shadow: 2px 2px 3px grey;
color: silver;

}
article
{

}
article.homeclass
{
text-align:center;
color: silver;
padding: 0px 20px 0px 20px;
    background-color: #393E46;
border-bottom: 2px solid #00FFF5;
border-top: 2px solid #00FFF5;
height: 350px;
float: left;
width: 75%;
max-width: 350px;
margin: 0 auto;
}
article.homeclass img
{
float: right;
margin-left: 30px;
margin-right: 25px;
margin-top: -15px;
margin-bottom: 0px;
}
ul.menu {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
font-weight: bold;
font-size: 15px;
font-family: "Comic Sans MS", cursive, sans-serif;
    background-color: #393E46;
position: fixed;
top: 180;
width:99%;
z-index:5;

}

ul.menu li {
    float: left;
}

ul.menu li a {
    display: block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
border-bottom: 2px solid #00FFF5;
    -moz-transition: background-color .3s ease-in;
-webkit-transition: background-color .3s ease-in;
-o-transition: background-color .3s ease-in;
transition: background-color .3s ease-in;
}

ul.menu li a:hover {
    background-color: #00ADB5;
    color: black;
-moz-transition: background-color 0.01s;
-webkit-transition: background-color 0.01s;
-o-transition: background-color 0.01s;
transition: background-color 0.01s;
}

a:visited
{
text-decoration: none;
}

a:link
a:focus
a:hover
a:active
footer a
{
text-decoration: none;
text-align:center;
color: #00FFF5;
}
footer
{
text-align:center;
color: silver;
    background-color: #393E46;
padding: 10px 0px 0px 0px;
border-bottom: #808080;
position: absolute;
bottom: 0px;
height: 25px;
border-top: 2px solid #00FFF5;
width: 105%;
}
<HTML>
<HEAD>
<LINK rel="stylesheet" type="text/css" href="CSS/styles.css">
<TITLE>Las Vegas | Home</TITLE>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="JAVASCRIPT/scrolleffect.js"></script>

</HEAD>
<BODY>
<HEADER>
<style>
header {
background-image: url("IMAGES/banner1.jpg");
}
</style>
<a name="top"><H1>Las Vegas</H1></A>
</HEADER>
<div id="home"></div>
<br>
<br><br><br><br><br><br><hr><br><br>
<br>
<ARTICLE class="homeclass">
<p class="homeclassheader">Accommodation</p>
<hr>
<p class="class2">Hotel 1</p>
<p class="class2">Hotel 2</p>
<p class="class2">Hotel 3</p>
<hr>
</ARTICLE>
<br><br><br><br><br><br>
<FOOTER>
<NAV>
All Copyright reserved to Dylan 2017 &copy;<br>
</NAV>
</FOOTER>

</BODY>
</HTML>

Answer №1

In this code snippet, you can see how to implement a basic slide show on your webpage. It's crucial to remember to properly link the image source, especially if it is located in an 'images' folder. For instance, using src="./images/lifeofpi.jpg" indicates that the image 'lifeofpi.jpg' is stored in the 'images' directory. Additionally, ensure that the <link rel> tag is placed within the head section of your website for an automatic slideshow feature.

<!DOCTYPE html>
<html>
<title>Test</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/html/styles.css">
<style>
.mySlides {display:none;}
</style>
<body>

<h2 class="w3-center">Automatic Slideshow</h2>

<div class="w3-content w3-section" style="max-width:500px">
<img class="mySlides" src="img_la.jpg" style="width:100%">
<img class="mySlides" src="img_ny.jpg" style="width:100%">
<img class="mySlides" src="img_chicago.jpg" style="width:100%">
</div>  

<script>
var myIndex = 0;
carousel();

function carousel() {
var i;
var x = document.getElementsByClassName("mySlides");
for (i = 0; i < x.length; i++) {
   x[i].style.display = "none";  
}
myIndex++;
if (myIndex > x.length) {myIndex = 1}    
x[myIndex-1].style.display = "block";  
setTimeout(carousel, 5000); // Change image every 5 seconds
}
</script>

</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

Show a dynamic modal with a widget displayed inside

I am facing an issue with my Angular.js website that is filled with a multitude of widgets. Each widget consists of a template.html file paired with a controller.js file to form an angular module. These widgets are utilized on a dashboard where users have ...

Passing state updates between child components by utilizing the useReducer hook and dispatching actions

Check out this interactive example on CodeSandbox with the code provided and highlighted linting issues: https://codesandbox.io/s/react-repl-bw2h1 Here is a simple demonstration of my current project setup. In a container component, there is an important ...

Step by step guide on rotating a plane with texture by 90 degrees

I've been working on developing an fps game, but I'm encountering an issue where the floor disappears from the scene when I try to rotate it close to 90 degrees. Here's the code snippet responsible for creating the plane. var colorMap = new ...

What is the best way to generate this arc using CSS3?

What is the most effective method for creating this unique shape using CSS3? The square image should be clearly defined. We greatly appreciate any insight you can offer. EDIT: I have put in a lot of effort, but standard CSS methods are not getting me t ...

Displaying text on an image when hovering over it

I have tried various solutions that I came across, but none of them have been successful so far. My goal is to display dynamic text over an image when the user hovers over it. Additionally, I would like to change the hover color. Currently, the text is alw ...

Uncovering the websocket URL with NestJS and conducting postman tests: A step-by-step guide

Creating a mean stack application using NestJS involves utilizing websockets. However, testing websockets in Postman can be confusing. Typically, I test route URLs in Postman and get output like: "http://localhost:3000/{routeUrl}". But when it comes to tes ...

Does the web browsing context within an iframe get reset when updating or specifying the src or srcDoc attributes?

Based on the official HTML5 specifications, it is stated that: When an iframe element is removed from a document, the user agent must discard the nested browsing context, if any This leads me to question whether changing the src or srcDoc attributes al ...

Using Selenium Webdriver to set a cookie with a Chrome extension

I have been experimenting with a Chrome extension in order to set a cookie when I use a Selenium Webdriver instance to open a page. Despite trying various methods suggested on different Stack Overflow posts, none of them seem to work as the cookie does not ...

updating a div with URL redirection instead of global redirect

I am facing an issue with redirecting my website flow to the login page when a user clicks any link on the page after the session has expired (either due to timeout or manual logout from another window). In an attempt to solve this, I inserted the followi ...

Use flexbox to manage the width of containers and control the wrapping of elements

Hello, I am a newcomer to utilizing flexbox in CSS. I have these "boxes" that need to maintain their width and wrap when the screen size is small. On a large screen: On a small screen: .container { margin-top: 1em; display: flex; justi ...

Trouble with value updating in PostgreSQL with NodeJs

var express = require('express'); var app = express(); var pg = require('pg'); var connectionString = "postgresql://postgres:sujay123@localhost:3001/redc"; app.use(express.static('public')); app.get('/index.h ...

Having trouble retrieving the $scope value in HTML, even though it was assigned within the success function of $http.post

Having trouble accessing the values of $scope properties after a successful $http post in index.html file. Here is the code snippet for reference, any help in resolving this issue would be greatly appreciated as I am new to AngularJs var app = angular.m ...

Expand Bootstrap navbar search box outside collapse menu

Currently, I am working on designing a navigation bar that showcases my brand on the left side, a full-width search bar in the center, and additional pages on the right. I am facing challenges in maintaining the full-width of the search bar without causing ...

Tips for adjusting the width of ngx bootstrap modal?

Is there a way to adjust the width of my ngx bootstrap modal so that it is not fixed? I have attempted to modify it in the HTML code below but without success: Here's the HTML snippet: <div bsModal #childModal="bs-modal" class=" ...

Tips for utilizing AJAX to send two values to PHP for comparison

How can I use AJAX to compare two values (#cpassword and #password) to see if they match? I've been attempting it, but it seems like I only get the value of '#cpassword'. Here is my cpassword-check.js file: // Validate confirm password whi ...

Leveraging the yeoman-generator variable within the template that is being generated

When creating an angularJS project with yeoman, I pass an argument to the generator which I retrieve from the main generator's script (index.js) using: this.argument('name', { type: String }); I can access this parameter within index.js as ...

I'm currently working on incorporating a rating system into my Vue.js project, but I am struggling to successfully pass the rating values

After carefully reviewing the documentation, I implemented the code below. While I am successfully retrieving data for enquiryDesc, I am encountering null values for rating. Despite trying various troubleshooting steps, the issue with null values persists. ...

"Error in react-three-fiber: Only the last mesh retains its model, all others are

Currently, I am working on a React application where I am using react-three-fiber to visualize data in a 3D environment. My goal is to create various models by passing data representing their characteristics as props into components. However, I am encounte ...

Gain access to a variable within an AngularJS directive's scope

I am facing an issue with the following directive var chartDir = function () { return { scope: { stat: '=' }, link: function (scope, element, attr) { console.log(scope); return; } } HTML < ...

Improving the Performance of HTML/CSS Animations - Enhanced Animation Speed

I have created an HTML page with CSS animation and transitions. <div class="container-fluid" id="team"> <div class="row first"> <div class="wrapper"></div> </div> <div class="row second"> <div class="wrapper" ...