Skip to content

Orphan html elements #481

Open
Open
@keycad

Description

@keycad

Hi,
I have a dynamic document which has some subheadings and variable length content below. In some cases, I get a heading placed at the end of one page, while the content starts in the next one. I tried to use orphans property, but during my tests I found it only works within the same tag.

So, how can I achieve this?

This is a small example to reproduce it, based on your annotated example. The desired effect would move "Title" to a new page, if there's no room for "Line 1" as well in the same page.

    .no-orphans {
      widows: 0;
      orphans: 2;
    }

  <div class="no-orphans">
    <h2>Title</h2>
    <p>Line 1</p>
    <p>Line 2</p>
    <p>Line 3</p>
    <p>Line 4</p>
    Line 5<br/>
    Line 6<br/>
    Line 7<br/>
    Line 8<br/>
    Line 9<br/>
    Line 10<br/>
    Line 11<br/>
  </div>

NOTE: This is a small repro based on the example, but the real scenario replaces all the <p>'s content with <div>'s that contain images, text... And the amount of these is dynamically generated, so it's not easy to enclose the first one with the title in the same container to include a no-break-inside property, without including some non-desired and custom logic in the template.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions