Styling Tip: Removing a header from the initial page of a chapter using CSS

Using CSS to generate HTML to PDF, I have successfully added page numbers at the bottom and chapter names at the top of each page using @top-center in the CSS and HTML code below. The rendering is done with Prince.

However, I need a way to exclude the header on the first page of the chapter while retaining it on subsequent pages.

Please provide guidance on how to achieve this:

@page {
margin: 27mm 16mm 27mm 16mm;
size: 7in 9.25in;
}

div.chapter {
  page: chapter;
}

h1 {
  string-set: chapter content();
}

@page chapter:left {
  @top-center {
    font: 11pt "Bookerly", serif;
    content: string(chapter, first);
    vertical-align: bottom;
    padding-bottom: 2em;
    font-variant: small-caps;
   color: #888888;
  }

  @bottom-center {
    font: 11pt "Bookerly", serif;
    content: counter(page);
    padding-top: 2em;
    vertical-align: top;
  }
}

@page chapter:right {
  @top-center {
    font: 11pt "Bookerly", serif;
    content: string(chapter, first); 
    vertical-align: bottom;
    padding-bottom: 2em; 
  font-variant: small-caps;
color: #888888;
  }

  @bottom-center {
    font: 11pt "Bookerly", serif;
    content: counter(page);
    vertical-align: top;
    padding-top: 2em;
  }
}
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Book</title> </head> <body lang="CS" vlink="purple" link="blue" class="calibre"> <div class="chapter"> <h1 id="c1">Heading</h1> ... (Content Continues)

Answer №1

I managed to fix the issue by including the CSS snippet below:

@page chapter:first {
  @top-center {
    font: 11pt "Bookerly", serif;
    content: "";
    vertical-align: bottom;
    padding-bottom: 2em;
    font-variant: small-caps;
   color: #888888;
  }

  @bottom-center {
    font: 11pt "Bookerly", serif;
    content: counter(page);
    padding-top: 2em;
    vertical-align: top;
  }
}

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

1 in every 3 divs in jQuery, chosen randomly

Hey there! I have a fun project in mind - programming a "Rock Paper Scissors" game with the computer. The only issue is figuring out how to make the computer choose a random object after I pick one of the 3 options. Here's what I've come up with ...

Looking for assistance with arranging Divs in HTML?

Having trouble getting my colored div boxes aligned side by side. The lower two divs seem to be overlapping with the yellow div on top of the blue one. How can I fix this and get them to line up like the green and red divs? Could it be an issue with how I& ...

Sending a parameter to a different function (on a separate webpage)

At the start of my webpage, there are two radio buttons on the first page, each with its own value. Upon clicking a link to move to the second page, a for loop is activated to grab the value of the selected button. The script has been tested and works as e ...

The total height of an HTML element, which takes into account the margin of the element itself

Is there a way to accurately calculate the height of an element including margins, even when dealing with child elements that have larger margins than their parents? HTMLElement.offsetHeight provides the height excluding margin, while this function from ...

Alert appearing before the user navigates back using the browser button

Is there a way to display a message to the user before they navigate away from the app by clicking the back button in their browser? In my app, I've disabled the ability for users to go back using the browser's buttons and instead provided intern ...

What causes a header to appear transparent when it has a background color set in HTML?

I'm attempting to create a webpage that resembles Gmail. I have a header with a background color, but when I scroll, the content in the body becomes visible. Here is the view without scrolling: https://i.stack.imgur.com/UQ2sO.png However, while scr ...

The alignment of the Unicode character is off and is not centered within the button

Upon implementing a unicode character as a button, I've observed that the alignment of the character is not centered properly (both horizontally and vertically) within the button. It's puzzling why this misalignment occurs even after setting padd ...

What is the best way to extend an inline-block element to cover the entire text line?

Let's talk about the scenario: https://i.stack.imgur.com/we05U.png In the image, there is a container (displayed as a div) with only one child - a span element. The goal is to introduce a second child that occupies the entire red space depicted in t ...

React fullpage.js causing z-index stacking problems

Take a look at the demo here: I'm having trouble getting the 'more info' modal to display above all other elements on the screen. Here's the desired stacking order, with the highest stacked element listed first: modal nav open header ...

A Guide to Quickly Registering Multiple Sidebars in functions.php

I'm looking to efficiently register multiple sidebars at once and differentiate them by unique IDs, similar to how we can easily register multiple menus simultaneously such as Main-Menu and Footer-menu. <?php register_nav_menus(array('primary ...

Utilize Bootstrap columns to maximize vertical space efficiency

I recently came across a bootstrap layout like this: https://i.sstatic.net/VXBCF.png In this setup, there is a single .row that contains 8 .col-lg-3 divs. However, I noticed that there is excessive vertical whitespace present, which not only looks undesi ...

SVG Mask not functioning properly with SVGs created in Illustrator (in all web browsers)

Alright, let's get to it - I've got a couple of SVGs here. The first one is a blue circle and the second one is a map of the United States. (Both of these were created in Illustrator) Here's what I want to do: I want the map to serve as a ...

Applying custom CSS to individual divs based on their text height using jQuery

I have a grid consisting of multiple boxes each sized at 280px by 280px, and I am seeking a way to vertically align text within hover overlays on each box. While my current code successfully aligns the text for the first box, I am encountering issues due ...

Is there a way to access a comprehensive list of all the font names stored on my personal computer?

I'm currently working on a project that requires using local fonts only. Since I am using a Mac, I have located the fonts in /Library/Fonts. However, I have encountered an issue when trying to use a font named 华文黑体 directly in my CSS property: ...

How can I make two lines equal in length by stretching them?

Looking to replicate the design shown in the image below using CSS: https://i.stack.imgur.com/cZiFT.png It's crucial for me that both lines are of equal length: https://i.stack.imgur.com/8phWR.png I attempted to recreate it with the following code ...

Is it possible to transfer my Bubble webpage to another hosting server?

Can I export the "Code" from bubble.io to create my own server? Appreciate any help! ...

Implementing an onClick event to reveal a concealed div located above each bar in D3.js (potentially requiring additional CSS code)

I'm currently working on a project where I want a hidden div, named myDiv, to be displayed above the clicked bar whenever a square bar is clicked. Here's what I've attempted so far: 1) I have written a Javascript function called showDiv() ...

Discover a new method for mastering jQuery Draggable: an advanced technique

Click here for the interactive demo. I'm trying to create a draggable effect for the cover element within the pic-area, but I only want it to be draggable until it completely fills the space without any white gaps. Please have a look at the example b ...

Can an excess of CSS impact the speed and performance of a website?

After conducting thorough research on this specific topic, I was unable to locate the precise answer that I require. For instance, there are numerous divs within my project that necessitate a border. One approach is to create a distinct CSS class such as ...

Class for Eliminating the Background Image Using Bootstrap

Is there a Bootstrap class that can be used to remove a background image from a div? Currently, I have this style defined in my CSS: background-image: linear-gradient(to bottom, rgba(0,0,0,0.1), rgba(0,0,0,0)); I would like to remove it using: bg-img-non ...