Collapse the columns and set them to float on the left side

My current setup might not be the most visually appealing, but it gets the job done. I have several col-md-4 tags in place. The issue arises when the height of the first tag is larger than the ones next to it, causing the subsequent tag to appear in the middle of the row instead of below the first one with the "TestTT..." string.

https://www.bootply.com/HJbiqZXmkE

The challenge I'm facing is that I am using AngularJS and looping through multiple elements with ngFor, making it difficult to dynamically adjust the layout based on the number of items being displayed.

Answer №1

When looping through div elements, they inherit default CSS styles. The content within the div may be uneven, which requires Bootstrap to automatically adjust for the best display results, as intended. To achieve this, you need to set a specific height for your div, although this could potentially affect responsiveness. In such cases, it might be necessary to write custom @media code in CSS. If you want to use four spaces without using a row, you can structure it like this:

<div class="col-md-4 customCss">Content1</div>
<div class="col-md-4 customCss>"Content2</div>
<div class=“col-md-4 customCss"><Content3</div>

In CSS:

.customCss{
  min-height:50px;// Your desired properties
}

UPDATED

I have used PHP in my example, but you can implement this in Angular or any other language of your choice.

Assuming $rows is an array:


  <?php 
  $rows =  array(array('id'='a'), array('id'='b'),array('id'='c'), array('id'='d'),array('id'='e')); 
  $i=0; // Initialize counter 
  foreach ($rows as $row){  
    if ($i%3==0) { // Check if the counter is a multiple of 3 ?>
        <div class="row"> <?php } ?>
           <div class="col-md-4">
             Content
           </div>        
      <?php $i++; ?>
      <?php if($i%3==0) { // Check if the counter is a multiple of 3 ?>
          </div>
        <?php } ?>
     <?php } ?>
     <?php if($i%3!=0) { // Close the div if loop does not end exactly on a multiple of 3 ?>
         </div> 
    <?php  } ?>

Feel free to reach out if you need further clarification!

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

The script is unable to locate the property 'indexOf' because it is undefined

Searching for a specific value in an array using ui-select to capture values. A function is created to verify the existence of the value, which works perfectly fine. However, the console displays multiple instances of the error 'Cannot read property & ...

Having trouble with your website not adjusting properly when resizing the browser or viewing it on a mobile phone

My website is not adapting properly to different screen sizes, even after I have added the META tags below. Any advice would be appreciated. Thank you. HTML <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="UTF-8> ...

Having trouble with Javascript/jQuery not functioning in IE8?

My current project involves a website that functions smoothly in Chrome, but encounters issues with running JavaScript/jQuery scripts in IE8. Even a simple alert on page load fails to execute. Admittedly, my approach is a bit messy as I have mixed CSS an ...

Fetching data from the server using Angular and parsing it as JSON

Can anyone provide some insight on the best way to use jsonObjects in ng repeat? Here is my code: This is the response I get from PHP: die(json_encode(array('sts'=>'success', 'title'=>'*****', 'msg' ...

Mastering the use of expressions in ng-click and ng-show in AngularJS

I've been working on creating expandable rows within a table, but I'm encountering some issues. Despite not receiving any error messages, the functionality isn't behaving as expected. I suspect there might be an issue with how I'm using ...

How to exclude elements nested inside another element using CSS or XPath techniques

Presented here is a snippet of XML code: <xml> <section> <element>good</element> <section class="ignored"> <element>bad</element> </section> </section> </xml> Identifying a ...

Can someone assist me in creating a clickable link that opens a menu in HTML when clicked?

I have been attempting for the past few days to open the megamenu by clicking on a link, but despite my efforts, I have not been successful. After reviewing some code, I discovered a clue in the CSS. It seems that setting the visibility value to visible wi ...

Why is my model not being updated when selecting an option in Angular UI Select-UI?

I want to streamline the use of select-ui by creating a wrapper in a directive. This way, I can easily update the control in one place and avoid the hassle of scattering it all over my site. Despite building a wrapper, I'm facing an issue where the v ...

Empty ng-repeat iteration despite the presence of HTML elements

After receiving a list of numbers from an API, I am using ng-repeat to display them on a web page. However, even though 10 elements are created for 10 numbers, the content is empty. Despite trying various combinations, I am unable to get the content to dis ...

What is the best method to apply a background image in HTML that functions properly in Internet Explorer?

Having trouble getting this CSS code to work in Internet Explorer. Need a solution that is compatible with IE for setting the background. body { background: url("images/Login-BG.png") no-repeat center center fixed; -moz-background-size: cover; -webkit ...

Highchart in ionic 2 not displaying

https://i.sstatic.net/q2CPR.png I inserted code for a highchart on my webpage, but it's not appearing I followed instructions from this video tutorial https://www.youtube.com/watch?v=FSg8n5_uaWs Can anyone help me troubleshoot this issue? This is ...

The orientation of the displayed images has turned vertical, breaking away from the traditional horizontal

My problem lies in trying to horizontally display the images fetched from the database. I attempted using "inline-block" but it proved ineffective. Despite looking for alternative solutions, none seemed to be a fit for my situation. $db = mysqli_connect(" ...

Is it possible to resize the background-image style?

When using the regular img tag in HTML, you can specify the width and height, and the browser will scale the image. If the dimensions are not too different from the original, the result is usually decent. For example, you can scale the avatar image to 32x ...

Using AngularJS to transfer JSON data to a directive

I am relatively new to Angular and making progress. It seems like I have encountered an issue with passing a JSON file from the controller to a directive using isolated scope. Below is my controller that communicates with the "dataArchive" factory: .cont ...

Efficiently adjust the width of a child div to automatically fit within

I stumbled upon this fascinating jsfiddle on this website that almost completely addresses my concern, solving up to 90% of it. Check out the JSFiddle Nevertheless, I am keen to incorporate margins within the inner divs. Despite attempting to modify the ...

maintaining the alignment of three div elements

I am struggling to keep three divs side by side within a container, each containing an image and text below it. I had this layout working perfectly before, but now the right div falls underneath the other two when the screen size is reduced, followed by th ...

Error: Unable to access the property 'fontSize' as it is undefined

<!DOCTYPE HTML> <html> <head> <title>Interactive Web Page</title> <link id="mycss" rel="stylesheet" href="mycss.css"> <script> function resizeText(size) { va ...

Spin the AngularJS icon in a complete 360-degree clockwise rotation

Hey there! I'm new to Angular and I'm trying to create a button that will make an icon inside rotate 360 degrees when clicked. Right now, the entire button is rotating instead of just the element inside it. I want only the "blue square" to rotate ...

Submitting AngularJS data to SQL Server

Having a slight issue with my post php file. Managed to get it to post to the database, but struggling to retrieve the player name from angularjs. $scope.addPlayer = function (playerName){ alert(playerName); $http.post("insert.php",{'Name&a ...

Bone Structure Styles - adaptable form

I'm currently working on a form using skeleton css and initially set it up with a three-column layout. However, I found that this created too much white space due to varying content lengths in each column. I would like to switch to a horizontal layout ...