Live data from Hacker News

How to Center in CSS

howtocenterincss.com

91–100 of 297 posts

Re: How to Center in CSS

#91
post #66

Earlier quoted context omitted.

and I wonder how the somehow survived unscathed and free from the semantic witch hunt of yore. shouldn't we replace them with: ?

This comment doesn't make any sense. A list is a thing, just as a table is... What are you trying to say?

Down vote for "doesn't make sense". It made perfect sense to me.

The phrase you were looking for is " I don't understand what you're saying."

Re: How to Center in CSS

#92
post #29
post #17

Earlier quoted context omitted.

Verbose? Compared to the other solutions it's a godsend, just use the CSS-tricks guide for it and you'll have nearly zero problems. I absolutely love it and pretty much refuse to use anything else for layout in CSS now.

IMHO constraint systems like GSS ( http://gridstylesheets.org/ ) handle centering in a much cleaner way. Pity that approach hasn't gotten any traction (though some people smarter than me say it's a bad idea, so who knows what the right answer is...)

When I first heard of GSS I thought it was the solution to layout that we'd all been waiting for. Unfortunately it's not all roses. It's possible, and quite easy to inadvertently create cyclical constraint dependencies. Depending on how your constraint solver is written this might mean that a layout will fail or that your system will lock or crash.

I'm subscribed to a couple of constraint solver mailing lists. A common question is "why is my constraint solver doing this...?", or "how do I massage my constraints to achieve this...?"

With CSS You can't build a layout that 'fails' (in the sense that a solution cannot be computed due to improperly defined dependencies), and you certainly can't send your browser into an infinite loop by applying an incorrect style.

I still really like the idea of constraint based systems, but I think they are more suited to (web)applications rather than documents.

Re: How to Center in CSS

#93
post #76

Earlier quoted context omitted.

I have not found a project yet that I could divorce the layout from the content without the use of javascript. i gave css many attempts at this. mainly from the desire to make the content easy to manage for others. or just for aesthetics. but css was (is) too clunky to make that separation. yet people still argue that not limiting yourself to what css can provide you, thereby giving up on the purity of content vs lay…

I'd agree it's not completely divorced, but it's much, much better than it used to be. If you've worked in environments where the only access you have is CSS (for instance, locked down CMSes, or editing subreddits), you'll find that many solutions are possible without manipulating HTML. CSS can be very powerful; especially with the advanced selectors of CSS3.

I think I'd rather just manipulate HTML with Javascript. At least then I only have one problem, which is HTML with inline styles. No separate CSS file to maintain or CSS rule precedence to worry about.

Re: How to Center in CSS

#95
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.

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.

Re: How to Center in CSS

#96
post #83

Earlier quoted context omitted.

That's really counterintuitive; the vertical center isn't an absolute position.

You need absolute positioning because margins in the normal flow are special in that they're subject to margin collapse, and trying to specify some sort of special interaction between margin collapse and "margin: auto" would be too complex. Absolute positioning is also nice because it has a well-defined notion of a containing block , which allows CSS 2.1 to easily define "what I'm vertically centering relative to". T…

If I wanted to do those things, I should write "margin-collapse: disabled" and "vertical-align: center". Making your abstractions leaky on purpose doesn't mean you're justified in doing it.

I don't understand CSS all that well, but I do understand basic layout concepts and my specific intent, and it isn't very productive to have to wait around for people like you to write books and answer stack overflow questions just so I can use CSS to do what it was designed to do. If I write "margin: auto" on an absolutely positioned element, I would expect it to do nothing, since those are just contradictory demands. I wouldn't expect it to do something completely unrelated like vertical centering.

Re: How to Center in CSS

#98

This is why css is fundamentally broken. Centering should be a feature in itself. I shouldn't be manipulating other attributes to achieve centering.

It is a feature of CSS 2.1. See my reply to chubs above. CSS 2.1 10.6.4 requires that "margin: auto" on both sides of an absolutely-positioned element mean "vertically center it".

You're saying that because they defined centering to occur when I mess with margins that makes centering a feature? Technically yes...

I meant an explicit feature with it's own attribute.

Re: How to Center in CSS

#99
post #91

Earlier quoted context omitted.

This comment doesn't make any sense. A list is a thing, just as a table is... What are you trying to say?

Down vote for "doesn't make sense". It made perfect sense to me. The phrase you were looking for is " I don't understand what you're saying."

Then perhaps you would like to explain it? The most meaningful interpretation I can see is that the commenter completely misunderstood the nature of the "semantic witch hunt" to which he referred. It seems charitable to assume that something was lost in translation and to ask for clarification rather than to assume that the commenter was just saying something stupid.

Re: How to Center in CSS

#100
post #19

Earlier quoted context omitted.

Which is why you use something like AutoPrefixer to automagically generate the needed browser prefixes and such, makes it a whole lot easier.

Which still doesn't cover older browsers just prefixes things appropriately for those that support it.

Fair enough, but for my uses 92% browser support is more than enough, it's the same as ems/rems for example.
Post reply on HN