What is the best way to establish a grid system limited to a maximum of 8 rows?

Looking to showcase a grid system with a maximum of 8 lines. The number of cells is variable, whether it's 12, 20, 100, and more. Click here for an image example.

Answer №1

If you want to create a grid layout, here's how you can do it:

(Check out these helpful resources: https://css-tricks.com/snippets/css/complete-guide-grid/ & )

  • Start by defining a grid template with 8 rows,

  • Then set the columns to auto-fill or auto-fit,

  • Finally, specify that the grid should fill column by column:

Here is an example of how to achieve this:

body {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8em;, 1fr));
  grid-template-rows: repeat(8, 1fr);
  grid-auto-flow: column;
  margin: 0;
  min-height: 100vh;/* optional */
  gap:2px;
}


/* Styling for the divs */

body {
  counter-reset: divs;
}

div {
  border: 1px solid;
  display:flex;
}

div:before {
  font-size:calc(12px + 3vw) ;
  margin:auto;
  counter-increment: divs;
  content: counter(divs)
}
<div></div>
<div></div> /* Repeat this line as needed */

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

Unable to resolve @font-face issue despite exhausting all possible solutions

Struggling with the @font-face code and unable to get my font file recognized. I've attempted various path changes, created new folders, renamed existing ones, even moved the font file to the root directory, but no luck. Testing in both Firefox and ...

Adding an image to your email content using Django

I tried using Django's Email message module to send an email with an embedded image. The image is located in my static folder. I attempted to use HTML code within Python to trigger the email, but the image is not appearing in the email. I have tried s ...

How can I utilize jQuery to iterate through every anchor tag on an HTML page?

I am looking to reference all anchor tags on the page that have a parent h2 tag. To achieve this, I need to iterate through each anchor tag that has a parent h2 and add an attribute using jQuery. <body> <h1>not me</h1> <a href ...

Issue with border styling in Material-UI vertical ToggleButtonGroup

In my current front-end project, I have implemented the React Material UI ToggleButtonGroup. For a Multiple Selection example with vertical styling, you can refer to this code snippet: https://codesandbox.io/s/eyk66?file=/demo.js However, I encountered a ...

Tips for aligning carousel indicators vertically in Bootstrap 5

I am struggling to vertically align the carousel indicators in Bootstrap 5. The solutions I have found so far are for Bootstrap 4, but they do not seem to work for me. Here is the markup for my carousel indicators. <div class='carousel-in ...

Ways to move Bootstrap 4 navbar list items to the right side?

Is there a way to move the li elements to the right without causing issues with the toggler or navbar? <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet" /> <nav class="navbar navbar-expand- ...

Ionic's ion-radio CSS: A highlighted selection

I've encountered an issue with my CSS in Ionic... My goal is to modify the CSS when a radiobutton is clicked, as illustrated below. [type=radio]:checked + ion-icon { background-color: $primaryColor; color: white; font-size: 45px; ...

Switch between showing and hiding a div by clicking on the panel header and changing the symbol from + to

I need assistance with a panel feature on my website. The panel should expand when the "+" symbol is clicked, displaying the panel body, and the "+" symbol should change to "-" indicating it can be collapsed by clicking it again. There is a slight twist t ...

What are some additional options for sourcing images in the img HTML tag?

I am facing an issue where I have two alternative images, with one image set as the default if the first two are not found. <img src='image1.png' onError="this.onerror=null;this.src='image2.png';" onError=" ...

How can we reduce the jitter experienced during page initialisation?

Is there a way to reduce the jittering effect on a page when using frameworks like jQuery/UI, especially with widgets like the button widget during layout processing on page load? I found setting the body tag to display: none, and then using $(function() ...

Do not display large numbers within an HTML card

I have https://i.sstatic.net/DkowD.png this card here and displaying dynamic data inside it. The number is quite large, so I would like it to appear as 0.600000+. If a user hovers over the number, a tooltip should display the full number. How can I achieve ...

Using JQuery and CSS to Transform Your Website Content

Imagine a scenario where I have two forms. Once the user completes the first form, they can click continue to proceed to the second form. Currently, I am using fadein and fadeout effects to show both forms on a single page. However, I want to switch to a ...

Customizing Jquery Button Styles: Enhancing Padding and Margin

Hey there! I'm having a bit of trouble trying to remove all the padding and margins from a simple Jquery button. I've been tinkering around but can't seem to figure out what I'm doing wrong. Any ideas on where I might be messing up? Y ...

Eliminate list items with a keyboard stroke

I am currently developing a straightforward todo list application using JavaScript. The main functionality I am trying to implement is the ability to add new items from an input field to a list, as well as the option to remove items from the list. While ...

Toggle multiple buttons based on the data fetched in the created() lifecycle hook

I have several toggle buttons that should be selected based on the values present in the response obtained through the created() method. <li> <input v-on:click="toggleCheckbox($event)" ...

Strategies for Resolving Table Alignment Problems using HTML and JavaScript

I am struggling to figure out how this dashboard will function as it is not a live website, but rather a tool that pulls data from a chemical analysis program and displays it in a browser view. My main issue is aligning two tables at the top of the page ...

Is it possible that the div's height is not being set to 0 pixels

<div style="height:0px;max-height:0px"> </div> It appears that setting the height of a div to 0 pixels is not having the desired effect. The div is still expanding to display its contents, so how can we stop this from occurring? ...

Using jQuery to remove all inline styles except for a specific one

Just a quick inquiry: Our Content Management System (CMS) utilizes CKEditor for clients to modify their websites. The front-end styles include the use of a pre tag, which we have customized to our desired appearance. However, when their team members copy a ...

Effortlessly showcase JSON data in an HTML owl carousel

Is there a way to display JSON data in HTML format? I have a JSON file containing reviews from Facebook, and I would like to showcase them on my website. Each review should be placed in its own div element. The JSON data below is extracted from the Faceboo ...

increasing the SQL integer value with padding

Is it possible to apply padding to certain INT return values retrieved from an SQL database using CSS within a div tag? I need specific numbers to have padding-left: 20px; while other specific numbers should have padding-right: 20px;. This presents a styl ...