Matching up irregular rows in div-made table

I have created a table using div elements that contain images as cell data. When an image is missing, I would like to center the remaining images in the row like this:

With all images present:

xxxxx
xxxxx

Missing images (2 in the second row):

xxxxx
 xxx

Currently, the images align to the left like this:

xxxxx
xxx

This is the CSS for the table:

.table
{
    margin-top:5px;
    margin-left:15px;
    margin-right:15px;
    display:  table;
    width:auto;
    border-spacing:0px;
}

.row
{
   display:table-row;
   width:auto;
   margin-left:auto;
   margin-right:auto;
}

.cell
{
    float:left;
    display:table-column;
    width:auto;
}

I attempted to use auto margins for left and right for the row, but it did not work. Do you have any suggestions?

Edit

<div class="table">
         <div class="row">
            #if ($has1)
                <div class="cell"><a href="#1"><img src="1.jpg" width="138"/></a></div>
            #end
            #if ($has2)
                <div class="cell"><a href="2"><img src="2.jpg" width="138"/></a></div>
            #end
            #if ($has3)
                <div class="cell"><a href="#3"><img src="3.jpg" width="138"/></a></div>
            #end

        </div>
         <div class="row">
            #if ($has4)
                <div class="cell"><a href="#4"><img src="4.jpg" width="138"/></a></div>
            #end
            #if ($has5)
                <div class="cell"><a href="5"><img src="5.jpg" width="138"/></a></div>
            #end
            #if ($has6)
                <div class="cell"><a href="#6"><img src="6.jpg" width="138"/></a></div>
            #end

        </div>
  </div>

Answer №1

Alright, give this a shot:

.table
{
    margin-top:5px;
    margin-left:15px;
    margin-right:15px;
    display:  table;
    width:auto;
    border-spacing:0px;
}

.row
{
   display:table-row;
   width:auto;
   margin-left:auto;
   margin-right:auto;
   text-align:center;
}

.cell
{
    /*display:table-column;*/
    display:inline-block;
    width:auto;
}​

For example: http://jsfiddle.net/JARQs/

Answer №2

Give this a shot:

.row {
   display: table;
   width: auto;
   margin-left: auto;
   margin-right: auto;
   text-align: center;
}

An alternative approach is to wrap the content in a container with display: table CSS and keep the original .row class.

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

Creating a div that is subtly askew

When it comes to positioning a div 15 pixels off-center horizontally from the page, traditional methods like setting margins to auto or using position:absolute may not work in this situation. The challenge lies in ensuring that the div scales correctly a ...

Exploring Selenium: Clicking on Auto-Complete Suggestions using Python

Attempting to interact with an auto-complete search bar on the site in order to search for results. Wanting to click on the drop-down element that appears after entering a city name to perform a full city name search and obtain results. Below is the cod ...

The v-autocomplete feature in vuetify doesn't allow for editing the text input after an option has been selected

Link to code on CodePen: CodePen Link When you visit the provided page and enter "joe" into the search box, choose one of the two Joes that appear. Try to then select text in the search box or use backspace to delete only the last character. You will no ...

Tips for adjusting the size of numbers (e.g. 0, 1,4..) using CSS

I have a paragraph on my website that contains a phone number and an email address within the header section. I have styled them to be the same font-size: small, but for some reason, the phone number appears slightly larger than the email address when view ...

Show the extracted data on the following web page once it has been cleaned

I am looking to connect a python file with an HTML page using Flask application. On the first page (upload.html), the user is required to select the job field and job title from two dropdown menus. Afterwards, the user needs to upload a file containing a l ...

How can I detect a change in user input using jQuery?

When utilizing jquery .oninput with an element, the event will trigger instantly whenever there is a change in the input value. In my scenario, it is necessary for me to validate the input value by calling the service immediately after any changes occur. ...

The navigation bar is showing my logo in a blurry and small format when viewed on a desktop

Currently, Twitter Bootstrap is being utilized on my website and a high-resolution logo has been successfully uploaded. The dimensions of the logo are 529 x 100 pixels, and here is the relevant CSS: .navbar-brand { float: left; padding: 12px 15p ...

Troubleshooting: Issue with Jquery functionality when selecting an item from dropdown menu

I've been trying to dynamically select an item from a dropdown menu, but for some reason it's not working even though I've followed the suggestions on this forum. Here is my HTML: <div> <div class="form-group"> <la ...

Displaying images stored in Laravel backend using Angular frontend

I am facing a challenge where I need to display an image on the frontend using Angular, but the image is stored on the backend in Laravel 5.5. I have already attempted some solutions, but they have not worked. What should I do? Below is the error message ...

Assistance required: The database is not found upon page reload. How can this be resolved?

My HTML5 code has created a database with create, add, delete, and print operations. However, the ObjectStore is re-created every time I load the page, and the additional values stored are not present upon reloading the page. What could be wrong with my ...

What is the best way to align text in the vertical center?

Trying to design a promotion layout with an image on the left and text on the right. How can I center the text vertically to appear in the middle of the picture? Attempts using margin and vertical-align have not been successful. Also, why does the text di ...

Creating a replica of Airbnb using Bootstrap 5: Transforming the search bar into a button

I am looking to implement a search bar button similar to the one on airbnb using bootstrap 5, like this example: https://i.sstatic.net/oIIzv.png Here is an example of HTML code that you can use: <button type="button" class="btn btn-ligh ...

"Effortless CSS Formatting in VS Code - A Guide to Automatic Styling

Recently started using VS code and I'm on the lookout for a solution to automatically format CSS whenever I save my work. Strangely, my searches haven't led me to any reliable extensions or clear guides on how to achieve auto formatting in VS cod ...

Arrange various numbers in a single row to be in line with

I'm utilizing bootstrap in an attempt to design the layout depicted below: https://i.sstatic.net/0w06U.png Here is a simplified version of my code: .curr { font-size: 12px; font-weight: 700; letter-spacing: .5px; } .price { -webkit-tap-h ...

Integrate a button following the first paragraph exclusively when there are two or more paragraphs present

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> jQuery(document).ready(function($) { if ( $('p').length < 1 ) { $('p:last-child').after('<div id="toggle" class="btn"> ...

Creating two div elements next to each other in an HTML file using Django

I'm having trouble arranging multiple divs in a single line on my website. Utilizing float isn't an option for me due to the dynamic number of divs generated by Django posts. Here is the code I am currently using: Index.html <!DOCTYPE html&g ...

How should one go about properly sizing and formatting image icons?

Currently, I'm exploring the most efficient ways to optimize image loading speed on a webpage. Specifically, I am looking for advice on the best method for resizing an image from 1600x900 to 890x500. Method 1 Utilize the following code: <img src= ...

The table is too large for the parent div in which it is placed, causing

Check out this example I have for putting a table in a div and making it fill the div: ex1_jsfiddle table { font-family: arial, sans-serif; border-collapse: collapse; width: 100%; height: 100%; table-layout: fixed; } td, th { border: 1px sol ...

Struggling to find a solution for altering font color with jQuery while creating a straightforward menu

I'm having trouble changing the color of the active button pressed to "color:white;"... Here is the link to the jsfiddle: http://jsfiddle.net/wLXBR/ Apologies for the clutter in the file, my css is located at the bottom of the CSS box (Foundation cod ...

Resolving CSS Fluid Image Problem

Even though my site background is responsive and functions well, I am encountering problems with the images. I want them to appear "fixed" in the same position as the background, regardless of resolution changes. For example, resizing the browser from 990p ...