Creating an overflow effect for sliders using only CSS

Is it feasible to develop a slider that extends beyond its parent elements and the body?

The concept involves having content within a section housed in a container. The slider would be part of this section, with slides overflowing past the parent element and body.
The vertical scroll would match the width of the container, but you would still be able to see slides outside of the container.

h2{
  text-align: center;
}

.container{
  margin: 0 auto;
  max-width:460px;
  border: 2px solid #ef34ed
}

.slider{
  display: flex;
  align-items: center;
  jusify-content: flex-start;
  overflow-x: scroll;
}

.slide + .slide {
  margin-left: 50px;
}

.slide{
  text-align: center;
}
<div class="section">
  <div class="container">
    <div class="row">
      <h2>Some title</h2>
    <div class="slider">
      <div class="slide">
        <img src="https://via.placeholder.com/150" alt="person" />
      </div>

      <div class="slide">
        <img src="https://via.placeholder.com/150" alt="person" />
      </div>
      
      <div class="slide">
        <img src="https://via.placeholder.com/150" alt="person" />
      </div>
      
      <div class="slide">
        <img src="https://via.placeholder.com/150" alt="person" />
        <p>Name</p>
      </div>
      
      <div class="slide">
        <img src="https://via.placeholder.com/150" alt="person" />
        <p>Name</p>
      </div>

      <div class="slide">
        <img src="https://via.placeholder.com/150" alt="person" />
        <p>Name</p>
      </div>

      <div class="slide">
        <img src="https://via.placeholder.com/150" alt="person" />
      </div>
      
      <div class="slide">
        <img src="https://via.placeholder.com/150" alt="person" />
      </div>

      <div class="slide">
        <img src="https://via.placeholder.com/150" alt="person" />
      </div>
      
    </div>
    
    <p>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla fringilla nisl eget ligula tincidunt, ut mattis velit ultricies. Sed efficitur odio vel ullamcorper lacinia. Curabitur vitae tortor mauris. In condimentum tellus ac fermentum sodales. Aenean varius metus nec sollicitudin tristique.

    </p>
  </div>
  <div>
</div>

https://i.sstatic.net/7Txqm.png

Answer №1

Hopefully this meets your needs.

h2{
  text-align: center;
}

.container{
  margin: 0 auto;
  max-width:460px;
  border: 2px solid #ef34ed;
  overflow: visible;
}

.slider{
  display: flex;
  align-items: center;
  justify-content: flex-start;
  overflow-x: scroll;
  padding:0 calc(calc(100vw - 460px)*0.5);
  margin:0 calc(calc(100vw - 460px)*-0.5);
}

.slide + .slide {
  margin-left: 50px;
}

.slide{
  text-align: center;
}
<div class="section">
  <div class="container">
    <div class="row">
      <h2>Some title</h2>
    <div class="slider">
      <div class="slide">
        <img src="https://via.placeholder.com/150" alt="person" />
      </div>

      <div class="slide">
        <img src="https://via.placeholder.com/150" alt="person" />
      </div>
      
      <div class="slide">
        <img src="https://via.placeholder.com/150" alt="person" />
      </div>
      
      <div class="slide">
        <img src="https://via.placeholder.com/150" alt="person" />
        <p>Name</p>
      </div>
      
      <div class="slide">
        <img src="https://via.placeholder.com/150" alt="person" />
        <p>Name</p>
      </div>

      <div class="slide">
        <img src="https://via.placeholder.com/150" alt="person" />
        <p>Name</p>
      </div>

      <div class="slide">
        <img src="https://via.placeholder.com/150" alt="person" />
      </div>
      
      <div class="slide">
        <img src="https://via.placeholder.com/150" alt="person" />
      </div>

      <div class="slide">
        <img src="https://via.placeholder.com/150" alt="person" />
      </div>
      
    </div>
    
    <p>
    Magna phaedrum electram pro an. Te nec delectus temporibus, omittantur ullamcorper ne pri. Pri ad affert urbanitas, laboramus eloquentiam pri ad. Purto summo interpretaris eam et, brute dolore ut eam, illud dolore putent et vim. Ei sed aliquip iudicabit, te fabulas menandri sed.

    </p>
  </div>
  <div>
</div>

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

What might be causing my direct descendant selector to not work as expected?

I'm struggling with my direct descendant selector. Let's analyze a straightforward example: .myDiv > table tr:first-child td { font-weight: bold; text-align: center; } <div class="myDiv"> <table style="width:100%"> < ...

Steer clear of dividing words

I am attempting to showcase sentences letter by letter with a fade in/fade out effect. However, I am facing an issue where words break in the middle. How can this word breaking be prevented? var quotes = document.getElementsByClassName('quote' ...

Menus that mimic the style of Google Translate's select options

I'm looking to design an HTML select menu using CSS in a similar fashion to Google Translate's style on Google Translate. I've searched for tutorials online, but they all involve jQuery. Is there a way to achieve something similar using only ...

What are some ways to optimize the use of the jquery.mCustomScrollbar.js script?

I have a myriad of inquiries and would greatly appreciate your assistance in addressing them. Despite spending countless hours attempting to solve the issue independently, I have been unsuccessful. One question that plagues me is why, when using Google Ch ...

Modify the Color of Chosen Anchors for Site Categories WITHOUT Using JavaScript

Is there a way to change the color of section anchors in a fixed header when selected without using JavaScript? I'm looking for a CSS-only solution that will change the color of the selected anchor and revert it back to normal when another anchor is c ...

Ways to prevent a div containing a lengthy content string from extending beyond other divs

Check out my Codepen project here Here is the HTML code for my personal website: <div id="splash" class="divider"> <h1 class="text-center text-uppercase">vincent/rodomista</h1> <p class="text-center text uppercase">Full Stack ...

Load a page and sprinkle some contents with a slide effect

I am brand new to jQuery and just starting out, so please excuse me if this question seems basic or silly. I would like the header and footer of my page to stay in place while the center content slides in from the right side when the page loads. This websi ...

Switching the background color of a button on click and resetting the color of any previously clicked buttons (a total of 8

I'm struggling to implement a feature where only one button out of a column of 8 should be toggled yellow at a time, while the rest remain default green. Unfortunately, I can't seem to get the function to execute on click, as none of the colors a ...

Struggling to locate a straightforward sidebar solution without relying on Bootstrap. Finding an easy-to-use answer seems

I have a lightweight and easy-to-understand code for a website project with two panels. The first panel on the left is a large navigation (270px width, top to bottom, similar to a wiki) with approximately 30 unordered list items. Next to it is the second ...

Challenges with the final child element's CSS styling

Hey everyone, I've recently added the following CSS: #tab-navigation ul li:last-child { background-image: url(../images/tabs-end.gif); background-repeat: no-repeat; color: #fff; display: block; border: 1px solid red; backgrou ...

Having issues with React Nivo tooltip functionality not functioning properly on specific graphs

While using Nivo ResponsivePie to visualize some data, everything is functioning properly except for the tooltip. For some reason, the tooltip isn't appearing as it should. Interestingly, I have a heatmap and a bar graph with tooltips that are working ...

Using percentages for CSS alignment and adjusting element widths

Greetings everyone! I have been struggling to align two divs - one on the right with a width of 30% and the other on the left with 70%. Despite my efforts, I have not been able to find a solution. I am hopeful that someone here can assist me. My setup inv ...

Endlessly tapping through each tab with no direction

I am attempting to click on all unopened tabs (elements) randomly across this page. While the code below usually does the trick, it sometimes doesn't click on all elements. I suspect that there might be an issue with how it loads indexes or some othe ...

Is there a different method like Calc() to create a static sidebar alongside content?

Is there a way to achieve a fixed sidebar on the left and a content area on the right without using calc() in CSS? I'm looking for a more universally supported method that works across different browsers. .left-sidebar { width: 160px; ...

Instructions for compiling node-sass within the present directory for specific files

In my project, the directory structure looks like this: - folder1 - styles1.scss - folder2 - styles2.scss I want to utilize node-sass through the command line to generate the following output: - folder1 - styles1.scss - styles1.css - folder2 ...

Highlighting the selected tab with an active class

Currently in the process of learning angularJs, I am still new to it and attempting to dynamically add an active class to the recently clicked tab. Within my interface, there are four tabs: insert, view, update & delete. My goal is to apply the active ...

Adding a class to the following DIV and smoothly transitioning the current one out can be achieved using a dynamic number of items in multiple instances

Is there a way to create a scalable CSS slideshow for text divs without using images? Here is the current HTML structure: <div class="mb-panel-container cf"> <div class="mb-panel-section mb-slider"> <div class="mb-panel active" ...

What strategies can I use to include multiple spans within div elements without causing the code to become overly lengthy?

I'm working with 20 spans representing movie genres, each accompanied by another span that "closes" the genre when selected. The closing span has an .active class, similar to this example: https://i.sstatic.net/7CuuX.png My version currently looks li ...

Is there a way to create an animation for changing .text in response to an on click event?

I'm currently developing a simple calculator that increases a variable when a button is clicked, displaying the updated value in a div. Each click on the 'amount-upwards' button adds 200 to the displayed number. Below is the jQuery code I a ...

How can we avoid re-rendering the same component repeatedly when using React Router v6?

As a beginner in react, I'm facing an issue with preventing components from re-rendering when navigating to a different page. Specifically, I want to display only text on my Signup and Login pages, but the Navbar keeps re-rendering every time I switch ...