Tips on causing a div to overflow instead of wrapping onto a new line

Are you looking to design a slider with 3 image containers all in the same row, where the third one overflows instead of wrapping to a new line? Here is an example:

Desired Design:

https://i.stack.imgur.com/dKyEg.png

Current State:

https://i.stack.imgur.com/zENP7.png

HTML Code:

    <div class="image-slide-wrapper">
      <div class="images-section">
        <div class="image-slide">
          <div class="slide-img">
          </div>
        </div>
        <div class="image-slide">
          <div class="slide-img">
          </div>
        </div>
        <div class="image-slide">
         <div class="slide-img">
         </div>
        </div>
      </div>
    </div>

SCSS Code:

.image-slide-wrapper {
        float: left;
        height: 55%;
        width: 100%;
        .images-section {
          float: left;
          height: 85%;
          width: 100%;
          border: 1px solid grey;
          border-radius: 8px;
          overflow: hidden;
          padding: 0.125rem;
        }
        .image-slide {
          float: left;
          height: 100%;
          width: 100px;
          margin-right: 0.25rem;
          .slide-img {
            float: left;
            height: 100%;
            width: 100%;
            border-radius: 0.35rem;
            background-color: #e9e9e9;

Note: The slider uses the images-section class for the slider and the image container is under the image-slide class. It's important to use float for consistency with the rest of the code.

Answer №1

<div style="overflow: hidden; width: 250px;">
  <div style="width: max-content">
    <img style="width: 100px;height: 100px;border: 1px solid black;" src="...">
    <img style="width: 100px;height: 100px;border: 1px solid black;" src="...">
    <img style="width: 100px;height: 100px;border: 1px solid black;" src="...">
  </div>
</div>

Answer №2

One alternative solution is to eliminate the float property from the thumb elements and instead apply display: flex along with flex-flow: row nowrap on the container.

.container {
  height: 100px;
  width: 250px;
  border: 1px solid grey;
  border-radius: 8px;
  overflow: hidden;
  padding: 0.125rem;
  display: flex;
  flex-flow: row nowrap;
}

.image-slide {
  height: calc(100% - .25rem);
  flex: 1 0 100px;
  margin-right: 0.25rem;
  border: 1px #ccc solid;
}
<div class="container">
   <div class="image-slide"></div>
   <div class="image-slide"></div>
   <div class="image-slide"></div>
   <div class="image-slide"></div>  
</div>

Answer №3

Adding display:flex; and flex-wrap:nowrap; to the .image-slide-wrapper class will work perfectly.

    .main {
        float: left;
        height: 85%;
        width: 100%;
        border: 1px solid grey;
        border-radius: 8px;
        overflow: hidden;
        padding: 0.125rem;
        display:flex;
        flex-wrap:nowrap;
    }
    
    .slider {
        float: left;
        height: 100%;
        width: 300px;
        margin-right: 0.25rem;
        display: block;
    }
<div class="main">
  <div class="slider">
    <img class="img" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTBYCs940TLL3tx_nyn7fVeidXWZyfOKV5QrQ&usqp=CAU">
  </div>
  <div class="slider">
    <img class="img" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTBYCs940TLL3tx_nyn7fVeidXWZyfOKV5QrQ&usqp=CAU">
  </div>
  <div class="slider">
    <img class="img" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTBYCs940TLL3tx_nyn7fVeidXWZyfOKV5QrQ&usqp=CAU">
  </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

The CSS top border is failing to display

For a school project, I've been attempting to add a top border to a set of hyperlinks in order to separate them from the title. However, after spending over an hour on this task, I still can't seem to get it to work. Below is the CSS code for th ...

Is there a way to automatically change the display of an element once the user has closed the menu?

How can I ensure that the display of an element remains unchanged when a user opens and closes my website menu using JavaScript? ...

Modifying inner content without altering CSS styling

Inside this div, there is a paragraph: This is the HTML code: <div id="header"><p>Header</p></div> This is the CSS code: #header p { color: darkgray; font-size: 15px; Whenever a button is clicked, the innerHTML gets updated: H ...

Can a border-bottom be made the same size as a class it is not linked to in CSS?

Can I set a border-bottom to match the size of a separate class? For example, I want a border-bottom at the bottom of each <section> tag. However, since the sections span the full width of the screen, the border-bottom inherits that width. Each < ...

Guide to creating a vertical handler that can be resized

Did you know that you can resize tables in http://www.jsfiddle.net? I'm curious about how to resize just the "Vertical Handler". Could someone share the source code with me? If possible, please provide an example on http://www.jsfiddle.net. ...

Scrollbar issue and splitting line in half

I am writing some CSS code below. I am trying to achieve horizontal scrolling, but if the sentence is too long, it breaks and displays on the next line. In the image, I want "aaaa.." to be displayed on only one line and "bbb.." on the second line, ...

Shine a light on the input with a captivating outer

Can we replicate the outer glow effect that Safari and other browsers automatically add to an input field without using jQuery? If you want to remove it, check out this article: Thank you! ...

Enhancing dynamic text boxes with jQuery by incorporating additional information

I've recently developed an interactive app that dynamically creates tables based on user input. The app includes a feature where you can specify the number of tables to generate and track the total count of tables added. Currently, I'm exploring ...

Guide on altering the cursor icon during an AJAX operation within a JQuery dialog

When I have a JQuery dialog open and make some $.ajax calls, why can't I change the cursor? I want to display a progress cursor while the code is processing so that users can see that the action is still ongoing. However, even though I update the CSS ...

Implementing dynamic width with ng-style in AngularJS

I am trying to dynamically resize a div when an event is fired from S3. In the code below, I pass the progress variable to the updateProgress function as a parameter. This function resides in the top scope of my Angular controller. s3.upload(params).on(& ...

Ways to conceal the TippyJS tooltip so it doesn't show up on video embeds

My website has tooltips enabled, but I am looking to hide the tooltip pop-ups that appear specifically over youtube video embeds. Upon inspecting the webpage, I found the code snippet below that is associated with youtube videos: <div data-tippy-root id ...

"Scrolling with Bootstrap Scroll Spy is causing incorrect sections to be

Can anyone help me with my issue regarding Bootstrap scrollspy settings? It seems to be highlighting the wrong div id, always the last one. Here is the code snippet: Content: <body style="heigt: 100%" data-spy="scroll" data-target="#side-menu"> ...

Implementing overflow-x: hidden in React JS for enhancing mobile user experience

In my current React project, I encountered an issue where setting overflow-x: hidden in the index.css file for the body tag worked fine on desktop screens but not on mobile. I read that adding it to the parent element would be a better solution, however, ...

Error in Bootstrap V5 Sass: Mixin not defined - when transitioning from @import to @use module system

Transitioning to the new SASS module system with @use from @import has presented some challenges, especially when working with bootstrap v5: https://i.sstatic.net/8Hy7W.png Old way: @import "~bootstrap/scss/bootstrap"; @import "~bootstrap/ ...

Issue with Bootstrap navigation bar not displaying on iPad devices

Currently, I am working on creating a custom bootstrap menu that displays properly on an iPad screen size. I have implemented the standard navbar code from Bootstrap with a few tweaks. While it works well on smartphones and laptops, the issue arises when ...

What is the best way to apply a :visited selector specifically to the most recently visited webpage?

I've noticed that all the pages I've visited on the site have now changed to the color I chose. However, my goal is for only the last page I viewed to be in the color I assigned. Thank you! ...

Issue with Safari: Unable to trigger CSS :hover when tapping SVG element

On an iOS device in Safari, tapping this SVG element does not trigger the transition animation to fade in the replacement <g id="training-sub-menu">. The animation is confirmed to work, as there is a strange behavior where long-pressing whe ...

Dropdown menu similar to the one utilized in Bootstrap

I am curious to understand how the drop-down menu system in Bootstrap3's tutorial page operates. It seems that it collapses all subtopics under a main topic by default, allowing users to either click or scroll to expand further. Additionally, the menu ...

How can I dynamically set the width of a span element in HTML?

Hello there! As a beginner in html and angularjs, I'm experimenting with dynamically assigning span width based on an angular js response. <div class="statarea" ng-repeat="x in names"> <div class="ratingarea"> <div class=" ...

Even after being removed, the input field in Firefox stubbornly maintains a red border

I have a project in progress that requires users to input data on a modal view and save it. The validation process highlights any errors with the following CSS snippet: .erroreEvidenziato { border: 1px solid red; } Here is the HTML code for the moda ...