Live data from Hacker News

How to Center in CSS (2015)

howtocenterincss.com

31–40 of 74 posts

Re: How to Center in CSS (2015)

#31
post #25

It doesn't solve vertical centering, but I am secretly still a fan of the center-tag. Just does what it's name implies in most situations. I still don't get why its avoided like the plague.

I've been doing HTML for ~10 years and have never seen this before. Apparently, it was deprecated with HTML4 already, though I'm not sure why.

Re: How to Center in CSS (2015)

#32
post #2

This is a straw man. Today you can simply use flexbox on the container: display: flex; justify-content: center; // horizontal align-items: center; // vertical Doesn't work in IE without a JS polyfill (which is available), but has worked in all other browsers for six years or so.

And yet six years later still no widespread support for the 'safe' keyword. Which means the content can overflow the container without a way to scroll to some parts of it: https://jsfiddle.net/r50qseah/

Re: How to Center in CSS (2015)

#33
Centering in CSS is "solved" problem if your "worst" browser to support is IE11. Flexbox does the job there.

However, there are still couple of common tasks that are pain/hard/impossible to do with just CSS.

Recently I learned that after all this years you still need to use JS to get css animation for dynamic height ("height:auto") of elements.

And there is no progress in fixing it at CSS standard level. It's just sad... https://github.com/w3c/csswg-drafts/issues/626 https://stackoverflow.com/questions/3508605/how-can-i-transi... https://stackoverflow.com/questions/3508605/how-can-i-transi...

Re: How to Center in CSS (2015)

#34
post #32
post #2

This is a straw man. Today you can simply use flexbox on the container: display: flex; justify-content: center; // horizontal align-items: center; // vertical Doesn't work in IE without a JS polyfill (which is available), but has worked in all other browsers for six years or so.

And yet six years later still no widespread support for the 'safe' keyword. Which means the content can overflow the container without a way to scroll to some parts of it: https://jsfiddle.net/r50qseah/

What is the 'safe' keyword?

Re: How to Center in CSS (2015)

#35
post #25

It doesn't solve vertical centering, but I am secretly still a fan of the center-tag. Just does what it's name implies in most situations. I still don't get why its avoided like the plague.

Earlier HTML had tags that styled elements. The community decided it would be better if styling was left to CSS and HTML simply described document structure. This way styling lives in one kind of file instead of two different places.

I wouldn’t recommend using it for big or professional projects, but I guess it’s fine for personal stuff. Like the other comment said it’s an obsolete tag. Browsers tend try hard not to break old HTML but not sure that’s guaranteed to always be the case.

Re: How to Center in CSS (2015)

#36

Centering in CSS is "solved" problem if your "worst" browser to support is IE11. Flexbox does the job there. However, there are still couple of common tasks that are pain/hard/impossible to do with just CSS. Recently I learned that after all this years you still need to use JS to get css animation for dynamic height ("height:auto") of elements. And there is no progress in fixing it at CSS standard level. It's just sa…

There are some tricks you can use if you know the max possible height your element can have, but it's not great, yeah.

Edit: Oh, I just saw that the stackoverflow question you linked has this for the accepted answer :)

Re: How to Center in CSS (2015)

#37
post #32

Earlier quoted context omitted.

And yet six years later still no widespread support for the 'safe' keyword. Which means the content can overflow the container without a way to scroll to some parts of it: https://jsfiddle.net/r50qseah/

What is the 'safe' keyword?

https://drafts.csswg.org/css-align-3/#overflow-values

Re: How to Center in CSS (2015)

#38
A wise man once said (me): ill use until the end of time and thy browsers shall support it. (did of course learn the new and improved ways to qualify the ignorance)

Re: How to Center in CSS (2015)

#39

Earlier quoted context omitted.

I just throw a in, it works well enough for most cases.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ce... The element is obsolete and is not in the HTML5 spec...

So? The browser doesn’t care.

You’re right of cause and centering is styling and it doesn’t belong in the html. It just that sometimes I really can’t be bothered with css and the center hr and a ton of br slips in, and it works well enough.

Re: How to Center in CSS (2015)

#40
post #25

It doesn't solve vertical centering, but I am secretly still a fan of the center-tag. Just does what it's name implies in most situations. I still don't get why its avoided like the plague.

I've been doing HTML for ~10 years and have never seen this before. Apparently, it was deprecated with HTML4 already, though I'm not sure why.

Probably the same reason that (bold) and (italics) aren't used anymore. There's now a clearer delineation between document structure (described via tags) and style (described via CSS) than there was in the earlier HTML specs.
Post reply on HN