What's the best way to arrange my containers for optimal placement?

I'm attempting to create a Thymeleaf template for rendering a printable PDF. Here is what I currently have:

<html xmlns:th="http://www.thymeleaf.org" >
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"
        charset="UTF-8"></meta>
    <title>Certificate</title>
    <style>
    @page {  
        margin-top: 0px;
        margin-left: 0px;
        margin-right: 0px;
        margin-bottom: 0px;
        size: A4 portrait;
    }
    body {
        font-family: Arial,Helvetica Neue,Helvetica,sans-serif;
        font-size: 10pt;
        background-size: 100%;
    }
    div.main{
        border: 1px solid;
    }
    div.centerText{
        text-align: center;
        background:lightcyan;
        margin: 0px;
    }
    div.leftText{
        text-align: left;
    }
    div.rightText{
        text-align: right;
    }
    div.signature{
        background:PapayaWhip;
    }
    </style>
</head>
<body th:style="'background-image:url(' + ${bgurl} + '); margin-top: 7.0cm; margin-left: 2.5cm; margin-right: 2.5cm; margin-bottom: 2.0cm;'">
    <div class="main">
        <div class="centerText">
            <h1>title</h1>
        </div>

        <div class="leftText">
            <p>description of certificate</p>
        </div>

        <div class="signature">
            <p>signature</p>
        </div>

    </div>

    <footer>
        <div class="rightText">
            <p>document information</p>
        </div>
    </footer>
</body>
</html>

The entire page has a background image, but the certificate's actual content must adhere to the margins specified in the body element. I attempted to set margins in the main div, but couldn't position it correctly.

Currently, everything seems fine up to the signature div, but I need to position this element at the bottom of the body with a 2cm bottom margin to the end of the page. The footer should also be positioned directly below the signature div.

I have tried numerous examples from various sources, but haven't been able to achieve the desired layout accurately.

CSS to make HTML page footer stay at the bottom of the page with a minimum height while not overlapping the content

Can anyone provide guidance? An explanation on how to solve this issue would be greatly appreciated, but a brief solution will suffice as well.

Answer №1

One way to achieve the desired layout is by using either 'position: absolute' or 'position: fixed' in your CSS.

@page {
    margin-top: 0px;
    margin-left: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
    size: A4 portrait;
}

body {
    font-family: Arial, Helvetica Neue, Helvetica, sans-serif;
    font-size: 10pt;
    background-size: 100%;
}

div.main {
    position: absolute;
    top: 7.0cm;
    left: 2.5cm;
    right: 2.5cm;
    bottom: 2.0cm;
    border: 1px solid;
    padding-bottom: 2.0cm;
    box-sizing: border-box;
}

div.centerText {
    text-align: center;
    background: lightcyan;
    margin: 0px;
}

div.leftText {
    text-align: left;
}

div.rightText {
    text-align: right;
}

div.signature {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    background: PapayaWhip;
}

footer {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
}
<body th:style="'background-image:url(' + ${bgurl} + ');'">
    <div class="main">
        <div class="centerText">
            <h1>title</h1>
        </div>

        <div class="leftText">
            <p>description of certificate</p>
        </div>

        <div class="signature">
            <p>signature</p>
        </div>
    </div>

    <footer>
        <div class="rightText">
            <p>document information</p>
        </div>
    </footer>
</body>

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 there a way to tally the checked mat-radio-buttons in Angular?

I am seeking a way to determine the number of radio buttons checked in a form so I can save that number and transfer it to a progress bar. <mat-radio-group name="clientID" [(ngModel)]="model.clientID"> <mat-radio-button *ngFor="let n of CONST ...

What is the best way to emphasize specific months and years in an Angular Material datepicker?

I have an array of days, which can be from any year. I am attempting to customize the Angular Material datepicker to highlight specific months and years in the selection views based on the array of days. .html <input [matDatepicker]="picker" ...

When setting the form action attribute in jQuery, the parameter being passed may be null

My goal is to redirect my form action to another page with a URL parameter. Here's the code I'm using: ui.setFormActionToTargetPage = function () { $('form').get(0).setAttribute('action', 'myTargetPage.html?id=' ...

When I attempt to incorporate multiple sliders on a single page, I encounter difficulties in determining the accurate stopping position if the number of slides varies

I am having trouble setting the correct stop position for sliders with different numbers of slides on a page. When I have the same number of slides in each slider, everything works fine. However, I need to have a different number of slides in each slider ...

Troubleshooting: Difficulty with svg mask function when implementing an svg image in a react.js environment

I'm attempting to achieve an effect where an image appears above a background image when hovering over it, similar to this example... https://jsfiddle.net/12zqhqod/7/ <img id="heretic" height="300px" width="300px" src="http://i.imgur.com/0bKGVYB ...

Is there a way to stop the MUI Select component's width from increasing when I choose multiple options?

Please check out the demo I created on codesandbox by clicking here View codesandbox demo I have implemented the MUI Select component with various props to enable multiple options selection without a fixed width constraint. Using a grid layout, I have ev ...

The functionality of ng-style is not compatible with min, and utilizing ng-model produces undesirable results

Why does the ng-style condition not work with min=0 if the saved value of ng-model="detail.Amount" is negative? <input type="number" min="0" oninput="validity.valid||(value='');" class="form-control" title="Amount" ng-model="detail.Amount" ng ...

What is the best way to position an image in the center over a video using HTML and CSS?

I am currently developing a website with a background video and I want to overlay a company logo on top of it while keeping it centered. My coding language of choice for this project is using HTML and CSS. Here's the HTML code snippet I have for this ...

Designing webpages by superimposing text onto images with customizable positioning

My current project involves developing an HTML document with a floor plan image as the main layer. On top of this image, I need to display employee names extracted from a database and positioned on the map based on a location variable within the database ...

The standard bootstrap navbar does not automatically create spacing for content below it

Hey there everyone, I’m facing an issue with my responsive bootstrap menu. When I click the toggle button to open the dropdown menu, it doesn’t push the other content down like it should. Instead, it just overlaps the content. I’ve been trying to sol ...

Attempting to showcase the information in my customized SharePoint Online list through a Web Part Page utilizing AngularJS

<script> //AngularJS Code goes here var appVar = angular.module('listApp', ['ngRoute']); appVar.controller("controller1", function($scope){}); function FetchEmployeeData($scope, EmployeeList){ var reque ...

What is the best way to place an "Add row" button directly in front of every horizontal row border within a table?

I would like to create an HTML table where I can insert rows by clicking on a centered "insert row" button placed between each pair of rows. This will help in visually indicating where the new row will be added. Is there a CSS solution to achieve this lay ...

Angular: The Ultimate Guide to Reloading a Specific Section of HTML (Form/Div/Table)

On my create operation page, I have a form with two fields. When I reload the page using window.reload in code, I can see updates in the form. However, I want to trigger a refresh on the form by clicking a button. I need help writing a function that can r ...

Discover the ultimate guide to harmonize IE 9 with the ingenious Bootstrap Multiselect plugin developed by davidstutz

I've come across an amazing plug-in developed by David Stutz that allows for a Bootstrap and jQuery multi-select options list. Here are some resources: Check out the source code on Github Find documentation and examples here This plug-in works fla ...

Footer displays within the content section

Currently, I am utilizing Next.js and antd's layout components to create a dashboard-style page using their Layout component. However, I have encountered two issues related to styling (CSS) in this setup: Footer appearing within the Content: I am wo ...

Template Function Problem Detected in AngularJS Formatting

I'm struggling to incorporate my scope attributes into a template function within my custom directive. The formatting for the return section in my template is not working as expected. This is how it currently looks: angular .module(' ...

Despite following all the correct steps, the tailwind CLI remains unresponsive. Additionally, the default button fails to display any content

view the document and my packages (image) Although it worked with the cdn, I'm puzzled why I can't use it properly with the cli ...

Stylish Sudoku Grid Design with CSS-Grid Borders

I have designed a sudoku puzzle and I am seeking assistance with CSS to style it. My goal for styling using CSS is illustrated here... https://i.stack.imgur.com/nrA47.png What I currently have appears like this... https://i.stack.imgur.com/zpNp6.png T ...

Error occurred while fetching image from Medium story API in Next.js

While working on my Next.js app, I encountered an issue with the Medium story API. Every time I try to fetch and display an image using the API, I receive an error message stating "upstream image response failed." The specific error code is: upstream image ...

Several DIVs with the same class can have varying CSS values

I am looking to modify the left-margin value of various separate DIVs using JavaScript. The challenge is: I only want to use a single className, and I want the margin to increase by 100px for each instance of the class. This way, instead of all the DIVs ...