Issue with GridLayout causing rows to be misaligned

As a newcomer to the world of CSS, I found myself in need of a grid layout for a quick project. Here's the mishmash of CSS code I came up with:

body {
  margin: 40px;
}

.container {
    display: grid;
    grid-template-rows: [row1start] 20% [row2start] 20% [row3start] 10% [row4start] 50% auto [last_col];
    grid-template-columns: [column_one_start] 50% [column_two_start] 50% auto [end];
    justify-items: stretch;
    grid-gap: 1rem;
}

.container.row1 {
    background-color: #444;
    color: #fff;
    border-radius: 5px;
    padding: 20px;
    font-size: 150%;
    grid-column-start: column_one_start;
    grid-column-end: span 2;
    grid-row-start: row1start;
    grid-row-end: span 1;
    justify-self: center;
    align-self: stretch;
}

.container.row2 {
    background-color: #444;
    color: #fff;
    border-radius: 5px;
    padding: 20px;
    font-size: 150%;
    grid-column-start: column_one_start;
    grid-column-end: span 2;
    grid-row-start: row2start;
    grid-row-end: span 1;
    justify-self: center;
    align-self: stretch;
}

.container.row3 {
    background-color: #444;
    color: #fff;
    border-radius: 5px;
    padding: 20px;
    font-size: 150%;
    grid-column-start: column_one_start;
    grid-column-end: span 2;
    grid-row-start: methodology_row_start;
    grid-row-end: span 1;
    justify-self: center;
    align-self: stretch;
}

.container.row4 {
    background-color: #444;
    color: #fff;
    border-radius: 5px;
    padding: 20px;
    font-size: 150%;
    grid-column-start: column_one_start;
    grid-column-end: span 2;
    grid-row-start: row4start;
    justify-self: center;
    align-self: stretch;
}

In essence, my goal was to create 4 rows (or tracks) that occupy 20%, 20%, 10%, and 50% of the space respectively. Below is the HTML snippet I used:

 <!DOCTYPE html>
<html lang="en" dir="ltr" xmlns="http://www.w3.org/1999/html">
 <head>
   <meta charset="utf-8">
   <title>Template</title>
   <link rel="stylesheet" href="{{ url_for('static',filename='css/container.css') }}">
 </head>

 <body>
     <header>
        <h1 class="logo">Template with grid</h1>
    </header>

    <div class="container">
        <div class="row1">
            <p>Row 1</p>
            Lorem ipsum dolor sit amet consectetur, adipisicing elit.
            Esse aliquid laboriosam minima ex praesentium recusandae
            reprehenderit unde sit tempore atque aut commodi quae expedita
            corrupti, dignissimos architecto. Eius, maiores ad?
        </div>
        <div class="row2">
            <p>Row 2</p>
            Lorem ipsum dolor sit amet consectetur, adipisicing elit.
            Esse aliquid laboriosam minima ex praesentium recusandae
            reprehenderit unde sit tempore atque aut commodi quae expedita
            corrupti, dignissimos architecto. Eius, maiores ad?
        </div>
        <div class="row3">
            <p>Row 3</p>
            Lorem ipsum dolor sit amet consectetur, adipisicing elit.
            Esse aliquid laboriosam minima ex praesentium recusandae
            reprehenderit unde sit tempore atque aut commodi quae expedita
            corrupti, dignissimos architecto. Eius, maiores ad?
        </div>
        <div class="row4">
            <p>Row 4</p>
            Lorem ipsum dolor sit amet consectetur, adipisicing elit.
            Esse aliquid laboriosam minima ex praesentium recusandae
            reprehenderit unde sit tempore atque aut commodi quae expedita
            corrupti, dignissimos architecto. Eius, maiores ad?
        </div>
    </div>
 </body>
</html>

I'm aiming for this visual layout:

To address any misalignments like "Row 2" wandering off course, everything seems to display correctly when opened in Opera directly, but not within my Flask app using render_template(). It's being called simply with something like:

@app.route('/')
def home():
    return render_template("template02.html")

Why isn't render_template() respecting my layout?

Answer №1

The most recent solution provided in this thread: utilizing a CSS stylesheet on a Jinja2 template was very beneficial to me. I am perplexed as to why altering the folder hierarchy is necessary for it to function.

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

Generate a table containing information organized by category

I am looking to create a component Table that groups countries together. Here is my mockup: enter image description here I am struggling to find a solution for this issue. Can someone please assist me? ...

What is the best way to insert my words within the boundary?

I am seeking assistance on inserting text within the border I created using an image. As I continue to add more text, I want it to display within the border as I type. Any guidance you can provide would be greatly appreciated. Thank you! li { list-sty ...

Customize PrimeNG component styles

Utilizing the PrimeNG OverlayPanel for a dropdown click feature, I am encountering an issue with moving the default left arrow to the right position. Despite trying various solutions, I have reached a dead end. Would you be able to provide me with some fr ...

What's the reason why Angular stops flickering with the use of "/" in href?

Recently, I've come across a peculiar issue in one of my web applications while using Angular's routeProvider as a template engine. The app functions properly, but the behavior seems inexplicable to me. The problem arises during page transitions ...

The discrepancy in percentages by a single pixel within Webkit

I am facing an issue with the positioning of two div elements. The first one has a height of 40% and the second one has a height of 60%. I have set the first element to be positioned at top: 0; and the second one at bottom: 0;. However, in Webkit browsers, ...

Identify when a click occurs outside specific elements

I've been searching for solutions to address this issue, but so far nothing has worked. Here is the JavaScript code I am using: var specifiedElement = document.getElementById('a'); document.addEventListener('click', function(eve ...

Update Table Row Background Color in Separate Table by Clicking Button Using JQuery

Two tables are involved in this scenario - one that receives dynamically added rows, and another that stores the data to be included. The illustration above displays these tables. Upon clicking the Edit button, the information from the selected row in Tab ...

Is it possible to highlight only a specific color on the div background?

I'm trying to create a layout similar to this: https://i.sstatic.net/dZ1ka.png I've managed to get most of it working, but I'm struggling with the yellow rectangle that spans the background of the screen. Currently, it looks like this: https ...

What is the difference between class at DOM and className at component?

When passing the className props to the child component, sometimes the className for the active link is not correctly reflected in the DOM element during production: The child component (Link) receives the className prop for the active link from the paren ...

What is the process for embedding a 3D model using three.js into a specific div on a webpage?

Lately, I've been struggling with a persistent issue. I can't seem to figure out how to integrate my three.js scene into a div on my website. Despite watching numerous YouTube videos and reading countless articles on the topic, I still haven&apos ...

What is the reason for the ineffectiveness of percentage padding/margin on flex items in Firefox and Edge browsers?

I am trying to create a square div within a flexbox. Here is the code I have used: .outer { display: flex; width: 100%; background: blue; } .inner { width: 50%; background: yellow; padding-bottom: 50%; } <div class="outer"> <div c ...

Ensuring consistency in aligning float elements

I've been struggling to create a concept design for my internship project. I aim to have a page with six clickable elements (images). When one is clicked, the others should disappear and the active one moves to the top. I managed to achieve this using ...

Updates made to CSS are not appearing on the Joomla site

My website is based on Joomla and has been functioning well since it was created. However, recently I have noticed that any CSS changes made in the files are not showing up on the site. I have tried clearing the cache and viewing it from different ISPs, ...

What are the proper steps to ensure images are displayed correctly on mobile devices?

https://i.sstatic.net/M68Ob.jpg https://i.sstatic.net/fPKXr.jpg Our background image is 1920x1080p and looks great on desktop browsers, but it's not displaying properly on mobile devices in either portrait or landscape mode. Is there a way to resolv ...

Animate the border to move to the next list item after it is hovered over

Seeking assistance to animate border-bottom movement in navbar Desiring animation effect for hover event on second li item The code for the navbar is as follows: .top-bar { background:#0d0d0d; width:100%; height:85px; position:fixed; top:0; z-index:99 ...

Ensure that a div remains active even after it has been selected through AJAX using jQuery

I am currently utilizing ajax to display information from a database. The application I am working on is a chat app, where clicking on a specific conversation will append the data to a view. The structure of my conversation div is as follows: <div clas ...

Issue regarding the sidebar's top alignment

Having trouble with the positioning of this sidebar. It seems to be hanging slightly over the top edge instead of aligning perfectly with it. Here's how it looks: enter image description here. CSS CODE: https://pastebin.com/RUmsRkYw HTML CODE: https ...

Hovering over a white background will darken the CSS styling

A stunning image on a dark background Displayed on Hover (right) An elegant picture with a white background Activated on hover (incorrectly) I would like it to have a darkened effect on the white background as well. CSS Styling .photo background: n ...

Tips for Choosing Certain List Items in a Responsive Bootstrap Navigation Menu for WordPress

I've put together a sleek bootstrap navbar menu for WordPress. If you want to check out the menu design, you can view it by clicking on this link: here There are still some tweaks that need to be made though. Specifically, I need to add a box around ...

Incorporate a Burger Icon into the Navigation Menu

insert image description here I am currently working on implementing a hamburger slide-out feature in my navigation bar. The desired behavior is for the sidebar to slide out to the right. We are using Elementor within WordPress for this project. Has anyone ...