Adjusting the width of the final card in the deck grid

Currently, I am utilizing angular-deckgrid for image display purposes. Within a container, there are two columns in which images are displayed with the column-1-2 class according to the documentation. However, in certain scenarios where only one image is present in the last row, I would like that particular image to occupy the entire width instead of the standard 50% space allocation.

The rendering of the two columns appears as follows:

<div deckgrid="" class="deckgrid ng-isolate-scope" source="loves">
   <div data-ng-repeat="column in columns" class="column column-1-2">
      <div data-ng-repeat="card in column" data-ng-include="cardTemplate" class="ng-scope"> "my card layout here" </div>
      <div data-ng-repeat="card in column" data-ng-include="cardTemplate" class="ng-scope"> "my card layout here" </div>
      <div data-ng-repeat="card in column" data-ng-include="cardTemplate" class="ng-scope"> "my card layout here" </div>
   </div>
   <div data-ng-repeat="column in columns" class="column column-1-2">
      <div data-ng-repeat="card in column" data-ng-include="cardTemplate" class="ng-scope"> "my card layout here" </div>
      <div data-ng-repeat="card in column" data-ng-include="cardTemplate" class="ng-scope"> "my card layout here" </div>
   </div>
</div>

It can be observed that the first column has three cards while the second column has two. My objective is for the third card in the first column to span the whole width. Unfortunately, achieving this via the controller is not possible due to the template not being rendered yet. I attempted a CSS solution along the lines of:

.column-1-2 div[data-ng-repeat]:last-child {
    width:200%!important;
}

However, I am unsure how to verify if the first and second columns have an unequal number of children using CSS.

Thank you.

Answer №1

Perhaps my understanding is flawed, but it seems like you can utilize the $last property of ng-repeat in conjunction with ng-class to add the class mylast-child to the last div within the ng-repeat.

 <div data-ng-repeat="card in column" 
      data-ng-include="cardTemplate" class="ng-scope"
      ng-class="{'mylast-child': $last}" > 
             "my card layout here"
 </div>


 .mylast-child {
     width:200%!important;
 }

In addition, ng-repeat offers other useful options:

Variable |  Type     |  Details
--------------------------------
$index   |   number |    iterator offset of the repeated element (0..length-1)
$first   |   boolean |  true if the repeated element is first in the iterator.
$middle  |  boolean | true if the repeated element is between the first and last in the iterator.
$last    |   boolean |  true if the repeated element is last in the iterator.
$even    |   boolean |  true if the iterator position $index is even (otherwise false).
$odd     |   boolean |  true if the iterator position $index is odd (otherwise false).

Answer №2

You may consider utilizing Angular's built-in methods

let firstDivCount =  angular.element(angular.element(".column")[0]).find('div').length;
let secondDivCount =  angular.element(angular.element(".column")[1]).find('div').length;

if(firstDivCount !== secondDivCount){
     //Add CSS styling
}

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

How can filters be effectively utilized alongside transclusion within directives?

Seeking advice on applying a filter to the transcluded text within my directive. Struggling to determine the best approach, I currently have a working version that utilizes the compile function to access the transcluded text. Take a look at this JSFiddle ...

I am looking to save the session value into the search box of the appTables application by utilizing jQuery

Is there a way to save the session value in the search box of appTables by using jQuery? <?php $session = \Config\Services::session(); ?> <script type="text/javascript"> $(document).ready(function () { var searc ...

jQuery UI Sortable: Efficiently Drag Items Across Multiple Interconnected Lists

One feature of using jQuery UI Sortable is the ability to make the sortable item container scroll when an item is dragged. This can be achieved by specifying the scroll option. In my case, I have several sortable lists that are connected within separate c ...

Triggering a specific outcome with every user interaction involving the selection of an element

How can I trigger this effect each time the user clicks on the element using jQuery? I have added a "ripple" class upon clicking, but when I click on the element for the second time, the effect does not execute because the class has already been added. Ho ...

What is the best way to line up my columns when they are split between groups of three and two?

I am having trouble aligning my columns in the way I want. The image shows that some tables have 3 columns while others have 2, and I would like to align the blue with the blue and the red with the red as shown in the picture: https://i.stack.imgur.com/1bL ...

Is it advisable to authenticate/authorize static files employed in pages that require authentication?

I am in the process of developing a cutting-edge angular 2 application. All back-end functionality is handled through REST API, ensuring seamless communication between the client and server. For enhanced security measures, all APIs that require authentica ...

How can I retrieve an array from the server side using AngularJS?

Currently, I'm involved in developing a web application meant for team collaboration. While the login and signup pages have been set up, other members of my team are focusing on the server (built with node.js and express framework) and database aspect ...

The button remains in a pressed state when viewed on a mobile device

This button is functioning properly in desktop view, but in mobile view the button remains pressed down. :root { --green: #4285f4; --black: rgba(9, 13, 25, 0.752); --box-shadow: .4rem .4rem 1rem #ccc, -.4rem -.4rem 1rem #fff; --box-shadow-inset: ...

The ng-route feature seems to be malfunctioning and I am unable to identify the error, as no information is being displayed in the console

Here is the code in my boot.php file where I have set up the links <ul class="nav nav-pills nav-stacked"> <li role="presentation"><a href="#/valley">Valley</a></li> <li role="presentation"><a href="#/beach"> ...

Troubleshooting a live chat box for CSS alignment issues

Need help with aligning a live chat box on every webpage? Check out this example for reference: You can find my code here: https://jsfiddle.net/fn77d0de/2/ ...

Animated CSS side panel

I'm currently working on creating an animation for a side menu. The animation works perfectly when I open the menu, but the problem arises when I try to animate it back closed. Is there a property that allows the animation to play in reverse when the ...

$filter is functioning correctly, however it is generating an error message stating: "Error: 10 $digest() iterations reached. Aborting!"

Here is an example of a JSON object that I am working with: { "conversations":[ { "_id": "55f1595d72b67ea90d008", "topic_id": 30, "topic": "First Conversation", "admin": "<a href="/cdn-cgi/l/e ...

My child template in Angular UI is not loading properly due to the presence of multiple views when the URL changes

After reviewing a couple of questions similar to this on various forums, I may have overlooked a crucial detail in them. Upon loading http://localhost:8000/characters/#/mages/detail/3, I am being redirected to my 'otherwise' URL: $urlRouterProvi ...

"Utilizing AngularStrap for dynamic popovers attached to anchors

Is it feasible to trigger a popover using AngularStrap Popover from an anchor or span element? This scenario works: <button content="hello" trigger="focus" bs-popover>clickme</button> However, the following attempts do not work: <a href= ...

What are the precise steps to create a flawless scrolling area?

I am facing an issue with setting accurate scroll zones for my divs. Here's my ideal scroll zone location: scroll zone in red Currently, I have a maximum of 4 divs and each div should contain a total of 10 rectangles per category (concentration, boos ...

Issue: unable to inject ngAnimate due to uncaught object error

Whenever I attempt to inject 'ngAnimate' into my app, I encounter issues with instantiation. Here is the code snippet in question: var app = angular.module('musicsa', [ 'ngCookies', 'ngResource', 'ngSanit ...

Creating a CSS triangle that smoothly transitions between two different colors

Is it possible to create a triangle in CSS that smoothly transitions between two colors without relying on a hover state? .arrow-down { width: 0; height: 0; border-left: 20px solid transparent; border-right: 20px solid transparent; b ...

Chrome and Firefox: Images cling together

I've encountered an issue with my recently launched website. Some images in a grid appear to be stuck together, but this problem only occurs in Firefox and Chrome browsers. Oddly enough, zooming in to around 110% then back to 100% seems to temporarily ...

Encountering 'error: undefined' message in dropzone.js success function

I created an Angular.js directive that adds a dropzone to my app and binds a function to the success event of dropzone.js. However, I am only able to retrieve the response and the file is undefined. The response is coming from the API that uploads the file ...

What are the possible complications that could arise from implementing this system for designing web pages?

Feeling frustrated with the limitations and compatibility issues of CSS, I decided to create a new approach for structuring webpages. Instead of relying on CSS, I developed a javascript library that reads layout instructions from XML files and uses absolut ...