Skip to content

Truly independent web browser

1.3 KB
Raw Blame
<!DOCTYPE html>
<script src="../../include.js"></script>
<style>
    .container { container-type: size; height: 20px; }
    #first { width: 200px; }
    #second { width: 300px; }
    .target { width: 1px; }
    .target.direct { width: 20cqw; }
    .target.mixed { width: calc(1cqw * sibling-index()); }
</style>
<div class="container" id="first"><div class="target" id="firstTarget"></div></div>
<div class="container" id="second"><span></span><div class="target" id="secondTarget"></div></div>
<script>
    // Switches container-relative lengths on in two elements that already have records, under
    // containers of different widths, and prints what they compute to.
    test(() => {
        const width = element => getComputedStyle(element).width;
        const widths = () => `${width(firstTarget)}, ${width(secondTarget)}`;
        document.body.offsetWidth;
        println(`initial: ${widths()}`);
        for (const className of ["direct", "mixed"]) {
            firstTarget.className = `target ${className}`;
            secondTarget.className = `target ${className}`;
            internals.updateStyle();
            println(`${className}: widths ${widths()}`);
        }
        first.style.width = "250px";
        document.body.offsetWidth;
        println(`resized: ${widths()}`);
    });
</script>