Live data from Hacker News

How to Center in CSS

howtocenterincss.com

271–280 of 297 posts

Re: How to Center in CSS

#271

Earlier quoted context omitted.

I also find it crazy how there was a huge campaign to remove use of the table tag for layout. 'It's non semantic! You're mixing layout and content!' people would cry over and over. .. But then we've ended up with bootstrap and it's grid layout, where we're doing exactly that, and for some reason it's perfectly fine.

The problem with tables for layout is that the layout algorithm is incredibly complex. People seem to think it's simple, because it kinda does the "right thing" in many cases, but it's actually ill-defined, varies between browsers, and has only a work-in-progress spec [1]. Width calculation is defined in terms of linear interpolation between the closest of four "candidate guesses" which bound the available width. And…

> because it kinda does the "right thing" in many cases, but it's actually ill-defined, varies between browsers, and has only a work-in-progress spec

Which is completely not like using CSS at all, right?

Re: How to Center in CSS

#272

Earlier quoted context omitted.

Sweet. I figure only 15 more years until we get two column layouts working, and then we'll finally be able to publish like it's 1979.

CSS multicolumn layout is four years old. It's implemented in all the major browser engines, and many popular sites like Wikipedia use it. http://www.w3.org/TR/css3-multicol/

Like I said, "working". I don't want two columns stretching ten feet long. I want two columns on this page, two on the next, two on the one after that...

Re: How to Center in CSS

#274

Earlier quoted context omitted.

The problem with tables for layout is that the layout algorithm is incredibly complex. People seem to think it's simple, because it kinda does the "right thing" in many cases, but it's actually ill-defined, varies between browsers, and has only a work-in-progress spec [1]. Width calculation is defined in terms of linear interpolation between the closest of four "candidate guesses" which bound the available width. And…

> because it kinda does the "right thing" in many cases, but it's actually ill-defined, varies between browsers, and has only a work-in-progress spec Which is completely not like using CSS at all, right?

Like I said, I've implemented both. CSS 2.1 was much easier than tables. Almost everything I implemented in CSS 2.1 made sense (with some notable exceptions, such as the hypothetical box, margin collapse, and border collapse). Tables were nonstop backwards compatibility hacks.

Re: How to Center in CSS

#275

To save people a bunch of time, here's 90% of the comments: >Just use flexbox! Which is great, except it isn't supported at all by IE8 or 9 and is only partially supported in IE10 (by prefix only). Which means a lot of people simply can't use it. I'm hesitant to use it myself, and I've got a very lax policy on supporting old IE.

It's a business decision to limit forward progress to support browsers 3-4 major versions behind. One that multi-billion dollar companies like Google have decided isn't worth it.

"A lot of people" = 4% on IE 8 & 9 (http://www.w3counter.com/globalstats.php)

Re: How to Center in CSS

#276
post #38

The mere fact that a site like this can exist and not be a joke is proof that CSS is still badly broken. I should be able to center things by writing: foo { align: center; valign: center; }

It really isn't.

There's this misconception that CSS is a display language; it's actually designed as a typesetting language that must degrade nicely.

Re: How to Center in CSS

#277

Earlier quoted context omitted.

You forgot the performance problem....

And anyone who wants to browse with JavaScript disabled…

I stopped worrying about those users years ago. Don't even bother with anymore. It's 2015 and all browsers support JS these days. If you disable browser features then you really shouldn't be surprised when functionality breaks. The same would happen if you disabled CSS or images.

Re: How to Center in CSS

#278
post #38

The mere fact that a site like this can exist and not be a joke is proof that CSS is still badly broken. I should be able to center things by writing: foo { align: center; valign: center; }

You're in luck. foo { display: flex; /* opt into the new box model */ justify-content: center; /* "align" */ align-items: center; /* "valign" */ } Vendor prefixes may or may not ruin your day (for now), but the spec is there and is exactly what you want. CSS is no longer "badly broken" if that's your metric.

Flexbox has made our life much better. But we still run into a bunch of implementation bugs, meaning that it will take a few more years for the promise to become reality: https://github.com/philipwalton/flexbugs

Re: How to Center in CSS

#279

To save people a bunch of time, here's 90% of the comments: >Just use flexbox! Which is great, except it isn't supported at all by IE8 or 9 and is only partially supported in IE10 (by prefix only). Which means a lot of people simply can't use it. I'm hesitant to use it myself, and I've got a very lax policy on supporting old IE.

It's a business decision to limit forward progress to support browsers 3-4 major versions behind. One that multi-billion dollar companies like Google have decided isn't worth it. "A lot of people" = 4% on IE 8 & 9 ( http://www.w3counter.com/globalstats.php )

Really depends on the business and their clients. If you've got a lot of corporate clients stuck on IE8/9, why disenfranchise them? Although I will say this has me re-considering flex.
Post reply on HN