Remove the footer specifically from the final page by utilizing CSS

I am currently working on generating a PDF. My goal is to remove the last page using CSS methods. I have attempted to use :last-child to achieve this, but unfortunately, it did not yield the desired results.

Here is an excerpt of my code:

body {
  font-family: 'Roboto', sans-serif;
  font-size: 0.85em;
  padding-left: 30px;
  padding-right: 30px;
  line-height: 0.95em;
}

@font-face {
  font-family: 'Roboto', sans-serif;
  font-style: normal;
  font-weight: normal;
}

footer {
  position: fixed;
  bottom: -30px;
  right: 0px;
  height: 50px;
  width: 270px;
  text-align: left;
}

footer .page-number:after {
  content: counter(page);
}

footer .page-number .last:last-child {
  display: none
}
<body>

  <footer>

    <div class="right" style="margin-left: -85px;">
      <span class="page-number"></span>
    </div>

    <table width="100%" class="last">
      <tr>
        <td>
          <span style="
    border: 1px solid;
    box-sizing: border-box;padding-right: 0.88cm;padding-left: 5px;vertical-align: middle;">Roles I &nbsp;</span>
          <span style="width: 300px;
    border-top: 1px solid;
    border-right: 1px solid;
    border-bottom: 1px solid;
    margin-left: -6px;
    box-sizing: border-box;padding-right: 70px;vertical-align: middle;">&ensp;&ensp;&ensp;&ensp;&ensp;</span><br>

          <span style="
    border-left: 1px solid;
    border-right: 1px solid;
    border-bottom: 1px solid;
    box-sizing: border-box;padding-right: 1.32cm;padding-left: 5px;vertical-align: middle;">Roles II</span>
          <span style="width: 300px;
    border-right: 1px solid;
    border-bottom: 1px solid;
    margin-left: -6px;
    box-sizing: border-box;padding-right: 70px;vertical-align: middle; ">&ensp;&ensp;&ensp;&ensp;&ensp;</span>
        </td>
      </tr>
    </table>
  </footer>
  My content here until Nth Page and my objective is to remove the content in the red box at the footer
</body>

In the provided example image, you can see that there are a total of 3 pages, with numbers and boxes highlighted in red within the footer. I specifically aim to delete the data within the red boxes while retaining the page numbers. https://i.sstatic.net/4Vsk2.png

Note: I am utilizing the dompdf library for this task

Answer №1

The issue lies with your selector, as it is not accurately targeting any elements.

Specifically, the selector

footer .page-number .last:last-child
is trying to target the last child element with the class name last within an element with the class name page-number inside a footer element.

This scenario would typically appear like this:

<footer>
    <div class="page-number">
        <div class="last"></div>
        <div class="last"></div> <!-- This is the targeted element -->
    </div>
</footer>

However, based on the structure you provided:

<footer>
    <div class="right">
        <span class="page-number"></span>
    </div>
    <table class="last"></table>
<footer>

It appears that you are attempting to select both .page-number and .last within the last footer element on the page. To achieve this, consider using the pseudo-selector :last-of-type.

The updated selector would be structured as follows:

footer:last-of-type .page-number,
footer:last-of-type .last

This targets all elements with either the class name page-number or last within the final <footer> element present on the page.

Keep in mind that if your footers are not siblings, you may need to adjust the positioning of :last-of-type or :last-child to align with their relevant parent elements until they are at the same level as the siblings.

For example, in a situation like this:

<div><footer></footer></div>
<div><footer></footer></div>
<div><footer></footer></div>

You would aim to match the div rather than the footer since pseudo-elements are defined relative to their parent, and each footer acts as the only footer within its corresponding parent.

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

Ways to apply Angular ng-options outside of a select element besides traditional use?

According to the official documentation, ng-options can be used on any element, not limited to just the select tag. This flexibility allows for enhanced customization of the selection UI, such as displaying thumbnail images or additional information beyond ...

Whenever I adjust the size of the div tag, it automatically shifts to the left and loses its responsiveness on mobile devices

This custom class has been created to adjust the size of the div tag and add margins in order to center the elements within the div. .adjust-width { width: 900px; position: center; margin-top: 50px; margin-bottom: 100px; margin-right: 150px; ...

Android not recognizing Ionic href links

Lately, I've been tackling a project involving an app that fetches JSON data from a server. Within this JSON data, there's an object containing HTML elements, often with URLs embedded within. Additionally, there's another object consisting o ...

What is the specified height for the AppBar and Toolbar components in Material-UI?

I'm trying to figure out the exact height being used in this scenario: <AppBar position="static"> <Toolbar> because I'll need that information for a calculation in another component. My current assumption is that it's 64px, b ...

Sass fails to import the theme for the angular material checkbox

I'm facing an issue where, despite specifying imports in my SCSS file and setting up a custom theme, the checkbox styles are not visible except for those related to typography. This is what my SCSS file looks like: @import "~bootstrap/scss/bootstrap ...

If there are no spaces, text will be removed from my list group

While working on developing a forum, I encountered an issue where if I repeatedly input letters or words without any spaces, it causes everything to overlap. Below is an example highlighting this problem: https://i.sstatic.net/KStNq.png Although there is ...

Restricting the Zoom Functionality in a Web-Based Project on a Touch-Enabled Display

I am currently working on a project that is web-based and runs on localhost. I need to prevent users from zooming in on the user interface. Is there a way to accomplish this using JavaScript? And can I achieve this restriction specifically on Google Chrome ...

PHP and issues with search functionality

I am currently working on developing a search function to retrieve and display data from a MySQL database based on user selection. However, I encountered an error that I am not sure how to resolve. Can anyone provide assistance? I am fairly new to PHP. The ...

Rails: jQuery - page refreshes unexpectedly during event execution

After successfully implementing a jQuery script for my custom dropdown menu on a standalone webpage, I encountered issues when integrating it into my Rails application. I am unsure if the problem is related to Turbolinks or if there is another underlying c ...

Mastering the Art of Line Breaks in WordPress

I am looking for a way to break a WordPress site title over two lines at a specific point in the text. Since the WordPress content filter 'wpautop' disables the ` ` tag (also known as ` ` or ` `), I'm wondering what the best alternative ...

How can Watir retrieve the inner html content of a <span> element?

Currently, I am attempting to locate a navigation link by iterating through several spans with the 'menu-item-text' class. My objective is to compare the content within the span tags to determine if it matches the correct navigation control for c ...

Enable Auto-Play for HTML5 Videos Inside Fancybox

I am currently working on a project that utilizes Fancybox for presenting individual HTML5 Videos and HTML5 video galleries. My goal is to have the single videos autoplay when opened in Fancybox, and then automatically close Fancybox once the video has fi ...

Using the HtmlTable Control to populate data from an HtmlTable object in ASP/C# Programming

It seems like a simple question, but I'm struggling to populate an HtmlTable control, accessible from codebehind, with data from an HtmlTable object already containing information. Could someone offer me guidance on this issue? Thank you in advance. ...

Enhance your AngularJS table with a custom Javascript context menu!

In the process of developing a shift planner, I have implemented a JS context menu and am attempting to display the shifts using Angular. However, upon clicking any table cell, all cells are being updated simultaneously. Is there a workaround for this issu ...

Embed an external JavaScript file into a primary file

Is it possible to include the coding from an external javascript file directly into the same file, similar to how we can put CSS inside a style tag? popwindow = window.open(src, name, 'height=500, width=500'); ...

Can the tooltip of an element be changed while the old tooltip is still visible without having to move the mouse away and then back again?

When I have an HTML anchor element with a tooltip that appears when the mouse is hovered over it, and then I use JavaScript to change the tooltip's text using element.title = "Another Tooltip", the new tooltip text does not immediately update visually ...

Retrieve the value from an input tag that is only displayed based on a condition using *ngIf

In my HTML form, I have implemented conditional visibility of input fields based on the radio button selection using *ngIf. <table> <tr> <td><label>name</label></td> <td><input #name />&l ...

Exploring the efficiency of different CSS selectors

I am struggling with the following code: HTML: <ul class="list"> <li class="list-item"> item 1 </li> <li class="list-item list-item_active"> Active item </li> <li class="list-item"> item 3 </li> ...

Alternate Row Colors Using Odd/Even CSS Styling for Main Headings

In my expand/collapse table, I have set up alternating row colors (dark grey and light grey) that adjust automatically when expanding or collapsing. The challenge I'm facing is that for certain rows, I want to apply a specific background color using ...

Which specific HTML element triggers the initiation of ajax in Jquery?

I have a situation where various HTML elements trigger ajax requests when clicked. My goal is to determine which specific element was clicked inside the ajaxComplete event. Although I attempted to use event.target, it only returns the entire document inst ...