Simple Image Slider CSS Only

Simple Image Slider CSS Only
Code Snippet:Accordion Image Slider( HTML-CSS)
Author: أحمد حذيفة
Published: January 10, 2024
Last Updated: January 22, 2024
Downloads: 18,668
License: MIT
Edit Code online: View on CodePen
Read More

This code creates a simple image slider using CSS only. It comes with a list of images that are displayed in a row. When the user hovers over the slider, the images will slide to the left, revealing the next image in the list. The user can also click on the images to view them in full size.

The CSS code for the slider uses the :hover pseudo-class to change the width of the li elements. When the user hovers over the slider, the li elements will become wider, revealing the next image in the list. The CSS code also uses the transition property to create a smooth animation effect.

How to Create Simple Image Slider CSS Only

1. Copy the following HTML code, specifically the structure within the <div class="accord"> element. This includes the <ul> list containing <li> items, each with a <div class="title"> and an <img> tag. Replace the image sources in the <img> tags with URLs or paths to your desired images.

<div class="accord">
		<ul>
			<li>
				<div class="title">
					<a href="#">the style</a>
				</div>
				<img src="https://p1.pxfuel.com/preview/1015/988/1021/watch-fashion-accessories-objects.jpg" alt=""/>
			</li>
			<li>
				<div class="title">
					<a href="#">A leaf </a>
				</div>
				<img src="https://p0.pxfuel.com/preview/248/813/143/achievement-adult-battle-black.jpg" alt="">
			</li>
			<li>
				<div class="title">
					<a href="#">rose</a>
				</div>
				<img src="https://p0.pxfuel.com/preview/990/311/594/coffee-cup-mug-office.jpg" alt=""/>
			</li>
			<li>
				<div class="title">
					<a href="#">the water</a>
				</div>
				<img src="https://p1.pxfuel.com/preview/259/365/195/finger-pointing-hands-watch.jpg" alt=""/>
			</li>
		</ul>
	</div>

2. Add the following CSS styles within <style> tag or external CSS file in your project. Modify the width, height, and color attributes in the CSS code to match your project’s design. Adjust the dimensions of the slider, images, and any other elements to suit your layout preferences.

* {
  margin: 0;
  padding: 0;
  font-family:ubuntu;
}

body {
  background-color: #ff4d4d;
}
.accord {
  width: 610px;
  margin: auto;
  margin-top: 100px;
  height: 400px;
  overflow: hidden;
  border: white 3px solid;
  background-color: white;
  transition: all 0.8s ease;
}
.accord ul li {
  width: 150px;
  display: block;
  float: left;
  position: relative;
  border-left: 2px solid white;
  height: 400px;
  transition: all 0.5s ease, opacity 0.2s ease;
  opacity: 0.8;
  backface-visibility: ;
}
.accord ul li img {
  width: 300px;
  height: inherit;
}
.title {
  transition: all 0.5s ease-in;
  position: absolute;
  bottom: 0;
  width: 300px;
  display: block;
  background-color: rgba(89, 89, 89, 0.4);
}
.title a {
  font-size: 110%;
  display: block;
  text-transform: capitalize;
  text-decoration: none;
  padding: 20px;
  color: white;
}
.accord:hover {
  box-shadow: 6px 6px 10px 5px grey;
  transform: scale(1.1, 1.1);
}
.accord ul:hover li {
  width: 100px;
}
.accord ul li:hover {
  width: 300px;
  opacity: 1;
}

That’s all! hopefully, you have successfully created a simple image slider using HTML and CSS only. If you have any questions or suggestions, feel free to comment below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About CodeHim

Free Web Design Code & Scripts - CodeHim is one of the BEST developer websites that provide web designers and developers with a simple way to preview and download a variety of free code & scripts. All codes published on CodeHim are open source, distributed under OSD-compliant license which grants all the rights to use, study, change and share the software in modified and unmodified form. Before publishing, we test and review each code snippet to avoid errors, but we cannot warrant the full correctness of all content. All trademarks, trade names, logos, and icons are the property of their respective owners... find out more...

Please Rel0ad/PressF5 this page if you can't click the download/preview link

X