Trouble with CSS Columns When Resizing Screen

I am currently struggling with a div that contains icons and text next to them. The issue arises when the window is resized smaller, causing the images and text to overlap and appear messy. Here is how it appears in full screen:

https://i.sstatic.net/fLPy1.png

And here is the chaotic result when the window is slightly resized:

https://i.sstatic.net/EBeFi.png

Below is my CSS code:

 
  .grid-wrap {
  margin-left: -3em;
  overflow: auto;
  height: auto;
}
.grid-col {
  float: left;
  padding-left: 3em;
  padding-bottom: 5px;
  width: 100%;

  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
.newspaper-col{
     -webkit-column-count: 2; 
    -moz-column-count: 2; 
    column-count: 2;
    -webkit-column-gap: 20px; 
    -moz-column-gap: 20px;
    column-gap: 20px;
    -webkit-column-rule-style: solid;
    -moz-column-rule-style: solid; 
    column-rule-style: solid;
    -webkit-column-rule-width: 1px; 
    -moz-column-rule-width: 1px; 
    column-rule-width: 1px;
}
.one-quarter {
  width: 25%;
}
.one-half{
    width:50%;
}

.one-third{
    width: 33%;
}
.one-whole{
    width: 100%;
}

Here is the HTML code:

                                        <div style="padding-left:10px; padding-top:10px">
                                        <ul class="grid-wrap one-whole plain">
                                            <li ng-repeat="item in items" class="grid-col one-quarter">
                                                <span style="display:inline-block; cursor:pointer" data-toggle="modal" data-target="#moduleOverride" ng-value="item" ng-click="moduleOverride(item)" ng-cloak>
                                                    <p><img style="float:left; margin-right:5px" ng-src="~/{{item.ModuleStateGraphicPath}}" /><span style="font-weight:bolder" ng-bind="item.ModuleHeaderText"></span><br /><span ng-bind="item.ModuleCalculatedStateText"></span></p>
                                                </span>
                                            </li>
                                        </ul>
                                    </div>

I tried utilizing the solution from this StackOverflow thread and the outcome can be seen below:

https://i.sstatic.net/lJg54.png The corresponding CSS for that design is as follows:

.dashboard-section > span:nth-of-type(4n+1){
clear:both;

}

The relevant HTML code looks like this:

<div style="padding-left:10px; padding-top:10px" class="dashboard-section">
                                            <span ng-repeat="item in items">
                                                <span style="display:inline-block; cursor:pointer" data-toggle="modal" data-target="#moduleOverride" ng-value="item" ng-click="moduleOverride(item)" ng-cloak>
                                                    <span><img style="float:left; margin-right:5px" ng-src="~/{{item.ModuleStateGraphicPath}}" /><span style="font-weight:bolder" ng-bind="item.ModuleHeaderText"></span><br /><span ng-bind="item.ModuleCalculatedStateText"></span></span>
                                                </span>
                                                <br ng-if="!(($index + 1) % 4)">
                                            </span>
                                        </div>

To provide some spacing, I added a width attribute to the parent span as shown below, but unfortunately, it did not fix the resizing issue:

<span style="display:inline-block; width:20%; cursor:pointer" data-toggle="modal" data-target="#moduleOverride" ng-value="item" ng-click="moduleOverride(item)" ng-cloak>
                                                    <span><img style="float:left; margin-right:5px" ng-src="~/{{item.ModuleStateGraphicPath}}" /><span style="font-weight:bolder" ng-bind="item.ModuleHeaderText"></span><br /><span ng-bind="item.ModuleCalculatedStateText"></span></span>
                                                </span>

I have hit a roadblock with this issue. Any help or suggestions are highly appreciated!

Answer №1

It's a breeze with the help of bootstrap:

<div class="row">
        <div class="col-md-3">.col-md-3</div>
        <div class="col-md-3">.col-md-3</div>
        <div class="col-md-3">.col-md-3</div>
        <div class="col-md-3">.col-md-3</div>
</div>

<div class="row">
        <div class="col-md-3">.col-md-3</div>
        <div class="col-md-3">.col-md-3</div>
        <div class="col-md-3">.col-md-3</div>
        <div class="col-md-3">.col-md-3</div>
</div>

Answer №2

I encountered an issue where the text next to images was wrapping inconsistently on different image/text pairs. Some wrapped to 2, 3, and even 4 lines, causing subsequent rows to not wrap all the way to the left of the div (refer to the image below).

https://i.sstatic.net/huvkb.png

To resolve this, I set each span to the same height so that each subsequent line could start all the way to the left as required.

                                                                <span style="display:inline-block;width:200px; height:100px; vertical-align:top; cursor:pointer" data-toggle="modal" data-target="#moduleOverride" ng-value="item" ng-click="moduleOverride(item)" ng-cloak>
                                                                <span><img style="float:left; margin-right:5px;margin-bottom:25px" ng-src="~/{{item.ModuleStateGraphicPath}}" /><span style="font-weight:bolder; vertical-align:middle" ng-bind="item.ModuleHeaderText"></span><br /><p ng-bind="item.ModuleCalculatedStateText"><br /></p></span>
                                                            </span>

Hopefully, this solution is beneficial to others facing a similar challenge. Happy coding!

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

Obtaining the ID of a moved item in Uikit's nestable component

I am currently utilizing the uikit framework and have a query regarding the nestable component. Despite seeking assistance in various places, none of the solutions seem to match my specific needs. My limited knowledge of JavaScript may be a contributing ...

What are the pros and cons of incorporating ID selectors in CSS?

This article discusses the drawbacks of utilizing ID selectors in CSS. Can you provide more information on the pros and cons of using ID selectors in CSS? In what scenarios should ID selectors be used over class selectors, and vice versa? Thank you. ...

What is the best way to add messages in between rows?

I'm working on a code snippet and I need help figuring out how to number all the rows in a table. When clicking on the "Read" button, I want a box to display below the associated row with a message. However, I'm struggling to correctly identify t ...

When sending an ajax request with HTML data as the payload

While working on an MVC program, I encountered an issue when trying to send data from a TextArea to the controller upon a button click. Everything worked fine until I had HTML-based data inside the TextArea. Here's a snippet of the HTML code: <te ...

Does Material-ui v4 display component names within the class attributes of the html DOM?

Upon transitioning from material-ui v3 to v4, it was observed that the react component/function names were included in the class attribute within the HTML. Is this normal? Could this potentially cause issues when trying to override class properties with n ...

Is it more effective to implement ng-required in AngularJS from the controller?

Trying to devise a clever approach for implementing ng-required. Imagine there are multiple inputs in my app with ng-required. <input type="text" id="one" /> <input type="date" id="two" /> <input type= ...

Customizing screen dimensions for a single page using jQuery mobile

I am currently facing an issue with adjusting the size of a specific page within my application. Even though I am using <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, target-den ...

Angular 7+: Trouble with displaying images from assets directory

Details regarding my Angular version: Angular CLI: 7.3.9 Node: 10.15.3 OS: win32 x64 Angular: 7.2.15 ... animations, common, compiler, compiler-cli, core, forms ... language-service, platform-browser, platform-browser-dynamic ... rout ...

Identify when objects in kineticJS are dropped

Key Concept Designing a match-the-following activity where red dots can be dragged to blue dots on the left. The draggable red dots must accurately match with the blue target dots. Objective Assigning values to each dot, and ensuring that once a red do ...

Update the value in JSON upon the click of a button

Currently, I am dealing with a nested buttonclick situation inside another buttonclick. Right now, my alert is working fine. $scope.getid = function (order) { $scope.chosen.id = order.id; $scope.chosen.status = order.point ...

Display data in an HTML table based on user search input using Angular

I am currently working on integrating a JSON file into my project, which will eventually be accessed through an API from a server. Right now, I am pulling data directly from an object. My goal is to build an HTML file that features a table with navigation ...

Prevent link from being clicked again in AngularJS after initial click

I'm in need of some assistance. I am trying to figure out how to disable the link (PAY Now) after it has been clicked on to prevent multiple clicks. <div class="Class1" data-ng-show="ShowButton == 'TRUE'"> <a href="javascript:void( ...

Error with infiniteCarousel in Internet Explorer versions 7 and 8 when using jQuery

Hello everyone! I've run into a little issue with some jQuery code I'm using. It was working fine before, but after making several changes and improvements, I can't seem to figure out what the problem is. I keep getting JS errors in both IE7 ...

How to customize the arrow color of an expanded parent ExpansionPanel in material-ui

Currently facing a challenge in customizing material-ui themes to achieve the desired functionality. The goal is to have the expansion panels display a different arrow color when expanded for improved visibility. However, this customization should be appl ...

Displaying a Div element containing dynamically calculated values based on selected options in Angular

As a newcomer to Angular, I decided to challenge myself by building a simple app. Currently, my select options only display the keys of a data object. What I really want to achieve is to show a value beneath the second select box for each team, which displ ...

Building an AngularJS project with Webpack is essential for optimizing performance and enhancing the overall

Currently, I am in the process of transitioning our AngularJS(1.4.X) project from a Ruby based build system to Webpack. Given that our project code does not utilize JS modules and follows an older Angular coding pattern, I am uncertain about how Webpack wi ...

Angular Text Input Box with Clear Icon

Can I implement a similar functionality like this -> Clear icon inside input text Is it possible to achieve this only using angular.js? I am trying to integrate it into my Angular application, but due to different private scopes, I am facing challenges ...

Ways to add style to Chrome without causing any changes in Edge

I'm working on fixing a bug in Chrome and have successfully applied a style to correct it. However, when I view it in Edge, the appearance is not right. How can I target only Chrome (version 60) with my styles, without affecting other browsers? @medi ...

Integrating jQuery class into code snippets

I have implemented a fixed header on scroll by adding the class 'fixed' and it is working fine. When I scroll down, after 50px, the 'fixed' class is added to my header container. However, when I scroll back up, the 'fixed' cla ...

Guide on how to eliminate the click effect from a Bootstrap 4 button

I have been struggling with the issue of removing the box-shadow effect from Bootstrap 4 buttons. I searched for solutions on various forums but couldn't find one that worked for me. So, I decided to try some custom CSS code I found online. I was able ...