Tips for organizing image divs into groups of three?

Hey everyone, I have multiple divs with classes like ItemLeft, ItemMiddle, and ItemRight. I want to know how I can display these image divs in rows of 3 using CSS or any simple method. Currently, all the images are displaying one below the other.

I am fetching the image divs through a getJSON call like this:

$.getJSON('http://www.awebsite.com/get?url=http://www.bwebsite.com/moreclips.php&callback=?', function(data){
    //$('#output').html(data.contents);

 var siteContents = data.contents;  

document.getElementById("myDiv").innerHTML=siteContents

Please note: every time I make the getJSON call, I receive 6 image divs which appear stacked vertically instead of 3 in a row!

Below are the div images retrieved by the getJSON call, but they are displayed one after the other rather than in rows of 3:

<div class="ItemLeft">


  <div class="Clipping">        
    <a class="ImageLink" href="/videos/id1234" title="galaxy">
      <img class="ItemImage" src="/Images/galaxyimg.jpg" alt="galaxy" />
      <img class="OverlayIcon" src="/Images/1.png" alt="" />
    </a>
    <a class="DurationInfo" onmouseover="showDuration2(this);" onmouseout="hideDuration2(this);" href="/videos/id1234"><span class="Text">51:57</span></a>
  </div>

  <div class="Title"><a href="/videos/id1234" title="galaxy">galaxy</a></div>

  <div class="VideoAge">1 daybefore</div>

  <div class="PlaysInfo"> broadcast 265</div>

</div>

Answer №1

After reviewing your query, I have replicated your leftItem to generate multiple items and included a fiddle link below: http://jsfiddle.net/tVMet/

To make your divs float properly, you need to assign a float property to them. At the end of the third div, insert another div element for clearing the float.

<div class="clear" />



.ItemLeft, .ItemMiddle, .ItemRight
{
    float:left;
}
.clear
{
    clear:both;
}

Answer №2

Creating an Image Gallery Layout:

    <div class="imagediv">

    <div class="imageitem"> // add image content here </div>
    <div class="imageitem"> // add image content here </div>
    <div class="imageitem"> // add image content here </div>

    <div class="clearfloat"></div>

    <div class="imageitem"> // add image content here </div>
    <div class="imageitem"> // add image content here </div>
    <div class="imageitem"> // add image content here </div>

    <div class="clearfloat"></div>

    </div>

Styling with CSS:

.imageitem {
   float:left;
}

.clearfloat {
   clear:both;
}

Answer №3

Creating a layout with multiple elements next to each other can be achieved in HTML using tables or by utilizing divs with the CSS property float: left. It is crucial to remember to insert a line break after each group of elements to prevent them from stacking on the same line.

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

Tips for efficiently obtaining JSON Ajax data, saving it to local storage, and presenting it in a jQuery Mobile list view

Upon calling ajax to my server, I receive 1000 units of data which I then store in my local storage before displaying it on a jQuery mobile list-view. However, this process takes around 50-60 seconds to complete. Is there a way to optimize this and make it ...

Transfer a term to a different division - JavaScript Object Model

I am trying to achieve a specific task where I need to move one term under another in SharePoint. However, despite my efforts using JSOM and SharePoint 2013, I have not been able to find a direct method for moving terms. The code snippet I have used below ...

Designing draggable tags similar to those on LinkedIn, incorporating a parent div element containing an SVG image and text

Lately, I've been exploring the world of CSS and Angular. Can someone give me a jumpstart on using CSS to design an element like the one shown in this https://i.stack.imgur.com/vcR3Z.png image? Essentially, this outer tag consists of a div element th ...

leveraging the bootstrap grid system for a responsive layout that positions an image beside a div

I am working on incorporating an image next to a div as seen in Facebook comments. Here is the HTML code I currently have: <div className="row"> <div className="col-sm-1"> <img className="img-thumbnail" ...

Jquery solution for toggling multiple Divs individually

I'm currently working on a small application that has both a sidebar menu and a header menu. My goal is to have all items in these menus toggle the visibility of content in one main window or page. When a button is clicked, I want it to show the corre ...

Populating JQuery autocomplete using a PHP array

As a beginner in the world of JavaScript and JQuery, I have been scouring the internet for hours trying to find a solution to my query. My goal is to populate a JQuery autocomplete feature using an array that I have created in PHP. Here is a glimpse of the ...

Troubleshooting Problems with jQuery and JSON

After compiling my data into JSON using PHP with 2 parameters, response and status, I encountered an issue. The response parameter contains the data that PHP retrieves when AJAX is processed, while status represents the error code or success command. Howe ...

choose characteristic using a filter

Let's consider the following scenario: <a data-id-5='1'>1</a> <a data-id-6='1'>2</a> Is there a way to use jQuery to select all attributes that start with data-id-? Can this be done? ...

Tips for keeping a div fixed at the bottom of the page when scrolling after a checkbox has been selected

Typically, I don't ask questions until I've exhausted all other solutions...but here we are. Despite my efforts in searching, I have not found any similar questions to mine. So, my question is: How can I make a div at the bottom of the page sti ...

Is there a way for ResponsiveSlides to fade the pager without causing any disruption to the content below, all

I have been working with the Responsive Slides jQuery plugin and made some custom modifications. Everything is going smoothly, but I am facing an issue with getting the pager and next/prev controls to fade in when hovering over the container. Although I s ...

Angular's counterpart to withCredentials in jQuery AJAX

Currently, I am using Angular to make an HTTP GET request to my local CouchDB. The code snippet below demonstrates how it is done with AngularJS: var req = { method: 'POST', url: BASEURL+'_session', headers: { &apos ...

Having trouble applying CSS styling to the div element

I'm new to CSS and struggling with aligning content within a div. Specifically, I can't get the actual price (striked off) to display next to the discounted price in the card - it keeps appearing underneath. Any ideas on how I can improve my CSS ...

IE11 not processing jQuery ajax response correctly

While creating a login page using jQuery/AJAX, my code is functioning perfectly on all browsers except for IE11. In IE11, I am encountering the following exception: SCRIPT7002: XMLHttpRequest: Network Error 0x800c0008, The download of the specified resour ...

Prevent the occurrence of a page break in between dt and dd elements

There are multiple instances of <dd> and <dt> elements in a specific order on this page. For instance: <dt> "Here is some random text" </dt> <dd> <input type="text"> <span></span> </dd> This str ...

Extract the value of a text box from within a div using jQuery in PHP

By clicking on the div or a tag, I aim to access the user id stored in the hidden field for each user. <?php foreach($user as $users) {?> <div class="user1"> <a class='inline' href="#inline_content" id="new2" > <img src="&l ...

jquery for delaying the loading of images

I want to sequentially load four divs one after the other with specified time durations, div1 should load in 1 second div2 should load in 3 seconds div3 should load in 5 seconds div4 should load in 7 seconds Here's the code I've written for ...

Saving data in HTML using PHP and then downloading it

Currently, I am tackling a project involving a website that is connected using PHP. The main function of the PHP script is to modify an HTML file stored on the server and then allow the user to download it. I attempted to use PHP DOM for this task but unf ...

Showing data stored in a mySQL database on a Flot chart

I have a php script that fetches data from a mySQL database and then attempts to display it on a graph using flot. Despite confirming that the values are being retrieved correctly and encountering no errors, the graph fails to render. Any insights into wha ...

Creating numerous Facebook posts using jQuery technology

I am currently facing a challenge when attempting to publish multiple facebook posts on a webpage using jQuery. Although I have managed to successfully post the first facebook post, I am encountering difficulties when trying to post another one. What coul ...

Iterate through child DIVs to obtain their corresponding IDs

I've structured my HTML code like this (IDs are placeholders for illustration purposes): <div id="selected-area"> <div id="01" class="folder-ready"> </div> <div id="02" class="folder-ready"> </div> <div id ...