Navigate to the left smoothly while maintaining an inline display and automatically adjusting height, with rows functioning correctly but columns

My layout consists of a grid with 8 boxes containing images. Each row has 4 columns, and there are 2 rows in total. The boxes are set to float: left and display: inline. Everything aligns perfectly when the height is fixed.

Here is an example:

Example Image

However, when I add height:auto, the second row stacks at the third column.

Here is how it looks:

Stacked Rows Example

I want all rows and columns to align properly without skewing or stretching the images. I am open to any solution (jQuery or other) as long as the desired result is achieved.

I have tried various solutions such as clear both, vertical-align: top, clearfix after, display: table-cell instead of display: inline, etc. I have exhausted all online resources for solutions.

Below is the CSS code snippet:

.post{
    float:left;
    display:inline-block;
    list-style: none;
    width: 200px;
    height: auto;
    overflow:hidden;
    margin-right: 12px;
    margin-bottom: 12px;
    padding: 10px;  
    background-color: white !important;
}

.post-body { 
    width: 100% !important;   
    height: auto;
    overflow: hidden;
    padding: 0px !important;
    margin: 0px !important;
}

.post img {
    width: 100% !important;
    height:auto;
    padding: 0px;
    margin: 0px;
}

This layout is on the Blogger.com platform, making it hard to share the entire HTML. However, here are the main sections:

<b:section class='main' id='main' maxwidgets='3' showaddelement='yes'>
<b:widget id='Blog1' locked='true' title='Blog Posts' type='Blog'>
<b:includable id='main' var='top'>
<b:includable id='post' var='post'>  
<div class='post-body entry-content' expr:id='&quot;post-body-&quot; + data:post.id' itemprop='description articleBody'>
<data:post.body/>
<div style='clear: both;'/> 
</div>
</div>
</b:includable>
</b:includable>
</b:widget>
</<b:section>

Answer №1

The best answer on this page can be found here: div float or display inline-block to left AND top. Another helpful resource is JQ-Masonry at

Answer №2

It appears that you have two primary divs set up, with one for the first line and another for the second line, possibly with additional divs inside containing images? To address this layout issue, consider adding the following code snippet:

<div style="clear:both;">
</div>

between the closing tag of the first line div and the opening tag of the second line 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

Frequently encountering broken styles in Magento 1.9 due to missing CSS and JS files

Recently, I've been facing frequent style breaking issues on my Magento sites (1.9.2+). This results in the home page displaying only text with missing CSS, JS, and images. To fix this problem, I usually clear the cache by deleting the var/cache fold ...

Excessive text in HTML div element

Whenever I maximize the window in any browser, I type a long string in a div or span tag. It perfectly fits within the div tag. However, when I minimize or compress the browser width, the text spills out of the div area. I am looking for a solution to set ...

The compatibility issue between Jquery highlight and show more/less function is causing them to malfunction when used

I am facing an issue where, while trying to search for a specific word to highlight it, the "show more" button closes and only displays the text prior to clicking the button. How can I ensure that the expanded content remains open while searching for a wor ...

Hover over images with the use of html or css styling

I've been attempting to change an image on my website when I hover over it, but despite looking at various examples, I still can't get it to work. Can someone please help me figure out what I'm doing wrong? Below is the HTML code I'm u ...

Enhancing your CircularProgressBar with dual variant colors using Material-UI

https://i.sstatic.net/0d35R.png Best practices for customizing MUI components with React ...

Overlapping spans

I am trying to stack these spans on top of each other without much success, http://jsfiddle.net/76NNp/79/ <td class="rtf hov"> <div>Investment</div> <div class="mub eub"> <span style="float:left">Test</spa ...

What is the determined method for calculating the pixel size of an SVG image?

Did you know that the Stackoverflow logo is actually an <a> element with a SVG image as its background? #hlogo a { text-indent: -999em; display: block; width: 200px; height: 50px; background-image: url("img/sprites.png?v=c4222387 ...

Center the R Shiny showNotification on the screen

Currently, I'm exploring ways to customize the feature of showNotification() in Shiny. Link to example notifications My goal is to have the message appear at the center of the screen instead of the bottom-right corner. While it doesn't seem pos ...

Steps for generating a sophisticated shadow effect using CSS

Currently in the process of revamping a poorly designed website by replacing images with CSS whenever possible, along with other updates. I have encountered a challenging graphic (there are three of these, one for each active tab): https://i.sstatic.net/1 ...

Increase the background image size for a <li> element

I am working with an unordered list and have set it up to display a background image on the li element when the cursor hovers over it: <div class="sidebar"> <ul> <li>test</li> <li>test</li> ...

What is the best way to align two buttons side by side when they are each contained in separate forms?

Is there a way to align the submit buttons in two separate forms side by side? The first form should display as a block level element, while the second form can be inline-block. <form action="#"> <div class="form-group"> <lab ...

Struggling to create responsive embedded videos?

https://i.sstatic.net/R0GUn.jpgI have successfully created a responsive video, but there seems to be an issue with the width to height ratio when the browser is fully stretched. The iframe appears narrow and tall in this situation. However, when the browse ...

Changing Scroll-bar Colors in JavaFX TableView Using Java

I modified the style of my TableViews programmatically with the following code- tableView.setStyle("-fx-base : #333333; -fx-background-color : gray"); Now I am looking to change the color of the scroll bar using the same method. I prefer not to add a ...

Is there a rationale behind using intricate CSS classes such as page-left-column-container-box-element-header for technical purposes?

What is the reasoning behind using this specific CSS and HTML structure for styling web pages? <div class="page"> <div class="page-left-column"> <div class="page-left-column-container-box"> <div class="page-left-column-con ...

Manipulating anchor links with jQuery by adding and removing classes

I am struggling to understand why I cannot remove a class from an element and then add a new one. Changing the CSS using .css(...) works, but for some reason .removeClass and .addClass are not functioning. Interestingly, I am able to successfully add and ...

Elements contained within the enclosing div will not be visible

I'm currently working on a responsive webpage, and I've encountered a new issue that I can't seem to resolve. I've wrapped three separate divs within a parent div, but for some unknown reason, the child divs are not displaying. Can some ...

Grid functionality in Bootstrap not responsive on mobile devices

I have created a grid structure for my website using bootstrap 3. It looks great on desktop, but when I resize the window it does not switch to mobile or tablet view. What am I doing wrong? On desktop, I want each panel to take up 1/6 of the row, and on ...

What is the best way to evenly space out divs filled with images in a horizontal layout?

On my website, the header consists of text and a logo. Since the font used is not standard, the text is displayed as an image. I am looking to create a design in which the elements of the site adjust according to the size of the browser window. Is this wh ...

Click outside of this popup to dismiss it

I have been struggling to figure out how to make this popup close when clicking outside of it. Currently, it only closes when clicked directly on it. Your assistance in this matter is greatly appreciated. Here is the HTML code: <h2>Popup</h2> ...

Issues with loading CSS, JavaScript, and links when deploying a Spring Boot application as a WAR file in Tomcat

My Spring boot web application runs smoothly as an executable jar, but when I build it as a war and deploy it to Tomcat, the CSS and JS files fail to load. Upon further investigation, I discovered that all links are pointing to the root context path "/" I ...