ish1301 ish1301 - 1 year ago 70
CSS Question

How to center absolute element in div?

I need to place a

) element in the center of my window. But I am having problems doing so, because the width is unknown

I tried this. But it needs to be adjusted as the width is responsive.

.center {
left: 50%;

Any ideas?

Answer Source
    <div style="position: absolute; left: 50%;">
        <div style="position: relative; left: -50%; border: dotted red 1px;">
            I am some centered shrink-to-fit content! <br />
            tum te tum