Comment

Comment by talideon

There's a way to centre variable width block elements that doesn't depend on flexbox, which is:

    .centred {
        /* Make the element only as wide as it needs to be. */
        display: inline-block;
        /* Let us apply positioning. */
        position: relative;
        /* Move the left of the element to the middle of the container. */
        left: 50%;
        /* Translate backwards half the width of the block, thus centring it. */
        transform: translateX(-50%);
    }
It's a useful bit of CSS to have around.
parent talideon 10 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton