News for hackers. Stuff that matters.
Re:How to Center in CSS (2015) by ChrisMarshallNY on Tuesday May 19, 2020 @11:11AM (#23235689)
Here's what I've been doing for years (The <div> can be any element, like <ul>):

<div id="wrapper" style="text-align:center"> <div id="wrapped" style="display:table;margin-left:auto;margin-right:auto;text-align:left"></div> </div>

WFM YMMV

Re:How to Center in CSS (2015) by RyanGoosling on Tuesday May 19, 2020 @11:30AM (#23235935)
You don't need the style="text-align:center" on your wrapper element
Re:How to Center in CSS (2015) by ChrisMarshallNY on Tuesday May 19, 2020 @02:50PM (#23238601)
> You don't need the style="text-align:center" on your wrapper element

Why not? The goal is to center something with an unpredictable size.

display:block adapts to the container. display:table adapts to the contents.

This uses both.

Re:How to Center in CSS (2015) by RyanGoosling on Tuesday May 19, 2020 @03:26PM (#23239017)
A box isn't text. Why don't you give it a whirl.
Re:How to Center in CSS (2015) by ChrisMarshallNY on Tuesday May 19, 2020 @04:59PM (#23240121)
Oh, I see. Gotcha. I use it for images and lists, so I've gotten used to it.

Cool. Thanks!

Re:How to Center in CSS (2015) by mattwad on Tuesday May 19, 2020 @11:14AM (#23235733)
you really use the same id twice on a page?! Heresey! Also.. I do the same (essentially: margin: 0 auto) but it works with display: block too, and you don't need text-align center on the parent.
Re:How to Center in CSS (2015) by bzb3 on Tuesday May 19, 2020 @11:18AM (#23235783)
It's not the same id: wrapper vs wrapped
Re:How to Center in CSS (2015) by ChrisMarshallNY on Tuesday May 19, 2020 @02:46PM (#23238538)
They were not IDs. They were indicators of what the div is for.

It was sort of HTML-pseudocode.

In any case, this is exactly how you center something that doesn't try to stretch across the entire page. It's old-fashioned, but robust.

Also, I would generally not use inline CSS. I think of it like I think of !important: the nuclear option.

That said, I tend to use inline styles a lot for WordPress site content, because I don't want to deal with the slow-ass "customize" option.