How can we loop through an array and display each item in a container with a fixed height until all the space is filled?

I am working with Vue and have a fixed height div container with overflow set to hidden. My goal is to iterate through a JavaScript array, adding each item to the div, and stopping when the bottom of the div space is reached. Additionally, I need this solution to be responsive.

<div class="container">
  <div class="header">Header</div>
  <div class="body" v-for="item in items">
    <div>{{ item.data }}</div>
  </div>
  <div class="footer">Footer</div>
</div>

.container {
  display: flex;
  height: 100%;
  flex-direction: column;
}

.header {
  height: 100px;
}

.footer {
  height: 100px;
}

.body {
  flex: 1;
  overflow: hidden;
}

To achieve this, you may need to calculate the height of the container in pixels and divide it by the font height of your item data. The number of items displayed should change when the window is resized to maintain responsiveness.

Answer №1

  1. One way to approach this is by using the element.offsetHeight function to determine when you have exceeded a certain height limit.
  2. Another option is to utilize the CSS property max-height along with the overflow-y property to restrict the height of an element.
  3. Alternatively, you can employ a SELECT element and specify the size attribute to control its dimensions.

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

Is it necessary to include the Roboto font when using MUI?

After reviewing the Material UI documentation, it appears that users are responsible for loading the Roboto font: Material UI is designed to use the Roboto font by default. You may add it to your project with npm or yarn via Fontsource, or with the Googl ...

The appearance of the upload button in React using Material-UI seems off

After following the MUI document on React Button upload, I noticed that the UI results were different than expected. Instead of just showing the button UI, there was an additional UI element present. By adding the sx={{display:'none'}} property, ...

It appears that the SignalR proxy is not defined

Why is $.connection.connectionhub showing as undefined? I am using webform. <script src="/scripts/jquery-1.6.4.min.js"></script> <!--Reference the SignalR library. --> <script src="/scripts/jquery.signalR-2.2.1.min.js">< ...

Dynamic height of a fixed-positioned Div

I encountered an issue with a Fixed positioned DIV that has dynamically appended content using jQuery. Once the height of the DIV exceeds the screen size, I am unable to view the contents at the bottom of the DIV without zooming in using the browser' ...

In the process of developing a custom Vue component library with the help of Rollup and VueJS 3

My goal is to develop a custom Vue component library using rollup and Vue.js. The process went smoothly with Vue2, but I encountered issues parsing CSS files with Vue3. To address this, I updated the dependencies in the package.json file. package.json { ...

Obtain the value of the input

I need assistance with the input below: <input value="25" data-hidden-value="25" name="associations[agencies][ids][]" data-hidden-name="associations[agencies][ids][]" class="string" type="hidden"> This particular input is generated dyna ...

Error: Unable to extract the 'email' property from the 'body' object due to its undefined status

Seeking assistance for debugging as I am encountering an issue that is not resolving on its own. The error message reads SyntaxError: Unexpected end of JSON input. Despite trying various methods, the errors persist, alternately throwing either TypeError: C ...

Determining the orientation of an image in JavaScript

Currently, I am attempting to determine the orientation of images using JavaScript in order to apply a specific class to them. This process seems to be functioning correctly on Firefox, but is presenting challenges on other browsers. It appears to work bet ...

How can I open the Ion-datetime view for the current year without allowing the selection of a specific day?

I am currently troubleshooting an issue with an Ionic date-time picker component. Upon opening the datepicker, it defaults to showing May 2021. As I scroll to the present date, I notice a circle highlighting today's date indicating that it selects th ...

Discrepancy in div height between Chrome/Edge and Firefox browsers

I am currently in the process of designing a straightforward website layout that includes a navigation bar at the top. The main focus is on an image that needs to stretch from the bottom of the navbar to the bottom of the window, filling up the entire scre ...

The jQuery find and replace feature is causing my entire content to be replaced instead of just specific paragraphs

Within this section, there are multiple paragraphs and an input field. The concept is simple: the user inputs text into the box, then hits "ENTER" to trigger a jquery function below. The process involves identifying matches between the paragraph content a ...

Adding numbers to a textbox using a JavaScript algorithm

There are two textboxes in this scenario. The first box should always contain 4 digits when you leave it, while the second box should always contain 10 digits. A javascript function needs to be implemented so that when a user leaves one of the textboxes, ...

Creating 3D Shapes with three.js

I am currently in the process of importing an STL object into my three.js scene. Unfortunately, this particular object seems to be using a large amount of GPU resources for rendering and animation, causing the overall performance of the scene to suffer. B ...

Exploring Vue Router: Navigating with Different Components on the Same Path

When using Vue 3 Composition API, if the components for paths "/users" and "/users/user-reference" are completely different and unrelated, how should I structure the router configuration? Possible Solutions: const routes = [ { path: '/users', ...

Passing variables by reference in JavaScript allows for direct manipulation of

Is there a JavaScript equivalent to PHP's method of passing variables by reference? [PHP]: function addToEnd(&$theRefVar,$str) { $theRefVar.=$str; } $myVar="Hello"; addToEnd($myVar," World!"); print $myVar;//Outputs: Hello World! If possible, h ...

"Troubleshooting: Resolving 404 Errors with JavaScript and CSS Files in a Vue.js and Node.js Application Deploy

I successfully developed a Vue.js + Node.js application on my local server. However, upon deploying it to a live server, I am facing a 404 error for the JavaScript and CSS files. I have double-checked that the files are indeed in the correct directories on ...

Try implementing in conjunction with the NPM package bootstrap-markdown

For my project, I have incorporated the NPM package bootstrap-markdown. To implement it, I included these lines in my JS file: var $ = require('jquery/dist/jquery.min.js'); require('bootstrap-markdown/js/bootstrap-markdown.js') The p ...

Using React to incorporate the necessary jquery for a separate library

I am looking to incorporate Trumbowyg library into my React project, however, I have encountered an error stating that jQuery is not defined. I found information suggesting that jQuery needs to be made available as a global variable in the window object. ...

What is the best way to transfer information from a view to a controller in Laravel using AJAX?

I am facing an issue with sending data from the view to the controller in Laravel version 7 I am sending data from a form and ul li elements I have an array of data in JavaScript Here is my HTML code: <ul name="ali" id="singleFieldTags&q ...

Utilizing pjax to open internal pages in a new tab

I have incorporated pjax into one of my projects, but I am facing a challenge when trying to open a page in a new tab or window. It appears that pjax opens all links in the same window except for those that lead to external websites. Below is the snippet ...