openhtmltopdf icon indicating copy to clipboard operation
openhtmltopdf copied to clipboard

Absolute positioned “labels” with long but clipped content are placed at improper position

Open devopsix opened this issue 3 years ago • 0 comments

Given this markup and styles:

<!DOCTYPE html>
<html lang="en">
<head>
    <style>
        .box {
            position: relative;
            width: 50mm;
            height: 50mm;
            margin: 10mm;
            border: 1pt solid black;
        }
        .label {
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
            border: 1pt solid red;
            text-align: center;
        }
        .clip {
            display: inline-block;
            max-width: 30mm;
            white-space: nowrap;
            overflow: hidden;
        }
    </style>
</head>
<body>
    <div class="box">
        <span class="label">Label</span>
    </div>
    <div class="box">
        <span class="label clip">Short<br />label</span>
    </div>
    <div class="box">
        <span class="label clip">Very, very, very, very, very, very, very, very, very long label</span>
    </div>
    <div class="box">
        <span class="label clip">Very, very, very, very, very, very, very, very, very long<br />label</span>
    </div>
</body>
</html>

The output should look like this (Chrome):

image

But it does look like this:

image

Sample project to reproduce the above

devopsix avatar Nov 23 '21 16:11 devopsix