Struggling with aligning content within a div using CSS grid techniques

I am experimenting with CSS Grid and running into issues with overlaying content. The structure consists of a top-level container defined as a CSS grid (class="container"), followed by a content grid (class="content") that divides into 3 rows (header, label, rows). The header is simply a header, the label contains labels for the rows, and the rows represent the content in a "table"

Here is a visual representation:

Upon resizing the window, I notice a scrollbar on the right side that affects the entire page. I would prefer the scrolling to be limited to the rows section only, not the whole page.

You can view a working example on StackBlitz here: https://stackblitz.com/edit/angular-ivy-ayujp5

Although it seems straightforward, I'm struggling to grasp how height is calculated and where and how overflow properties should be defined.

p {
  font-family: Lato;
}

.container {
  display: grid;
  grid-template-columns: 30px 1fr 30px;
  grid-template-rows: 30px 1fr 30px;
  grid-template-areas: '. . .' '. content .' '. . .';
}

.content {
  grid-area: content;
  display: grid;
  grid-template-rows: 50px 30px 1fr;
  grid-template-areas: 'header' 'label' 'rows';
}

.header {
  grid-area: header;
}

.label {
  grid-area: label;
  display: grid;
  grid-template-rows: 1fr;
  grid-template-columns: repeat(3, 4fr);
  align-items: center;
}

.rows {
  grid-area: rows;
  height: 100%;
}

.row {
  background-color: pink;
  margin: 5px 0px;
  border-width: 1px;
  border-radius: 10px;
  padding: 25px;
  color: black;
}
<div class="container">
  <div class="content">
    <div class="header">Header</div>
    <div class="label">
      <div>Name</div>
      <div>From</div>
      <div>To</div>
    </div>
    <div class="rows">
      <div class="row">
        <div class="label">
          <div>1</div>
          <div>1999/01/01</div>
          <div>1999/12/01</div>
        </div>

      </div>
      <div class="row">
        <div class="label">
          <div>2</div>
          <div>1999/01/01</div>
          <div>1999/12/01</div>
        </div>

      </div>
      <div class="row">
        <div class="label">
          <div>2</div>
          <div>1999/01/01</div>
          <div>1999/12/01</div>
        </div>

      </div>
      <div class="row">
        <div class="label">
          <div>3</div>
          <div>1999/01/01</div>
          <div>1999/12/01</div>
        </div>

      </div>
      <div class="row">
        <div class="label">
          <div>4</div>
          <div>1999/01/01</div>
          <div>1999/12/01</div>
        </div>

      </div>
    </div>

Answer №1

I typically use the following method for calculating height:

.pin-table { height: calc(100vh - 125px); overflow: auto; }
. However, I'm open to hearing any alternate suggestions.

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

Adjusting element position while scrolling

Objective The goal is to have the page navigation display lower on the page by default. This will provide a cleaner layout as shown in the image below. Context An interactive element for navigation was implemented utilizing Headroom.js. This library d ...

How can I assign a class to my Typography component in Material UI?

When using my material-ui component, I wanted to add an ellipsis to my Typography element when it overflows. To achieve this, I defined the following styles: const customStyles = (theme) => ({ root: { textAlign: "left", margin: theme.spacing( ...

Creating a JSON array using looping technique

I am attempting to construct a JSON array using a loop where the input className and value will serve as the JSON obj and key. However, I am facing difficulties in creating one and cannot seem to locate any resources on how to do so. Below is an example sn ...

Conceal Choices During Search using jQuery Select2

I'm having trouble figuring out how to make the Select2 plugin work for my specific color selection feature. My goal is to allow users to choose 5 colors from a list, including an "Other" option. When the user selects "Other", they should be able to ...

Adjust the canvas size to fit its parent element ion-grid

I am currently working on an Ionic 3 component that displays a grid of images connected by a canvas overlay. I have utilized Ionic's ion-grid, but I am facing an issue with resizing the canvas. The problem is that I cannot determine the correct dimens ...

Implementing a method to pass total value to the <td> tag in angular JS using controller

I am having trouble calculating the total IR for each table cell. Despite my efforts, the function is not working as expected and I can't figure out why. $scope.getTotalb = function () { var totalb = 0; for (var i = 0; i < $scope ...

Variations in spacing due to line breaks

Looking for a solution to my code formatting issue in HTML. Here is an example of my CSS: span{height:200px;width:200px;border-width:1px;border-color:black;border-style:solid;display:inline-block} This is how my HTML code looks before changes: <span& ...

Collapse the borders of Angular's div layout container

I need help with collapsing the borders of div containers when generating a table using angular material's layout system. To see what I have done so far, please refer to my jsfiddle linked below: Jsfiddle Below is the HTML code snippet. Any guidance ...

A guide on creating a clickable polygon in Vue.js using Konva

Is there a way to create an interactive polygon in Vue Konva where I can set each corner with a click? I haven't been able to find any resources other than the v-polygon which only creates predefined polygons. ...

I'm having trouble aligning this div in the center of the screen. It looks like the position is slightly off

<!DOCTYPE html> <html> <head> <style> body { background-color: #7a64fa; } .container { background-color: #ffffff; position: fixed; top: 50%; left: 50%; margin-top: -50px; ...

Using CSS Classes with PHP Variables in Conditionals: A Handy Guide

I have limited experience in programming and I'm attempting to edit a .php file within a Wordpress theme. Please keep this in mind as I explain my issue. Within the theme, there is code that calculates the average score from 1 to 10 and then displays ...

"Transitioning from jQuery to Vanilla Javascript: Mastering Scroll Animations

I'm seeking guidance on how to convert this jQuery code into pure Javascript. $('.revealedBox').each(function() { if ($(window).scrollTop() + $(window).height() > $(this).offset().top + $(this).outerHeight()) { $(this).addCla ...

How can you utilize the Array submission syntax within HTML coding?

I currently have numerous input fields within a form, and some of them are structured like this: <input name="agents[]" type="file" /> Additionally, imagine there is a plus button next to this field as shown below: <img src="plus.jpg" id="some_ ...

Step by step guide to showcasing images dynamically in user interface

My current project involves displaying a screen with an HTML table and an image. The HTML table is fully dynamic. The Code Working Process When the user loads a page (with a URL), I render an HTML table in different parts as the page loads. I retrieve al ...

techniques for accessing HTML source code through an AJAX call

I am trying to retrieve the HTML source of a specific URL using an AJAX call, Here is what I have so far: url: "http://google.com", type: "GET", dataType: "jsonp", context: document.doctype }).done(function ...

Who needs a proper naming convention when things are working just fine? What's the point of conventions if they don't improve functionality?

I am a newcomer to the world of JavaScript programming and stumbled upon this example while practicing. <html> <head> <script type="text/javascript"> function changeTabIndex() { document.getElementById('1').tabIndex="3" d ...

Bootswatch alternative for Bootstrap CSS without utilizing Google Fonts

Currently, I am in the process of developing a webpage and utilizing Bootswatch for styling. However, there are times when I need to work offline and host locally. The issue I am facing is that Bootswatch cannot be used offline due to the fact that it util ...

Tips for positioning HTML elements at the exact mouse location as it moves, without any delay?

Currently, I am in the process of developing a web-based drawing application that does not rely on using a canvas. My decision to avoid using a canvas is because I plan to incorporate CSS Keyframes into the HTML elements upon placement. This approach allow ...

Do we need to use aria-labelledby if we already have label and input associated with "for" and "id"?

Here is the HTML structure for the Text Field component from Adobe Spectrum: The <label> element has a for attribute and the <input> has an id which allows screen readers to read out the label when the input is focused. So, why is aria-label ...

Discover the ins and outs of the "DOM" within a string, treating it as HTML in AngularJS

Looking to extract data from a legal HTML string based on tags and attributes, but want to avoid using jQuery in favor of Angular. Are there built-in functions in Angular for this task? ...