ways to create a separation between floated elements

For my photo wall, I am trying to create a specific pattern where every 1, 10, 11, 20, 21, and 30 displays a big image sized at 160x165. In between each pair of big images are 8 small images sized at 85x80.

The first line works as expected with one big image followed by 4 small images aligned together like a big one.

I want the second line to follow the same pattern, but with 4 small images appearing first, followed by the big image. The issue is that instead of displaying all 4 small images together, it initially shows 3 small images and then starts a new line with the remaining small image (desired outcome is for these 4 small images to form a square). I attempted to use a line break after positions $i=7,17,27... but it doesn't work well for floated elements.

<div style="width:350px"> 
    <?php
    $i=0;
    foreach($photo_array as $each){


        if($each!=''){
        $i++;

        $img_id=$username.$i;
         $pos=stripos($each,'&'); 
         $src=substr($each,$pos+1);

        $each_photo_string='user_data/post_img/'.$src;

        if(  (($i-1)%10==0) || ($i%10==0) ){
            echo '<img id="'.$img_id.'" class="p_photo_image" width="160"  height="165" style="margin-left:5px;float:left;"  alt="'.$each.'" src="'.$each_photo_string.'" >';
        }
        else{

                echo '<img id="'.$img_id.'" class="p_photo_image" width="85" height="80" style="float:left;margin-bottom:5px; margin-left:5px;"  alt="'.$each.'" src="'.$each_photo_string.'" >';
                if(($i%10)==7){
                    echo '<br>';
            }


        }

        }
    }

     ?>
</div>

Answer №1

If you have floated objects, using <br> is not recommended.

Instead of <br>, consider the following alternative:

<div style="float:left; width:100%; height:1px; margin:20px 0; display:block;"></div>

To create a break when dealing with floated objects, use another floated object with a margin attribute.

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

Horizontal rule located within a table but spanning the entire width

I wrote the following code: <table> {item.awards.map((obj,i) => <tbody> <tr> <td>Name</td> <td>:</td> <td>{obj.title}</td> </tr> ...

Is it possible to shift the "ul" block of the navigation bar to the right without compromising the responsiveness toggle button functionality?

I'm currently using bootstrap NavBar and encountering an issue where moving the ul block to the right is disabling the toggle button responsiveness. <head> <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" c ...

How to efficiently handle data binding for multiple users sharing common inputs within a table on an ASP.NET Razor Page?

I am currently working on a project that involves populating a table with member information such as name and email. Within this table, there are columns where a "warning" can be entered for each member, along with a textbox for additional information rega ...

What is the best way to stop Quasar dropdown list from moving along with the page scroll?

I am facing an issue with my code while using Quasar (Vue 3.0). The code snippet in question is: <q-select filled v-model="model" :options="options" label="Filled" /> When the drop-down menu is open and I scroll the pag ...

Complete a checkbox entry form and showcase it within a "division" on the current page

Hello everyone, I need some help. I have a form that I want to send to a specific div on the same page. This is what I am aiming for. I have a floating div named "basket" in the top right corner of my page where I want the form data to be displayed after s ...

Vanishing Submit Button with CSS

In my input submit button, I have included the following code: <input class="buttons" type="button" onclick="javascript:jQuery(xxxx)" style="font-size: 12px;" value="Invite to Bid"> Additionally, there is a CSS function that adds an elegant "Go" im ...

How come my jQuery isn't updating the class of a specific element?

I apologize if this question seems too specific to my own project, but I am facing a dilemma. I am attempting to change the color of the title of the user's current page to orange when hovering over the page name in the navigation menu. In simpler ter ...

Triggering OnClick() more than once may result in the function failing to execute as intended

My dilemma involves a table of cells where clicking a cell triggers an event. I need to dynamically add cells, so I plan to call OnClick again on all rows. But when I do so for the second time, cells that have already had OnClick called twice stop firing a ...

What is the best way to utilize AJAX for displaying data within a div element?

I am struggling with integrating two files - index.php and process.php. In my index.php file, there is a form that submits to process.php: <form class="form" action="process.php" method="POST" name="checkaddress" id="checkaddress"> <table> ...

Navigate to the top of the page prior to updating the Link route in NextJS

Whenever I click on a link to navigate to a new page, the page loads and immediately scrolls to the top. I want to change this behavior so that the scroll resets to the top before the new page is rendered. You can observe this issue on . If you scroll do ...

Can you please explain the purpose of the white space in the HTML code?

Currently, I am working on developing a mobile application, and as I start adding styles, I notice a mysterious blank space that seems to be appearing out of nowhere. Can anyone provide any insights or suggestions to help me troubleshoot this issue? https ...

Using the clip-path property to determine the content padding within a div

I am encountering an obstacle while attempting to insert icons into a polygon-shaped div. The problem lies with the padding, as the icons get cut off by the borders of the polygon. #container { width: 200px; height: 200px; border: 2px solid blac ...

What is the best way to prevent double clicks when using an external onClick function and an internal Link simultaneously

Encountering an issue with nextjs 13, let me explain the situation: Within a card component, there is an external div containing an internal link to navigate to a single product page. Using onClick on the external div enables it to gain focus (necessary f ...

Elements within the DIV tag are not displaying in a linear arrangement as intended

I'm having trouble creating a navbar with Bootstrap 4. The items in my div tag are not inline, and I can't align my nav item to the right. Here is the HTML code: <nav class="navbar navbar-inverse "> <div style="display:inline"> ...

Scrolling to the bottom of the page triggers jQuery to load additional content

Is your jQuery script not working properly when attempting to load more content upon reaching the bottom of the page? It seems to be functional on Safari/iPad and Android Mozilla browsers, but encountering issues on default Android and Chrome browsers. ...

Jquery adds a fun, wobbly effect to animations

I'm experiencing an issue with the animation I've implemented causing some slight shaking and wobbling of the text and certain elements which is affecting the overall look. You can view a live example of this behavior here: This problem specific ...

Attempting to create a button that will only appear for items with a defined value for a specific variable

I am currently facing an issue with a template that needs proper population. The store locator on my website lists pharmacies and displays their relevant information (phone number, address, hours of operation) along with three buttons (view store, view fl ...

Creating Custom Styles with Polymer for <content> Elements

Seeking help with styling using the ::content selector and custom CSS properties. Any insight would be appreciated! To simplify, I have a Polymer component utilizing a content tag that will always contain a paper-input: <template> <style> ...

Why is my Datalist control not showing up in ASP.NET?

For the past few days, I've been working on dynamically generating labels using a DataList in ASP.NET code. Despite confirming that the data is being pulled into the datasource and seeing the control display correctly in the HTML code 'design&apo ...

The boundary for the multipart/form-data in the $http post request is missing

I noticed that the boundary I set for the post call appears different in Chrome. How can I make my custom boundary "--test" display correctly on the request payload? var url = '/site/apkUpload'; var deferred = $q.defer(); console.log ...