Automated line wrapping within a div

My goal is to showcase images within a unique div structure. Currently, the arrangement appears as follows:

It seems that the green divs are extending beyond their parent div (the black one).

This is how it's structured:

<div class="photoView center">
    <div class="grid">
        <div ng-repeat="i in [1,2,3]" class="groupPhoto">
            <div ng-repeat="i in [1,2,3,4]" class="col-1-4 photoSimple" style="display:inline-block;"></div>
        </div>
    </div>
</div>

CSS :

.photoPrincipal {
  width: 600px;
  height: 300px;
  background-color: blue;
}

.photoView {
  width: 600px;
  height: 300px;
  background-color: rgba(0, 0, 0, 1);
  margin-top: 50px;
}

.photoSimple {
  width: 130px;
  height:75px;
  background-color: green;
  margin:10px;
  border: 2px dotted white;
  display:block;
}

UPDATE
I forgot to mention that I am utilizing SimpleGrid, a CSS library that provides grid-based styling. Currently, it functions properly with this setup: http://jsfiddle.net/jmsqskyn/

In essence, I aim to have four green divs per line. However, this is not happening.

I attempted to use display:block but it had no effect.

Answer №1

Here is a solution that may help:

  • To resolve the issue, I included a float:left property to .photoSimple, which requires clearing the parent container (.photoView).

  • An alternative approach is to use overflow:hidden in .photoView as a clearfix method.

  • You can find more information about clearfix at: .

See a live demonstration here: http://jsfiddle.net/jmsqskyn/

Another demo showcasing clearfix usage: http://jsfiddle.net/jmsqskyn/1/

.photoView{
    overflow:hidden; /* Added for clearing */
    width: 600px;
    /* height: 300px; */
    background-color: rgba(0, 0, 0, 1);
    margin-top: 50px;
}

.photoSimple{
    width: 125px;
    height:75px;
    background-color: green;
    margin:10px;
    border: 2px dotted white;
    display:block;
    float:left; /* Added for alignment */
}

Answer №2

To optimize your layout, consider changing the CSS property to display:inline-block for your DIV elements.

After making this adjustment, the updated code should look like this:

.photoSimple {
  width: 130px;
  height:75px;
  background-color: green;
  margin:10px;
  border: 2px dotted white;
  display:inline-block;
}

If you encounter any issues with using display:inline-block;, you can try replacing it with float:left;.

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

JS (jQuery) not working as expected - Laravel 8 integrated with Bootstrap 5 and jQuery

Having difficulty integrating bootstrap and jQuery with Laravel 8. Despite following multiple tutorials and meticulously following the steps, the buttons remain unclickable. It seems like the click function is not running at all. The app was initialized u ...

Comparison between UI Router and ngRoute for building single page applications

Embarking on a new Angular project, a single page app with anticipated complex views such as dialogs, wizards, popups, and loaders. The specific requirements are yet to be clarified. Should I embrace ui.router from the start? Or begin with ngRoute and tra ...

What is the most efficient method for creating and updating SKU combinations from JSON while also managing stock levels and reducing the number of database queries?

My inventory system organizes data by SKU, containing product options (represented here by values): --------------------------------------------------------- id color size material stock -------------------------------------- ...

Updating CSS for dropdown menu in Fluent/Fabric design

I am working with a dropdown component from Fluent UI and I am trying to customize the CSS of the dropdown options. Although I can add classes using className to the dropdown itself, I am facing difficulty in styling the dropdown options directly due to th ...

Best method for transferring Entity details to a jquery dialog box within ASP.NET MVC 3

I am currently working on an ASP.NET MVC 3 Page where I need to loop through a collection of objects in the Model. Each object will have a button next to its information for users to edit it in a jQuery UI dialog. However, I am facing a dilemma in finding ...

"Include the 'unsafe' prefix at the start of the URL in AngularJS

Whenever I attempt to access app://csttree?featuretype=cst_issue&verticalid=2132321&l1=3213&l2=3242 within my app, the URL gets parsed as ==> unsafe:app://csttree?featuretype=cst_issue&verticalid=2132321&l1=3213&l2=3242 Is ...

Include a personalized header in $http

In my factory, I have multiple functions that follow this structure: doFunction: function () { return $http({ method: 'POST', url: 'https://localhost:8000/test', data: {}, headers: { "My_Header" ...

Detailed enrollment procedure

I am facing an issue with the code in my HTML that validates input types. The system detects empty fields and prevents proceeding to the next step. How can I disable this validation as some of the fields are not required? For instance, the input type < ...

Utilizing external Cascading Style Sheets in AngularJS 1

Can an external CSS be applied to a component in AngularJS1? If yes, then how can it be done? I have only seen examples of applying inline css... ...

Code in JavaScript that shows only a portion of the selected option in a dropdown menu

I'm just starting to learn Javascript and I'm looking to create a script for a select tag that displays countries and their phone codes. My goal is to have the dropdown menu show both the country and code, but once the user selects an option, onl ...

Request for clarification on utilizing JQuery's $.get() function

I have a question that I am currently pondering: In the code provided at this link: , do you think it will work? Please explain. $.get('http://1.testaddress.com/ajax/remote.php?id='+id, responseCallback); Could the reason why ...

Using a different method to handle multiple callbacks in Angular or a suitable replacement for $.Callbacks

Is there a similar functionality in Angular to jQuery $.Callbacks? I am seeking a straightforward method to manage callback lists within Angular. My goal is to achieve the following using Angular: function Broadcast(){ var self= this; this._status ...

Tips for maintaining the original ng-click initialized value as the ng-init value after the page is refreshed

My ng-repeat feature includes buttons for liking and disliking images. The problem I'm facing is that each time the page refreshes, the count of likes and dislikes gets reset to the initial value set by ng-init. How can I maintain the incremented lik ...

Error Alert: jQuery Ajax Not Executing

Looking to send form data to PHP using jQuery. Check out the code below. -------------HTML FORM-------------- <div id="createQuestionBlock"> <form id="createQuestionForm" action="" method="POST"> Question Code: <input id="code" ...

Retrieve a variable from the context and assign it to the Angular scope

I'm having trouble accessing the sourcePath in the controller $scope. This is the code I have: (function() { var sourcePath; sourcePath = 'app/assets/javascripts/shared/controllers/some_controller.coffee'; angular.module("shared"). ...

Having trouble understanding why my submission button isn't working

I'm struggling to understand why my submit button isn't working correctly. Initially, I had an e.preventDefault() at the beginning and it didn't have any effect. However, after receiving advice from an instructor, I included it in the condit ...

What is the method to modify the text of an element without altering its existing properties?

https://i.stack.imgur.com/cBu6P.png $.ajax({ type: "GET", url: "my url" + x, datatype: "html", success: function(data){ //alert(x); //var Content = data; var sendId ; var data = $.parseJSON(data); ...

The presence of a PDF document within an iframe is causing overlapping with another element

I am facing an issue on a screen where I have to display pdf or html content using an iframe. To show the PDF or HTML, I am using an iframe and then displaying a popup when necessary to cover the entire screen. This setup works perfectly in most browsers. ...

How can we transfer a jQuery value from an input field without using a single

This task may seem challenging. How can single quotes be eliminated from a variable when passed directly to another variable? I am using jQuery variable $("#test").val() to extract the value from an input below <input type="text" ...

Struggling to connect with PouchDB within my HTML-based Web application

I am looking to integrate pouchDB into my WebApp so that upon clicking a button, the data from a JSON file will be saved to pouchDB. In the initial stage in my index.html, I included the following: <script type="module" src="pouchdb/packa ...