Modify the table layout by incorporating images within separate div containers for each row

In my layout, there is a grey box element that contains a table with rows of small images. I want the table to automatically adjust based on the number of images so that when the grey box reaches its maximum size, the images move to the next row. Is this achievable?

Additionally, I am trying to make the layout resizable for different screen sizes.

Below is a snippet of the CSS and HTML code:

body {
   background-color:  #141414;
   margin-top:3%;
   margin-left: 2%;
   margin-right: 2%;
}

/* CSS properties omitted for brevity */

<body>
<div class="video-item">
  <p class="font-semibold">Something else</p>         
  <div class="video-display"></div>
</div>
  
<div class="video-spacer"></div>

<div class="video-item-2">
    <p class="font-semibold">THUMBNAIL PREVIEW</p>
      <div id="thumbnail-grid">
        <img id="arrow_up" src='http://www.pngdot.com/wp-content/uploads/2015/11/Png_Up_Arrow_01.png' alt="arrow" height="25" width="45">
          <table id="thumbs">
             <tr>
                  <td tabindex="3"><img id="arrow_up" src='http://oleaass.com/wp-content/uploads/2014/10/Random-truths18.jpg' alt="arrow" height="40" width="60"></td>
                  <!-- Additional image TDs removed for brevity -->
               </tr>
           </table>
           <img id="arrow_down" src='http://www.pngdot.com/wp-content/uploads/2015/11/Png_Up_Arrow_01.png' alt="arrow" height="25" width="45">
         </div>
</div>
</body>

If solving this with CSS alone is not feasible, I am open to using JavaScript or jQuery as well.

Thank you!

Answer №1

When the solution reaches a certain width, it automatically breaks into new lines.

body {
   background-color:  #141414;
   margin-top:3%;
   margin-left: 2%;
   margin-right: 2%;
}


.video-item {
   width: 30%; 
   float: left; 
   margin-bottom: 5px;
}

.video-item-2 {
   width: 66%; 
   float: left; 
   margin-bottom: 20px;
}

.video-display {
   background-color: #1F1F1F; 
   height: 450px;
}

p {
   color: white;
   text-align: center;
}

#thumbs {
  text-align: center;
  max-height: 400px;
  overflow: auto;
}

#thumbnail-grid {
   background-color: #1F1F1F; 
   height: 450px;
}

.video-spacer {
   width: 2%;
   float: left;
   min-height: 200px;
}

#arrow_up, #arrow_down {
   display: block;
   margin: 0 auto;
}

#arrow_down {
   -ms-transform: rotate(180deg); /* IE 9 */
   -webkit-transform: rotate(180deg); /* Chrome, Safari, Opera */
   transform: rotate(180deg);
  }
<body>
<div class="video-item">
  <p class="font-semibold">Something else</p>         
  <div class="video-display"></div>
</div>
  
<div class="video-spacer"></div>

<div class="video-item-2">
    <p class="font-semibold">THUMBNAIL PREVIEW</p>
      <div id="thumbnail-grid">
        <img id="arrow_up" src='http://www.pngdot.com/wp-content/uploads/2015/11/Png_Up_Arrow_01.png' alt="arrow" height="25" width="45">
        
          <div id="thumbs">
            <img src='http://oleaass.com/wp-content/uploads/2014/10/Random-truths18.jpg' alt="arrow" height="40" width="60">
            <!-- more images -->

          </div>
        <img id="arrow_down" src='http://www.pngdot.com/wp-content/uploads/2015/11/Png_Up_Arrow_01.png' alt="arrow" height="25" width="45">
      </div>
</div>
</body>

Answer №2

To improve the structure of your layout, it's recommended to replace tables with a div container. This will allow for better organization and flexibility in design. Here is an example of how this can be achieved:

<div class="imageContainer">
    <img class="singleImage" ...... / >
</div>

For styling using CSS, you can utilize the float property as shown below:

.singleImage {
    height: 40px;
    width: 60px;
    float: left;
}

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

Is the JavaScript progress bar dysfunctional when used with object-oriented JavaScript code, but functions properly with arrow functions?

After posting a question about the JavaScript progress bar not working with object-oriented JavaScript code on Stack Overflow, I decided to try rewriting the script using arrow functions. Here is the new code: document.getElementById("barButton").addEve ...

Pass the radio button value and accompanying text to a PHP script

I am struggling with sending both the radio button value and text to php. Currently, I can only send the radio button value. However, I want to also include the text after the radio button without altering the checkbox information. <input name="li ...

navigating between html pages using sliding next and previous buttons

I am in the process of developing a multi-page form spread across 4 different pages. I would like to incorporate next and previous buttons to allow users to easily navigate through the form. Although I have tried looking online for solutions, most results ...

What is the best way to create a seamless background transition for buttons on a mobile device?

Currently, I am working on my random quote generator project and I am trying to make it so that when the button is touched on a mobile device, the background color becomes semi-transparent. Below is the code I am using: #loadQuote { position: fixed; w ...

"Exploring the interactivity of touch events on JavaScript

Hi there, I'm currently facing an issue with the touch events on my canvas. While the mouse events are functioning correctly and drawing as expected, incorporating touch events seems to be causing a problem. When I touch the canvas, the output remains ...

Elements that do not change when hovered over and that intersect

In the provided example, I am attempting to decrease the opacity of non-hover elements on an HTML page. The code snippet below successfully reduces the opacity of non-overlapping elements. However, when there is a background element that overlaps and shou ...

Issue with iPhone CSS displaying differently on mobile devices

The CSS design does not display correctly on iPhone devices in real-life testing, even though it appears fine on browsers with mobile view emulators. Interestingly, the design also looks great on Android phones but encounters issues specifically on iPhones ...

Styling the elements that are next to each other using CSS

Hey there, what if I have HTML elements structured like this: <div> <div>Name</div> <div><input type="text" class="check"> <div>Age</div> <div><input type="number" class="check"></div> ...

The web typography appears fuzzy or has incorrect thickness, lacks consistency across pages and even within a single page

The font (ProggyCleanSZBP.ttf from 1.1.5 release) appears to be intermittently thick and blurry. If you compare with , you'll notice that the latter displays as desired in most cases, but there are instances where the issue occurs, such as the first ...

The alignment of the navigation menu disrupts the functionality of the dropdown sub-menus

I'm finding it challenging to center the navigation menu while maintaining the functionality of the drop-down li elements. Here is my demo: http://jsbin.com/tosayosino/1/edit?html,css,js,output Removing the float:left; property from .jetmenu li succ ...

Having difficulty choosing a drop-down menu option with AJAX technology

My current project involves creating a page where the database is updated upon a drag-and-drop event. Specifically, I have implemented drag-and-drop functionality on a page, and whenever a div (deal-card) is dragged and dropped into another div (stage-colu ...

What is the best way to locate an item reference for a specific DOM element?

Imagine a vast DOM structure with approximately 10,000 HTML elements, including 1,000 span tags. None of the span elements have any identifiers and are buried deep within other objects with long, complex Xpath paths that are not user-friendly for selectio ...

The JavaScript code is not being executed, as the address bar displays the function name instead

In my project, I have created numerous "js-classes" with various functions spread across different files. Unfortunately, the codebase is too large to share entirely. However, towards the end of the project, I encountered a bug where a specific function wa ...

problem with z-index and background image overlap

I'm attempting to overlay a .header-content div, containing the website content, on top of another .header-bg div, which has only a background cover and a set height using z-index. When I change the .header-bg to position:absolute, the background ima ...

Sending Django Variable With Javascript

As a newcomer to Javascript, I am grappling with retrieving the value of a variable from my HTML form. My current code seems to be somewhat functional - I added an alert to test the logic and found that the else statement is working fine. However, I'm ...

Managing and Streaming Music in a Rails Application

Currently, I am storing mp3s using paperclip and they only play back if I utilize Amazon S3. However, I am hesitant to use Amazon S3 because I am unsure how to secure the files. Now, I am reconsidering my approach as I need to secure the mp3s and provide ...

When the text is in motion, the ::before element will stay static

I'm working on creating a unique custom SVG underline for a header design. My goal is to achieve something similar to this: https://i.sstatic.net/EI1aT.png Here's what my code currently looks like: HTML: <div class="container"> ...

Displaying and hiding the top menu when the div is scrolled

I have developed a script that is designed to display the menu in a shaking motion and hide it as you scroll down. It functions properly when scrolling within the body of the webpage, but I am facing issues when attempting to do so with a div that has an o ...

How can you position the nav collapse toggle to the far right while still allowing it to collapse downwards on smaller devices with Bootstrap 5?

I am in need of a navigation section that is always visible on all devices, with a collapsible toggle aligned to the right. In Bootstrap 5.2, if I place the collapse toggle after the <div class="collapse navbar-collapse ..., the collapsible conten ...

What causes the slight shifting of on-screen elements when the doctype is removed from an HTML document?

During the process of converting from HTML4 to HTML5, I compared my html4 and html5 pages and noticed that removing deprecated elements after the doctype declaration was causing slight movements in on-screen elements. For example, in the code snippet below ...