Adjust the height of each child element to be half of the fixed height of the parent

There is a wrapper containing multiple boxes generated using ng-repeat from a list. The wrapper has a fixed height of 300px. If the list contains only one box, a class is added to fill the entire space of the wrapper. However, when there are more than one box in the list, each box should have a height of 50% of the wrapper's height (150px for three boxes). While attempting to set this height using ng-class and a style property, it resulted in an issue where the third box's height was not visible due to overflow. Any suggestions on how to address this?

Angular.module("myApp", []).controller("myController", function($scope) {
             $scope.myList1 = [{
                 id: 1,
                 name: "Box 1"
             }];

             $scope.myList2 = [{
                     id: 1,
                     name: "Box 1"
                 },
                 {
                     id: 2,
                     name: "Box 2"
                 }, {
                     id: 3,
                     name: "Box 3"
                 }
             ];
         });
body {
     height: 100vh;
     width: 100vw;
 }

 .wrapper {
     display: flex;
     flex-direction: column;
     flex: 1 1 auto;
     border: 1px solid blue;
     overflow: auto;
     height: 300px;
 }

 .box {
     display: flex;
     flex-direction: column;
     flex: 0 0 auto;
     background-color: orange;
     border-bottom: 1px solid red;
 }

 .fillBox {
     flex: 1 1 auto;
 }

 .fillHalfBox {
     height: 50%;
 }

Answer №1

Why not give this a shot?

{triggerHalfBox: list1.size > 1} -> {triggerHalfBox: list2.count > 1}

Answer №2

It seems like your ng-class expression is facing evaluation issues. Please review the expression carefully, or consider exploring alternative methods for adding classes conditionally. You may find helpful insights in this resource: https://example.com/ngclass-alternatives

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

What are some ways to increase the scalability of an HTML form?

My login page is easy to read on larger screens like laptops or tablets, but on mobile devices, users have to zoom in to see the text clearly. I want to make it more scalable, but I'm struggling to figure out how. Here's the HTML code: <!DO ...

Making a div equal in height to an image

What I currently have is like this... https://i.stack.imgur.com/7FeSi.png However, this is what I am aiming for. https://i.stack.imgur.com/fn9m0.png The image dimensions are set up as follows... #content img{ padding: 3%; width: 60%; height: 50%; floa ...

The table is too large for the parent div in which it is placed, causing

Check out this example I have for putting a table in a div and making it fill the div: ex1_jsfiddle table { font-family: arial, sans-serif; border-collapse: collapse; width: 100%; height: 100%; table-layout: fixed; } td, th { border: 1px sol ...

Display a compilation either in the backend or the frontend

I'm fairly new to NodeJS and I could really use some advice. I currently have a webpage that displays a list of users, which is retrieved from a collection using Mongoose. I am aware of two different ways to display this list: 1) One option is to que ...

Acquiring administrative authorization upon user login with PHP

I have developed a registration form and a login form using PHP. However, whenever I run this code, it displays the message "invalid username" when the username is invalid, or it says "your account isn't approved by admin yet." Can anyone please guide ...

Facing issues with Handsontable opening within a jQuery UI dialog?

After implementing the Handsontable plugin in multiple tables, everything appears as expected on the parent page. However, when attempting to open a dialog containing a table, the tables do not display properly (only in IE). A demonstration of this issue c ...

Rotate image in Vue3 using @click

I have a dashboard with a refresh button that I want to rotate 360 degrees every time it is clicked. How can I achieve this rotation effect on the image with each click of the refresh button? Below is the code snippet I have been working on, but it only r ...

Is it possible to swap a <div> element with the content of another HTML page using the .innerHTML method?

I am currently working on a project that involves loading different webpages into a <div> on my page once specific links are clicked. I came across a thread about using jQuery for this purpose, but I'm not familiar with it. Is there a way to ach ...

Incorporate different courses tailored to the specific job role

https://i.stack.imgur.com/iGwxB.jpg I am interested in dynamically applying different classes to elements based on their position within a list. To elaborate: I have a list containing six elements, and the third element in this list is assigned the class ...

Implementing external pagination and data export in a UI-grid

Currently, I am utilizing ui-grid with external pagination to showcase my data. A problem has arisen where I can only export the data that is currently being viewed. In order to meet my requirements, it is necessary for me to be able to export ALL the data ...

The order of CSS precedence shifts even when the class sequence is the same

In my development setup, I have a react component that is embedded within two distinct applications each with their own webpack configurations. Within the component, I am utilizing a FontAwesome icon using the react-fontawesome library: <FontAwesom ...

Only wrap certain elements if they consist of two specific items

<div class="section"> <label>Title: </label> <input type="text" /> </div> <div class="section"> <label>Text: </label> </div> My goal is to enclose the label + input within an additional div ...

onpageshow event behaves as expected exclusively on webkit browsers (triggers function solely when visible on the screen)

I am inserting an HTML file using an object tag. The encompassing div of the object tag is hidden with a display:none property. However, I encounter an issue where the onpageshow event that I placed on the body tag of the HTML object behaves differently a ...

Jasmine spying on a standalone function that is not a method of an object

What is the best way to spy on a function that is not a method of an object? In my specific case, the function callMe is not defined on the window object - it is a dependency loaded through angular. if (X) { callMe('hello'); } ...

Steps to display a JSX component stored in a variable

Presently, I am implementing an if/else statement within my code to determine the content that will be displayed in the JSX element named 'signupMessage'. Subsequently, I render the contents of this 'signupMessage' element. render() { ...

How to customize the page background color in Next JS

I am currently working on a project using Next Js and have encountered an issue. I have a global.css file set up in the project, but I need to change the background color of a specific page without affecting the rest of the project. Although I have tried u ...

Retrieving HTML in Angular

As I delve into the world of Angular, my goal is to retrieve an HTML template from a file using JavaScript without relying on ng-include or any other directives. The challenge lies in not having HTML elements to work with, as all I have is a JavaScript fil ...

Center an image both vertically and horizontally within an Owl Carousel arrow slider

I have set up an owl carousel on my page with a customized arrow positioned next to the slider. Currently, it looks like this: https://i.stack.imgur.com/gCfM0.png My goal is to vertically align the arrows and make sure the left arrow is aligned to the le ...

Discovering the quantity of identical elements within a JavaScript array

Looking for some assistance in solving a JavaScript problem as I am relatively new to the language: I have an array and I need help in determining the count of identical values. Below is my array: var arr = ["red", "blue", "green", "red", "red", "gray"] ...

Angular error ReferenceError: $Value is not defined in this context

As a newcomer to AngularJS, I am facing an issue while passing a list from the HTML file to the backend for processing. The error message ReferenceError: $Value is not defined keeps popping up. Within my controller file, I have a function named test. The ...