All pictures aligned with overflow

The first container is working fine, displaying 2 images vertically, but when there are 6 images, it overflows.

The problem lies with container 2, where I want to create a horizontal list of images with overflow (only horizontal).

This is the current state of my CSS:

#container {
  display: block;
  width: 80%;
  height: 40vw;
  background: red;
  margin-bottom: 50px;
}

#imglist {
  display: block;
  overflow: auto;
  height: 40vw;
  width: 40%;
}

#imglist div {
  display: block;
  width: 100%;
}

#imglist div img {
  width: 100%;
}

/* Problem */

#container2 {
  display: block;
  width: 80%;
  height: 20vw;
  background: red;
}

#imglist2 {
  overflow-x: scroll;
  display: block;
  width: 100%;
  height: 15vw;
}

#imglist2 div {
  width: 20%;
  display: inline;
}

Refer to this JSFiddle for an example: https://jsfiddle.net/n4a2tc7s/

Answer №1

Take Charge of Wrapping and Concealment

To have full control over wrapping and hiding content, it is recommended to specify white-space: nowrap for the container. Additionally, set overflow-y: hidden instead of overflow-x: scroll to prevent horizontal scrolling. This will ensure that scroll bars only appear on the vertical axis, as needed.

In the example below, I included height: 100% for #imglist2 to address an issue where the scrollbar was cutting off the images due to the 15vw declaration. If this was intentional, you can revert it back to its original state:

#container2 {
  display: block;
  width: 80%;
  height: 20vw;
  background: red;
  white-space: nowrap;
}

#imglist2 {
  overflow-y: hidden;
  display: block;
  width: 100%;
/*height: 15vw;*/
  height: 100%;
}

#imglist2 div {
  width: 20%;
  display: inline;
}
<section id="container2">
  <div id="imglist2">
    <div>
      <img src="http://img.youtube.com/vi/Je7VuV9yHIw/1.jpg">
    </div>
    <div>
      <img src="http://img.youtube.com/vi/uxps_fYUeJk/1.jpg">
    </div>
    <div>
      <img src="http://img.youtube.com/vi/Zvr3cwbbqHU/1.jpg">
    </div>
    <div>
      <img src="http://img.youtube.com/vi/Ka9xtXPD3BA/1.jpg">
    </div>
    <div>
      <img src="http://img.youtube.com/vi/U8HVQXkeU8U/1.jpg">
    </div>
    <div>
      <img src="http://img.youtube.com/vi/e7_UUfokexM/1.jpg">
    </div>
  </div>
</section>

Answer №2

Take a look at this code snippet:

#block3 {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 70%;
    height: 25vh;
    background: blue;
    white-space: pre;
}

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

BS grid malfunctioning in a non-uniform manner

When a division in the advantage grid is clicked, the card body of another division collapses. However, this does not occur in the disadvantage grid. Clicking on one section in the disadvantage grid does not collapse another section as it does in the advan ...

Guide to incorporating flash into a form similar to the method used on http://www.mediafire.com

I'm looking to integrate a flash upload feature into my index file, but I'm not sure how to do it. Here is the link to the flash uploader: . I want it to work similar to how uploading works on when you click on UPLOAD. Thank you for any assistan ...

Issue with changing the height of a textarea in a mobile browser when it is

I'm currently facing an issue specific to mobile devices that I have also encountered on Google Chrome (even when using the developer tools in mobile view). The problem is quite straightforward. There is a simple form on the website, consisting of a ...

Having difficulty implementing a hover event on a sibling element of a target using either the duration parameter in jQuery UI or CSS

My objective is to alter the background color of an element and one of its higher siblings in the DOM but within the same parent upon hover. While I successfully used CSS transition to change the first element, I encountered difficulty getting the sibling ...

Display a floating label above the text input when it is focused or when it holds text

I am trying to create an animated search bar where the label moves from being over the text input to above it. I came across a helpful example in a fireship.io video, which includes the CSS and HTML code available here The example I found demonstrates the ...

The left and right edges are not extending across the entire screen

Can anyone help me determine if this is a duplicate issue? I'm unsure why my left and right borders are not extending the full width of the screen. The website in question is ojs.monojitbanerjee.co.cc Here is the structure: <body> <div id= ...

What are some effective ways to analyze jQuery and JavaScript using web development tools?

I'm struggling to use web development tools to inspect the JavaScript on websites. It's challenging to identify which parts of a site are utilizing JS, unlike CSS or HTML where it's more visibly defined. Even when I attempt to delete some J ...

Align the inline text at the center as if it were an inline-block element

Currently working on a design that appears deceptively simple, yet I'm encountering challenges in centering it while keeping the text aligned to the left. https://i.sstatic.net/qhf6p.png In an attempt to have the background span only the actual text ...

Chrome has a tendency to cut off page contents in print preview, unlike other browsers that do not have this issue

My current version of Chrome browser (54.0.2840.59) is exhibiting a strange behavior when attempting to print preview an HTML page I have developed. The print preview truncates the page content, displaying less than what should be shown. The content is not ...

Working with the collapse event in Bootstrap

After purchasing a template from ThemeForest, I found it to be absolutely amazing. However, I am struggling with using Bootstrap as it seems quite complex. The left menu is structured with collapsible ul and multiple li elements. I am seeking assistance o ...

Improve the readability of text that is overflowing using CSS styling techniques

I am facing a problem with a table containing fixed-width content that doesn't always fit within the designated space. My goal is to truncate the text to a fixed width and add an ellipsis, while allowing the full text to be visible when hovering over ...

The left side of my image doesn't quite reach the edges of the screen as desired

Even after setting the padding and margin in the parent container to 0, the image is still not filling to the edges. Here is the image. This snippet of code shows my JavaScript file: import styles from './css/Home.module.css'; export default fun ...

Encountering issues with loading styles in Vue single file components

While working on my project at this link, I encountered an issue with displaying a styled modal. Despite trying to import the styles using: <style scoped> @import "../styles/modal-style.css"; </style> and even directly pasting the co ...

Effortlessly alternate between dual-column and single-column layouts using CSS

Creating a basic two column layout with fixed widths is my current project. <div id='box'> <div id='ontop'>Ontop</div> <div id='column1'>Column1</div> <div id='column2'&g ...

Persistent vertical menu dropdown that remains expanded on sub menu pages

I am struggling to understand how to keep my menu sub items open when on the active page. Although I have tried similar solutions, I have not been successful in implementing them. I apologize if this question has been asked before. My approach involves usi ...

What is the best way to ensure a string of words in HTML/CSS wraps to the next line seamlessly?

As I work on creating my portfolio website using Bootstrap and custom CSS, I am running into an issue with the game titles breaking in the middle when displayed. Despite my limited proficiency in English, I tried searching for a solution without success. ...

Conflicting styles occur when trying to align images using both TailwindCSS and CKEditor 5

My current project involves using Laravel 10 with Vite as the asset builder and Tailwind for CSS. The app.css file contains the following code: @tailwind base; @tailwind components; @tailwind utilities; I am currently implementing a text editing feature u ...

Ways to secure a floating item onto a backdrop picture

Currently I am working on editing this page. When you hover over the cat, its eyes blink or two black dots randomly appear. My goal is to prevent the random blinking dots from appearing. I want to keep the hover object attached to the cat/background image ...

Stop the default drag behavior on an input range element in VueJS

Is there a way to disable the default drag functionality of an input range element without affecting the click feature? Users should be able to change values by clicking instead of dragging. <input type="range" min="0" max=& ...

Suitable HTML container for ASP form over HTML table

Can anyone advise on the best HTML container to use for an ASP form that can be styled with CSS instead of an HTML table? For example, consider the following form on an aspx page: <form id="WPF" runat="server"> <asp:Label ID="lblCCode" Text="Cou ...