Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
            
- /css/css-grid/masonry/tentative/abspos/row-masonry-alignment.html - WPT Dashboard Interop Dashboard
 
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>CSS Masonry Test: Masonry layout alignment properties for absolutely positioned elements</title>
  <link rel="author" title="Yanling Wang" href="mailto:yanlingwang@microsoft.com">
  <link rel="match" href="row-masonry-alignment-ref.html">
  <style>
    html,body {
        color:black;
        background-color:white;
        font:15px/1 monospace;
    }
    .container {
        width: 800px;
        height: 850px;
        border: 2px solid black;
        margin: 20px;
    }
    .masonry {
        display: masonry;
        masonry-direction: row;
        grid-template-rows: repeat(5, 150px);
        position: relative;
        padding: 20px;
        gap: 15px;
        border: 1px dashed #999;
        width: 700px;
    }
    .item {
        background: lightblue;
        padding: 10px;
        border: 1px solid blue;
        width: 80px;
    }
    .abspos {
        position: absolute;
        width: 40px;
        height: 60px;
        border: 2px solid black;
        font-size: 10px;
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
    }
    .align-self {
        grid-row: 2 / 3;
    }
    .align-start {
        align-self: start;
        background: lightcoral;
    }
    .align-end {
        align-self: end;
        background: lightgreen;
    }
    .align-center {
        align-self: center;
        background: lightblue;
    }
    .justify-self {
        grid-row: 4 / 5;
    }
    .justify-start {
        justify-self: start;
        background: gold;
    }
    .justify-end {
        justify-self: end;
        background: silver;
    }
    .justify-center {
        justify-self: center;
        background: tan;
    }
    .combo-center-center {
        grid-row: 3 / 4;
        align-self: center;
        justify-self: center;
        background: hotpink;
    }
    .safe-align {
        position: absolute;
        background: orange;
        border: 1px solid darkorange;
        grid-row: 1 / 2;
        height: 170px;
        width: 30px;
        align-self: safe end;
        justify-self: center;
        font-size: 10px;
    }
    .unsafe-align {
        position: absolute;
        background: purple;
        border: 1px solid darkmagenta;
        grid-row: 5 / 6;
        height: 170px;
        width: 30px;
        align-self: unsafe end;
        justify-self: center;
        font-size: 10px;
    }
  </style>
</head>
<body>
<div class="container">
  <div class="masonry">
    <div class="item">Item 1</div>
    <div class="item">Item 2</div>
    <div class="item">Item 3</div>
    <div class="abspos align-self align-start">align-self: start</div>
    <div class="abspos align-self align-end">align-self: end</div>
    <div class="abspos align-self align-center">align-self: center</div>
    <div class="item">Item 4</div>
    <div class="item">Item 5</div>
    <div class="abspos justify-self justify-start">justify-self: start</div>
    <div class="abspos justify-self justify-end">justify-self: end</div>
    <div class="abspos justify-self justify-center">justify-self: center</div>
    <div class="abspos combo-center-center">center + center</div>
    <div class="safe-align">align-self: safe end</div>
    <div class="unsafe-align">align-self: unsafe end</div>
  </div>
</div>
</body>
</html>