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

Getting data in a ng-Dialog Modal with AngularJS is a breeze!

Hi there, I'm new to Angular JS and facing an issue with displaying data from my MySQL database in a table as well as in a modal for more detailed information: I've included the HTML file named _detail_modal.html at the bottom of the page. ...

Is retrieving data from the database causing unexpected additional space to appear in the textarea?

I am facing an issue with a basic php file that fetches information from a MySQL database and displays it inside a textarea. However, when I access the file through browsers, there seems to be extra space at the start and end of the text within the textare ...

The transition effect of changing opacity from 0 to 1 is not functioning properly in Firefox

Having some trouble with this animation not working in Firefox. I'm triggering the animation using JavaScript after a delay like so: document.getElementById('my_id').style.webkitAnimationPlayState = "running"; I've also attempted: s ...

Adjusting the starting position of text within an HTML <li> element

I am currently in the process of designing a webpage layout with three columns. I have a specific vision for how I want the text to align within these columns but I am unsure of how to achieve it. Is there a way to make the text start at an exact position, ...

Adjust the contents of a DIV depending on which Toggle button is selected

When a user clicks on either "Twin Bed" or "King Bed", the content inside the "demand-message" should change to either "high demand" or "Only ??? rooms left". The ID will remain the same for both buttons due to existing logic. However, the message display ...

Displaying information from an array using AngularJS

I'm struggling to display data from an array and I could use some help. Here's a snippet from my service.js file: this.fetchData = function() { var myArray = $resource('url', {method: 'get', isArray: true}); myArray ...

What is the best approach to create a JavaScript search filter function spanning two pages?

Page1.html has a form with a drop-down menu containing options Color and Shape. There is also a submit button. Assuming Page2.html displays various shapes like Blue Square, Red Square, Blue Circle, Red Circle, is it feasible to create a JavaScript file th ...

Adding to the beginning of a list in JQuery mobile

Having trouble figuring out how to prepend my list in jQuery mobile while keeping the divider on top of the most recent item added. I attempted to prepend the newly added item, but it ended up shifting the divider to the bottom instead. function loadScan ...

Adding a box shadow around the entire div in Internet Explorer 11 with CSS

I am having difficulty applying box-shadow to create a shadow around the entire perimeter of a div. While it works in FireFox, it does not work in IE 11. So far, I have attempted solutions from this StackOverflow thread. For reference, here is a JSFiddle ...

Looking to display the ng-option in two lines within Angular 6?

How can I display data in a select dropdown with two lines for each option? I am currently using ng-select. <ng-select [(ngModel)]="selectedData" placeholder="Select Data"> <div *ngFor="let data of Data"> <ng-option [value]="da ...

What causes certain components in ReactJs to not respond to the `:focus` pseudo-class?

Currently, I am in the process of implementing a straightforward Emoji-Rating system where 5 emojis are displayed on the screen and upon hovering over them, their appearance changes. This functionality is achieved using the :hover pseudo-class. My goal is ...

What sets apart li.parent from ul?

I am facing some confusion with this parent keyword. Are li.parent and ul the same thing? If so, can someone please explain what this means? Thank you. (nav and sidebar are classes). .sidebar ul.nav .active > a:focus, .sidebar ul.nav li.parent a.active ...

CSS opacity is currently not working as intended

Why doesn't the opacity work here? I've tried using hex and rgba colors, but nothing changes. Even adding classes to tr and td didn't help... First attempt: .done{ background-color: rgba(0,175,51,5); color:white; opacity: 50; ...

Tips on replacing views within ion-view and updating the title in the title bar to match the injected page through the use of Ionic and AngularJS

I am new to ionic and angular JS. I am currently working on a simple app within the ionic framework. My goal is to inject an HTML template into the ion-view tag using ngRoute. However, I am facing issues as my code is not successfully injecting the HTML te ...

Check the radio box corresponding to the adjacent label

As a hobby, I have been exploring ways to automate questionnaires that I used to manually deal with for years. It has always intrigued me how best to streamline this process, and now I am taking the opportunity to indulge in my passion and enhance my JavaS ...

Attempted everything... Clicking away but a div refuses to show up post-click, resulting in an error message

When attempting to click a button, I encountered an error stating that the element is not clickable at point (1333, 75) as another element would receive the click. This issue arose while using Google Chrome version 65. <li class="slds-dropdown-trigge ...

The HtmlHelper ActionLink consistently establishes the current controller instead of allowing for the specification of another controller

I have been utilizing the HtmlHelper class to incorporate some code into my layout Navbar as a menu. Here is the code snippet: public static MvcHtmlString MenuLink(this HtmlHelper helper,string text, string action, string controller) { ...

Adding a class to a Vue component using the $refs property

I am facing an issue where I need to add dynamic class names to various Vue components based on their reference names listed in a configuration file. Manually adding classes to each component is not feasible due to the large number of components. To addre ...

Display various divs simultaneously based on the quantity of items in the dropdown menu

In my project, there is a dynamic select list that retrieves items from the database. Users have the ability to add or delete items from this list. Below is some code related to this functionality: <div class="form-group col-md-3"> <la ...

Rearranging div placement based on the width of the screen

I am currently working on building a responsive website and I need two divs to switch positions depending on the screen width, both on initial load and when resizing. Despite my efforts in researching and trying various options, I have not been successful ...