News for hackers. Stuff that matters.
Re:Plugging a 1986 Mac Plus into the Modern Web (2013) by icebraining on Sunday March 22, 2015 @06:28PM (#9248526)
Doesn't simply replacing the table/tr/td with a div with "margin: auto; text-align: center" work? Seems to yield the same result, at least in Firefox.
Re:Plugging a 1986 Mac Plus into the Modern Web (2013) by lisper on Sunday March 22, 2015 @06:42PM (#9248569)
Margin: auto doesn't center vertically. Also, it only centers the element that it applies to, not the contents of that element. My example was supposed to illustrate this, but it actually has a bug. I thought buttons didn't get centered by text-align, but they do. Here's an updated example:

    <table style='height: 100%; width: 100%'>
      <tr><td align=center valign=center>
	<h1>Hello world</h1>
	The following green square should be centered:<br>
        <div style='width: 30px; height: 30px; background: green'></div>
      </td></tr>
    </table>
margin:auto also requires you to manually set the width of the div you're trying to center in order to work.
Re:Plugging a 1986 Mac Plus into the Modern Web (2013) by nkuttler on Sunday March 22, 2015 @07:31PM (#9248699)
That's easy to do without tables. See display: table; and display: inside-block for the div. text-align: center, yadda.
Re:Plugging a 1986 Mac Plus into the Modern Web (2013) by lisper on Sunday March 22, 2015 @08:25PM (#9248826)
Display: table is cheating, and essentially conceding that you should have been using tables all along. And there is no such thing as display: inside-block. (You probably meant inline-block.)

The devil is in the details. I believe if you try it you will find it is nowhere near as easy as you imagine.

Re:Plugging a 1986 Mac Plus into the Modern Web (2013) by JoshTriplett on Sunday March 22, 2015 @10:32PM (#9249200)
> Display: table is cheating, and essentially conceding that you should have been using tables all along.

Not at all. "display: table" (and the related "display: table-cell" and similar) mean that you've written something which is not semantically a table, but which should use the browser rendering conventions of a table. That's a perfectly reasonable distinction.

Otherwise, would you suggest that every use of "font-family: sans-serif" is cheating and essentially conceding that you should have been using a <font> tag all along?

Re:Plugging a 1986 Mac Plus into the Modern Web (2013) by lisper on Sunday March 22, 2015 @11:27PM (#9249355)
> Otherwise, would you suggest that every use of "font-family: sans-serif" is cheating

Yes, if your intent is to use font-family as an example in an argument for using CSS.

> and essentially conceding that you should have been using a <font> tag all along?

No, I'm saying that a font tag and a font-family style are equivalent. One is as good as the other.

You should read this:

http://blog.rongarret.info/2009/02/on-semantics-of-html.html

Re:Plugging a 1986 Mac Plus into the Modern Web (2013) by JoshTriplett on Monday March 23, 2015 @12:25AM (#9249497)
Even if you argue that HTML tags don't have semantic meanings (which I'd strongly disagree with, pointing to numerous tools that derive useful semantic information from such tags), there's quite a lot of value in defining your markup in terms of semantics and then separately defining what you want those semantics to look like. With good semantic markup, you can easily retheme your site to look completely different, make it scale to a mobile UI, or make it accessible to users of screen readers.

So, there's a major difference between using font-family and a <font> tag, and a major difference between using display: table* and <table>/<tr>/<td> tags. And for the same reason, you shouldn't use class="sidebar" if what you mean is class="navigation" (or for that matter <nav>). Let alone class="big-red-button" when what you mean is class="delete".

To use an example from that article: sure, <p> is not as semantically significant as <section> or <h1>, but it's a lot more semantic than, say, <br/><br/>, which I've seen used between paragraphs. "This is a paragraph" is more semantically useful than "this has an indent on the left and 1.4x line spacing"; "this is a heading" is more semantically useful than "this is 24pt and bold".

Re:Plugging a 1986 Mac Plus into the Modern Web (2013) by lisper on Monday March 23, 2015 @01:56AM (#9249655)
> there's quite a lot of value in defining your markup in terms of semantics and then separately defining what you want those semantics to look like

I completely agree. But HTML+CSS does not achieve that goal, at least, it didn't when that post was written.

Re:Plugging a 1986 Mac Plus into the Modern Web (2013) by rgro on Sunday March 22, 2015 @10:35PM (#9249210)
Although it was a little late to the party, flexbox solves a bunch of issues with css layouts.

Here's a working example that doesn't use tables: https://jsfiddle.net/q8zxxr3b/

Or, here's the inline example:

  <div style="display: flex; height: 100%; flex-direction: column; align-items:center; justify-content: center;">
      <div style="text-align: center;">
          <h1>Hello world</h1>
          The following green square should be centered:<br />
          <div style="display: inline-block; width: 30px; height: 30px; background: green;"></div>
      </div>
  </div>
Re:Plugging a 1986 Mac Plus into the Modern Web (2013) by lisper on Sunday March 22, 2015 @11:22PM (#9249341)
No, you have to vertically center it as well. Horizontal centering is fairly easy even with flex-box.
Re:Plugging a 1986 Mac Plus into the Modern Web (2013) by nostrademons on Monday March 23, 2015 @01:12AM (#9249582)
Vertically centered on Chrome Mac as well. Safari (and IE) still requires a vendor prefix to use flexbox, but with that added, it works in Safari as well:

https://jsfiddle.net/k281a8v0/

Re:Plugging a 1986 Mac Plus into the Modern Web (2013) by lisper on Monday March 23, 2015 @01:54AM (#9249652)
Congratulations, yours is the first solution I've seen that actually works.
Re:Plugging a 1986 Mac Plus into the Modern Web (2013) by simcop2387 on Sunday March 22, 2015 @11:34PM (#9249371)
This does appear to be vertically centering it, at least in Firefox.
Re:Plugging a 1986 Mac Plus into the Modern Web (2013) by sim0n on Monday March 23, 2015 @01:10AM (#9249580)
That does vertically center the content.