Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for layouts with nested CSS grids and auto-height rows #2354

Open
charliesneath opened this issue Jan 20, 2025 · 0 comments
Open

Support for layouts with nested CSS grids and auto-height rows #2354

charliesneath opened this issue Jan 20, 2025 · 0 comments
Labels
bug Existing features not working as expected

Comments

@charliesneath
Copy link

charliesneath commented Jan 20, 2025

  • This issue was originally posted as a follow-up to Support for flexible row heights based on content size #2342.
  • This layout only uses CSS grid and demonstrates example of the layout I'm trying to recreate with Weasyprint; the previous example mixed in flex.
  • The title might need to change to reflect the issue more correctly; I'm not exactly sure what the primary issue is.

Overview

  • The .container is a grid with a single row and column. This represents the page the layout will fill.
  • The .layout is a grid with a single column and a dynamic number of rows (3 in this example)
  • Each .row is a grid with a single row, but a number of columns (.cell) equal to the number of children photos/images
  • The images themselves are set to object-fit: constrain so that they will retain their original aspect ratio, but expand to fill available space.

My expectation is that the layout .row heights adjust to the size of the content, since they will be different sizes depending on the orientation of images on this page.

(Note that I'm hard-coding the grid-template-columns value for the .rows in this example, but I would just use some CSS variables with the template to make this dynamic.)

Here's a view leveraging Chrome's grid inspector:

Image

Chrome Output

Image

Weasyprint Output

I might be missing a few lines of CSS to make this snap into place, but here's the output I'm getting currently.

Image

CSS


.container {
  display: grid;
  width: 500px;
  height: 600px;
  background-color: black;
  padding: 50px;
  box-sizing: border-box;

  .layout {
    display: grid;
    padding: 50px;
    background-color: white;
    min-height: 0;

    .row {
      display: grid;
      border: 1px dashed black;
      justify-content: center;
      min-height: 0;
      min-width: 0;

      &#row-1 {
	grid-template-columns: 1fr 1fr;
      }

      &#row-2 {
	grid-template-columns: 1fr;    
      }

      &#row-3 {
        grid-template-columns: 1fr;
      }

      .cell {
        max-height: 100%;
        max-width: 100%;
        min-height: 0;
        min-width: 0;
        border: 1px solid black;

	&.portrait {
	  background-color: lightgreen;
	}

	&.landscape {
	  background-color: lightblue;
	}
      }

      img {
        object-fit: contain;
        max-height: 100%;
        max-width: 100%;
        min-height: 0;
        min-width: 0;
        border: 1px solid black;
	height: 100%;
	width: 100%;
	display: block;
      }
    }
  }
}

HTML

<div class="container">
  
  <div class="layout">

    <div class="row" id="row-1">
      <div class="cell"><img src="{% static 'images/landscape.png' %}" /></div>
      <div class="cell"><img src="{% static 'images/landscape.png' %}" /></div>
    </div>

    <div class="row" id="row-2">
      <div class="cell"><img src="{% static 'images/portrait.png' %}" /></div>
    </div>
    
    <div class="row" id="row-3">
      <div class="cell"><img src="{% static 'images/landscape.png' %}" /></div>
    </div>
    
  </div>
  
</div>
@liZe liZe added the bug Existing features not working as expected label Jan 20, 2025
@liZe liZe mentioned this issue Jan 21, 2025
20 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Existing features not working as expected
Projects
None yet
Development

No branches or pull requests

2 participants