Guide to building an image carousel using HTML and CSS

Having trouble incorporating an image slider into my website. The images are 1650 by 350 in size and there are a total of 4 images with these dimensions. I attempted to implement this using HTML and CSS, but the images are not sliding automatically as intended. I tried to set up automatic movement in the CSS file, but it doesn't seem to be working. Any ideas on what could be causing this issue?

CSS:

.slider {
    width: 1600px;
    height: 350px;
    background-color: yellow;
    margin-left: auto;
    margin-right: auto;
    margin-top: 0px;
    text-align: center;
    overflow: hidden;
}

.image-container {
    width: 2000px;
    background-color: pink;
    height: 350px;
    clear: both;
    position: relative;
    -webkit-transition: left 2s;
    -moz-transition: left 2s;
    -o-transition: left 2s;
    transition: left 2s;
}

.slide {
    float: left;
    margin: 0px;
    padding: 0px;
    position: relative;
}

#slide-1:target~.image-container {
    left: 0px;
}

#slide-2:target~.image-container {
    left: -1600px;
}

#slide-3:target~.image-container {
    left: -3200px;
}

#slide-4:target~.image-container {
    left: -4800px;
}

.buttons {
    position: relative;
    top: -20px;
}

.buttons a {
    display: inline-block;
    height: 15px;
    width: 15px;
    border-radius: 50px;
    background-color: lightgreen;
}

HTML:

<div class="slider">
  <span id="slide-1"></span>
  <span id="slide-2"></span>
  <span id="slide-3"></span>
  <span id="slide-4"></span>
  <div class="image-container">
    <img src="./assets/slider-1.jpg" class="slide" width="1650" height="350" />
    <img src="./assets/slider-2.jpg" class="slide" width="1650" height="350" />
    <img src="./assets/slider-3.jpg" class="slide" width="1650" height="350" />
    <img src="./assets/slider-4.jpg" class="slide" width="1650" height="350" />
  </div>
  <div class="buttons">
    <a href="#slide-1"></a>
    <a href="#slide-2"></a>
    <a href="#slide-3"></a>
    <a href="#slide-4"></a>
  </div>
</div>

Answer №1

Have you considered implementing this? Simply adding the necessary CSS and script will provide you with a fully functional carousel without any extra effort.

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

Problems with CSS text scrolling

We have a client who wants a marquee-style scrolling text banner, and I tried using CSS animations to achieve it. However, I encountered some quirks that I'm struggling to fix. If you want to take a look at the issue, here is the link: https://jsfidd ...

"Transitioning from Bootstrap version 3.3.7 to the latest Bootstrap version 4.1.3

Everywhere I look, it says that Bootstrap 4.1 is compatible with Bootstrap 3, but when I update my project to the newer version, a lot of things stop working, such as this cookie consent feature. @{ Layout = ""; } @using Microsoft.AspNetCore.Http ...

Learn how to dynamically insert a source for an IMG element in Laravel using Blade by utilizing a variable returned from a view

I have been working on a website that displays various products and I utilize Blade for creating dynamic product pages. Here is an example of how I do it: Route::get('/products/{product}', function ($product) { return view('products/pr ...

Is there a way to extract the data enclosed by "<div>" and "</div>" utilizing python's sgmllib or parser module?

This is the HTML snippet provided: <div id="wrap"> <div id="content"> <h1>head</h1> <ul class="jobpara"> <li class="floatl"><span>time:</span>2013-08-13</li> <li clas ...

What is the best way to implement an image in React?

I've organized all my images into an "images" folder within the src directory, but I'm having trouble using them with different methods. None seem to be working. When trying to import /budjet.jpg, I received the error message: "Module not found: ...

Update the $_Get value without the need to refresh the entire page

I have a directory named vehicles, containing approximately 600 distinct images, all with the extension (.jpg), and each named as numbers from 1 to 600. I am displaying them as a vehicle gallery with Next and Previous buttons. The image displayed is deter ...

CSS image replacement; won't render properly

I'm currently working on implementing a hover image swap effect for my website gallery. The CSS code I have so far is below. While the original images in my HTML file are displaying correctly, the hover functionality is not working as expected. CSS: ...

Can PHP variables be styled using CSS techniques?

Is there a way to apply CSS styling to a PHP variable using a style sheet? Here is the PHP variable I am working with: if(empty($email)){ $msg[] = "Email address required."; $msg['error'] = true; } I am looking to change the color of th ...

Tips for including data labels in a scatter plot using d3.js

I am currently studying d3.js for data visualization and I have chosen to work with the titanic dataset My objective is to incorporate passenger names into my visualization so that when a cursor hovers over a point, the person's name is displayed. H ...

When inline-block elements wrap onto a new line, they expand to full width

Upon my realization, an inline-block element will expand to 100% width if there are more child elements than can fit on one line: <div style="background-color:red;padding:5px"> <div style="display:inline-block;background-color:green;padding:5 ...

Tips for positioning the text and icon within a tag nestled in a paragraph tag?

Need help aligning text and icons inside paragraph tags on a tag. Here is the HTML code I'm currently using: <div class="application-intro"> <p><a class="btn" href=""><i clas ...

Difficulty navigating to different sections of a webpage using HTML

I'm facing a strange issue. The title pretty much sums it up. Here's a snippet of the code: <a href="#test1">Go to test 1</a> <a href="#test2">Go to test 2</a> <a href="#test3">Go to tes ...

Implement input validation in React by enhancing the functionality of HTML input tags

Below is the input provided: const REGEX_EMAIL_VALIDATION = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}&bsol ...

How can I update the language of a button text in a React component?

Looking to update the button labels from a different language to English. Here is how it currently appears: https://i.sstatic.net/6JZ6m.png ...

What are the steps for showcasing the output of a JavaScript function on an HTML page?

After searching the community for solutions, I'm still struggling to understand them. I have a JavaScript function that reads data from a .json file and displays a specific object in VisualCodee console. Now, I want to show this object on an HTML fil ...

Tips for including information in a chart

I'm facing an issue with my current code as it is not functioning properly. Here is the link to the current output: http://jsfiddle.net/4GP2h/50/ ...

I am facing issues with applying my CSS styles to my PHP include files correctly

After facing an issue with my previous post due to unclear information and improper code presentation, I realized that the root cause was not related to a duplicate question. So, here is a new post with detailed information. In my project, I have created ...

Display an additional div when the mouse hovers over the image

I'm currently working on a "cast" section for one of my projects, and I'd like the actor's character to be revealed when the actor is hovered over. How can I make this happen without leaving a gap on the page when hiding the display of the d ...

Enhance your user experience by implementing a jQuery solution that makes a div

Looking to add a small div on the right side of your screen that moves along with your vertical window slider? Wondering if jQuery has a function to get the current vertical slider position? I thought scrollTop() might work, but it only returns from a spe ...

The submission of an MVC view page does not redirect back to the controller

Having trouble with the code below. When I click the "Submit" button, it's supposed to take me back from the view page to the controller. However, when I set a breakpoint at the controller method [HttpPost] ProductEdit, the code never stops there. Th ...