Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      The Ultimate Guide to Node.js Development Pricing for Enterprises

      July 29, 2025

      Stack Overflow: Developers’ trust in AI outputs is worsening year over year

      July 29, 2025

      Web Components: Working With Shadow DOM

      July 28, 2025

      Google’s new Opal tool allows users to create mini AI apps with no coding required

      July 28, 2025

      5 preinstalled apps you should delete from your Samsung phone immediately

      July 30, 2025

      Ubuntu Linux lagging? Try my 10 go-to tricks to speed it up

      July 30, 2025

      How I survived a week with this $130 smartwatch instead of my Garmin and Galaxy Ultra

      July 30, 2025

      YouTube is using AI to verify your age now – and if it’s wrong, that’s on you to fix

      July 30, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Time-Controlled Data Processing with Laravel LazyCollection Methods

      July 30, 2025
      Recent

      Time-Controlled Data Processing with Laravel LazyCollection Methods

      July 30, 2025

      Create Apple Wallet Passes in Laravel

      July 30, 2025

      The Laravel Idea Plugin is Now FREE for PhpStorm Users

      July 30, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      New data shows Xbox is utterly dominating PlayStation’s storefront — accounting for 60% of the Q2 top 10 game sales spots

      July 30, 2025
      Recent

      New data shows Xbox is utterly dominating PlayStation’s storefront — accounting for 60% of the Q2 top 10 game sales spots

      July 30, 2025

      Opera throws Microsoft to Brazil’s watchdogs for promoting Edge as your default browser — “Microsoft thwarts‬‭ browser‬‭ competition‬‭‬‭ at‬‭ every‬‭ turn”

      July 30, 2025

      Activision once again draws the ire of players for new Diablo Immortal marketing that appears to have been made with generative AI

      July 30, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»Anchor Positioning Just Don’t Care About Source Order

    Anchor Positioning Just Don’t Care About Source Order

    April 28, 2025

    Ten divs walk into a bar:

    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
    <div>6</div>
    <div>7</div>
    <div>8</div>
    <div>9</div>
    <div>10</div>

    There’s not enough chairs for them to all sit at the bar, so you need the tenth div to sit on the lap of one of the other divs, say the second one. We can visually cover the second div with the tenth div but have to make sure they are sitting next to each other in the HTML as well. The order matters.

    <div>1</div>
    <div>2</div>
    <div>10</div><!-- Sitting next to Div #2-->
    <div>3</div>
    <div>4</div>
    <div>5</div>
    <div>6</div>
    <div>7</div>
    <div>8</div>
    <div>9</div>

    The tenth div needs to sit on the second div’s lap rather than next to it. So, perhaps we redefine the relationship between them and make this a parent-child sorta thing.

    <div>1</div>
    <div class="parent">
      2
      <div class="child">10</div><!-- Sitting in Div #2's lap-->
    </div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
    <div>6</div>
    <div>7</div>
    <div>8</div>
    <div>9</div>

    Now we can do a little tricky positioning dance to contain the tenth div inside the second div in the CSS:

    .parent {
      position: relative; /* Contains Div #10 */
    }
    
    .child {
      position: absolute;
    }

    We can inset the child’s position so it is pinned to the parent’s top-left edge:

    .child {
      position: absolute;
      inset-block-start: 0;
      inset-inline-start: 0;
    }

    And we can set the child’s width to 100% of the parent’s size so that it is fully covering the parent’s lap and completely obscuring it.

    .child {
      position: absolute;
      inset-block-start: 0;
      inset-inline-start: 0;
      width: 100%;
    }

    Cool, it works!

    CodePen Embed Fallback

    Anchor positioning simplifies this process a heckuva lot because it just doesn’t care where the tenth div is in the HTML. Instead, we can work with our initial markup containing 10 individuals exactly as they entered the bar. You’re going to want to follow along in the latest version of Chrome since anchor positioning is only supported there by default at the time I’m writing this.

    <div>1</div>
    <div class="parent">2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
    <div>6</div>
    <div>7</div>
    <div>8</div>
    <div>9</div>
    <div class="child">10</div>

    Instead, we define the second div as an anchor element using the anchor-name property. I’m going to continue using the .parent and .child classes to keep things clear.

    .parent {
      anchor-name: --anchor; /* this can be any name formatted as a dashed ident */
    }

    Then we connect the child to the parent by way of the position-anchor property:

    .child {
      position-anchor: --anchor; /* has to match the `anchor-name` */
    }

    The last thing we have to do is position the child so that it covers the parent’s lap. We have the position-area property that allows us to center the element over the parent:

    .child {
      position-anchor: --anchor;
      position-area: center;
    }

    If we want to completely cover the parent’s lap, we can set the child’s size to match that of the parent using the anchor-size() function:

    .child {
      position-anchor: --anchor;
      position-area: center;
      width: anchor-size(width);
    }
    CodePen Embed Fallback

    No punchline — just one of the things that makes anchor positioning something I’m so excited about. The fact that it eschews HTML source order is so CSS-y because it’s another separation of concerns between content and presentation.


    Anchor Positioning Just Don’t Care About Source Order originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleNVIDIA Riva Vulnerabilities Leave AI-Powered Speech and Translation Services at Risk
    Next Article GitHub for Beginners: Building a REST API with Copilot

    Related Posts

    News & Updates

    5 preinstalled apps you should delete from your Samsung phone immediately

    July 30, 2025
    News & Updates

    Ubuntu Linux lagging? Try my 10 go-to tricks to speed it up

    July 30, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    CVE-2025-7528 – Tenda FH1202 Stack-Based Buffer Overflow Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-44888 – Foresight Wireless FW-WGS-804HPT Stack Overflow Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-4336 – eMagicOne Store Manager for WooCommerce Arbitrary File Upload Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Meet Rowboat: An Open-Source IDE for Building Complex Multi-Agent Systems

    Machine Learning

    Highlights

    Multiple HPE StoreOnce Vulnerabilities Let Attackers Execute Malicious Code Remotely

    June 3, 2025

    Multiple HPE StoreOnce Vulnerabilities Let Attackers Execute Malicious Code Remotely

    Multiple security vulnerabilities in Hewlett-Packard Enterprise (HPE) StoreOnce software platform that could allow remote attackers to execute malicious code, bypass authentication mechanisms, and acc …
    Read more

    Published Date:
    Jun 03, 2025 (4 hours, 3 minutes ago)

    Vulnerabilities has been mentioned in this article.

    CVE-2025-37096

    CVE-2025-37095

    CVE-2025-37094

    CVE-2025-37093

    CVE-2025-37092

    CVE-2025-37091

    CVE-2025-37089

    This interactive AI video generator feels like walking into a video game – how to try it

    May 30, 2025

    Best USB WiFi Adapter For Kali Linux 2023 [Updated September]

    June 3, 2025

    CVE-2013-1424 – Matplotlib Buffer Overflow Vulnerability

    June 26, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.