I've been slammed at work and not updating this site as much, though I have two biggish posts planned: a followup to my previous discussion about table layout, and the results from a hackathon my company ran the other week.
So I have put out arguments that tables solve more problems than they cause, but the accursed IE8 through up a counterargument... in short it looks like using colspans on rows before rows with items that have set widths may lead to frustrating results. A temporary fix was moving the "offending" colspan to its own table, but I refer my future self to this stackoverflow discussion that describes how setting "table-layout:fixed;" and a placeholder row explicitly setting widths, before the colspan, seems to lead to the correct behavior.
Wednesday, June 27, 2012
Tuesday, June 5, 2012
a sinking feeling about floating
I sometimes worry that I'm making what an old boss coined a CLM (career-limiting-move) by publicly declaring my irritation with floating divs vs tables.
My preference for tables is a a hangover from my paleolithic web roots, I'm afraid, but I'm not convinced modern html5-based design provides a solid alternative for flexible grid-based design. Floated divs certainly have advantages (in flexiblity, readability, division of form from content) but "always having things stay where you'd expect them to" isn't among them.
Case in point: here is some CSS and its rendered result when applied to a wrapper div and 6 children, color coded for your convenience:
<style>
.floater_wrapper {
background-color:#cccccc;
width:160px;
height:58px;
}
.floater_wrapper div{
float:left;
width:40px;
height:20px;
margin:4px;
text-align:center;
}
.floater_wrapper div:hover{
margin:2px;
border:2px solid white;
}
</style>
Simple enough, right? Float divs, and add a border when hovered. And in general it works ok... except on Firefox and Chrome, if you happen to have changed the page zoom (like by pressing ctrl-+) up a notch. In that case when you hover over 3 the floating changes, the box 4 jumps to underneath 3, and 5 and 6 get pushed down a row, outside of the box.
I'm not sure exactly what's going on, in terms of why the "4" thinks "2" is lower than "3" and so it floats against that-- I assume the screen zoom is putting in rounding errors. This particular case is easily remedied by not changing the margin when hovered and giving the non-hover state a transparent border, rather than assuming a 2px border plus a 2px margin is the same as a 4px margin.
So this case had a simple fix, but the non-intuitiveness and obscurity of the error (in terms of the page zoom) gives me pause. A radical change in structure like that is just not something you would have seen in a table-as-layout solution. Just to get it out of my system, I'd like to write a few more advantages caveman-tables-for-layout have over floating divs. (Which is the fairest way of putting it, I think: people who say the argument is "tables vs css" are being grossly unfair.)
Eric Meyer, in 2009, put it pretty well:
I can see the advantages that floated divs can have: like in today's example I didn't need to pollute the numbered divs with table structure layout, and programmatically it would have easier to just keep on adding in divs, rather than having to coordinate the row structure. (and yeah yeah yeah, tables are for tabular data and using them for layout is the anti-thesis of proper html5 semantic thinking.)
But on the flipside, the wrapper in this example had a fixed height, in part because a container div will collapse if all its contents are floated (hence things like the clearfix hack... and don't get me started about some of the disgusting stuff I've seen to get columns to line up!)
Finally, beside my love of colspans and rowspans and what not, it's a lot easier to throw a "border" onto a misbehaving table you're trying to construct than to get a visualization of errantly interacting floating divs!
I'm swimming against the tide of design history here, I know, but until I learn of a better way to get grid-like behavior on a webpage, tables are going to be part of my web design arsenal.
(Quick followup as I ponder this a bit more: I do realize responsive design is generally a lot harder with tables, because of the mix of form and content. Most of what I really count on tables for, though, is not in the "whole page" style of layout, but for individual smaller widgets, where you really don't want things jumping around, and for them to keep their general relative positions. That's actually one of the paradoxes of responsive design: usually you want layout things to stay the same, no matter how the content changes, but with responsive design you finally want things to shift when the content seems to big for the space allotted...)
My preference for tables is a a hangover from my paleolithic web roots, I'm afraid, but I'm not convinced modern html5-based design provides a solid alternative for flexible grid-based design. Floated divs certainly have advantages (in flexiblity, readability, division of form from content) but "always having things stay where you'd expect them to" isn't among them.
Case in point: here is some CSS and its rendered result when applied to a wrapper div and 6 children, color coded for your convenience:
<style>
.floater_wrapper {
background-color:#cccccc;
width:160px;
height:58px;
}
.floater_wrapper div{
float:left;
width:40px;
height:20px;
margin:4px;
text-align:center;
}
.floater_wrapper div:hover{
margin:2px;
border:2px solid white;
}
</style>
1
2
3
4
5
6
Simple enough, right? Float divs, and add a border when hovered. And in general it works ok... except on Firefox and Chrome, if you happen to have changed the page zoom (like by pressing ctrl-+) up a notch. In that case when you hover over 3 the floating changes, the box 4 jumps to underneath 3, and 5 and 6 get pushed down a row, outside of the box.
I'm not sure exactly what's going on, in terms of why the "4" thinks "2" is lower than "3" and so it floats against that-- I assume the screen zoom is putting in rounding errors. This particular case is easily remedied by not changing the margin when hovered and giving the non-hover state a transparent border, rather than assuming a 2px border plus a 2px margin is the same as a 4px margin.
So this case had a simple fix, but the non-intuitiveness and obscurity of the error (in terms of the page zoom) gives me pause. A radical change in structure like that is just not something you would have seen in a table-as-layout solution. Just to get it out of my system, I'd like to write a few more advantages caveman-tables-for-layout have over floating divs. (Which is the fairest way of putting it, I think: people who say the argument is "tables vs css" are being grossly unfair.)
Eric Meyer, in 2009, put it pretty well:
All this is why the old “only use tables for layout” argument keeps coming up over and over: strip away the overheated rhetoric and obvious link-baiting, and you find the core of a real need. Because as powerful as CSS can be, table cells do certain things very easily that CSS makes very, very hard. Cells stretch vertically, keeping equal heights as a matter of their intrinsic nature. They stay out of each others’ way, while still being allowed to sit next to each other and use any sizing dimensions. They tie their layout to their parent elements, and vice versa.I'd love to hear if the situation has changed much since then.
I can see the advantages that floated divs can have: like in today's example I didn't need to pollute the numbered divs with table structure layout, and programmatically it would have easier to just keep on adding in divs, rather than having to coordinate the row structure. (and yeah yeah yeah, tables are for tabular data and using them for layout is the anti-thesis of proper html5 semantic thinking.)
But on the flipside, the wrapper in this example had a fixed height, in part because a container div will collapse if all its contents are floated (hence things like the clearfix hack... and don't get me started about some of the disgusting stuff I've seen to get columns to line up!)
Finally, beside my love of colspans and rowspans and what not, it's a lot easier to throw a "border" onto a misbehaving table you're trying to construct than to get a visualization of errantly interacting floating divs!
I'm swimming against the tide of design history here, I know, but until I learn of a better way to get grid-like behavior on a webpage, tables are going to be part of my web design arsenal.
(Quick followup as I ponder this a bit more: I do realize responsive design is generally a lot harder with tables, because of the mix of form and content. Most of what I really count on tables for, though, is not in the "whole page" style of layout, but for individual smaller widgets, where you really don't want things jumping around, and for them to keep their general relative positions. That's actually one of the paradoxes of responsive design: usually you want layout things to stay the same, no matter how the content changes, but with responsive design you finally want things to shift when the content seems to big for the space allotted...)
Tuesday, May 29, 2012
choking on cookies
Just a note: if you are designing an integration using iframes (like where your content shows up in an iframe on some other domain's site) you need to be aware of some pretty deep browser-specific issues involving cookies. IE will block cookies until some privacy blahblah is set; Safari has similar issues, but it's issue is about cookies on pages that haven't been directly navigated to (i.e. they've only shown up in an iframe, rather than the domain having ever been seen in the URL bar.)
There might be some further differences between the two cases; it seems like IE will allow cookies over the life of the page, at least, which is more than we got from Safari (which was a big issue because our pattern was to authenticate in one endpoint call, and then do further requests for more data) but don't quote me on that. The short of it is: you have to do a lot more QA on cross-brower issues if they involve iframes and other sites, and in fact the problem are so significant you should be thinking about them as you architect your embedded pages (and possibly doing rapid prototypes to make sure you can get to the cookies you need to when you need them.)
There might be some further differences between the two cases; it seems like IE will allow cookies over the life of the page, at least, which is more than we got from Safari (which was a big issue because our pattern was to authenticate in one endpoint call, and then do further requests for more data) but don't quote me on that. The short of it is: you have to do a lot more QA on cross-brower issues if they involve iframes and other sites, and in fact the problem are so significant you should be thinking about them as you architect your embedded pages (and possibly doing rapid prototypes to make sure you can get to the cookies you need to when you need them.)
Wednesday, May 23, 2012
got python? you got a webserver...
At Peter Cooper's How to Build a Chat Room in JavaScript in Under an Hour webinar I learned this trick: if you have python installed on your system (many OSX machines do by default), you have a cheap-and-cheerful, ready-to-go web content server:
Just go to the relevant directory and type:
or whatever port you want, and you can then go to http://localhost:8081/
(Slightly longer explanation at the Linux Journal.)
This can be especially user because some browsers are a bit weird about loading stuff from the file system, you run into odd cross-site-scripting style issues, like if you try to load a static ".json" file or what not.
By the way Peter Cooper also runs Javascript Weekly, a roundup of JavaScript news and articles. Great to finally have found a way to keep up with neat stuff in the industry...
UPDATE:
There's a variant if you want to run scripts:
python -m CGIHTTPServer 8081
It's pretty old-school; you make a cgi-bin directory under where you will run the command. Your scripts then have to start with #!/usr/bin/php or whatever, and have execute permissions.
Also I just realized (duh) that PHP has its own webserver-
php -S localhost:8000
Which avoids some pesky header issues when I was trying to run through Python CGI.
Oddly missing from that previously linked list (tho mentioned in a comment:
npx serve@latest
Just go to the relevant directory and type:
python -m SimpleHTTPServer 8081
or whatever port you want, and you can then go to http://localhost:8081/
(Slightly longer explanation at the Linux Journal.)
This can be especially user because some browsers are a bit weird about loading stuff from the file system, you run into odd cross-site-scripting style issues, like if you try to load a static ".json" file or what not.
By the way Peter Cooper also runs Javascript Weekly, a roundup of JavaScript news and articles. Great to finally have found a way to keep up with neat stuff in the industry...
UPDATE:
There's a variant if you want to run scripts:
python -m CGIHTTPServer 8081
It's pretty old-school; you make a cgi-bin directory under where you will run the command. Your scripts then have to start with #!/usr/bin/php or whatever, and have execute permissions.
Also I just realized (duh) that PHP has its own webserver-
php -S localhost:8000
UPDATE UPDATE
I was running into CORS problems running my own dev server ("Access-Control-Allow-Origin" issues). The python based solutions I googled up looked annoying, but here's another basic webserver you can use, with an argument that runs around the CORS issues:
npx http-server . -p 9999 --cors='*'
(Obviously pick your own port)
UPDATE UPDATE UPDATE
here is a a list of these static servers
UPDATE UPDATE UPDATE UPDATE
Oddly missing from that previously linked list (tho mentioned in a comment:
npx serve@latest
Thursday, May 17, 2012
the way the cookie crumbles
Today as a quick tool to help with some QA I made cookiemonster, a simple tool to go through all the cookies associated with the request and print out the cookie content.
Clearly not rocket surgery, but useful today! If you view the source of that file, you can see a little bit of odd JSON parse and stringify. We sometimes stuff JSON structures as cookies (a cheap and cheerful technique but you need to be aware that those cookies then get sent with every request for all non-CDN'd content - so don't overdo it!) and it's nice to use stringify's ability to format the content-- but a barse JSON parse and stringify would thrown exceptions for non-JSON'd data, so I catch that case and just treat it as a plain string.
slashmaze
slashmaze - source (click to redraw)
Our marketing director Gerard LaFond pointed me to an upcoming book by his co-collaborator (and Serious Games superstar) Ian Bogost... the books is called 10 PRINT CHR$(205.5+RND(1)); : GOTO 10 and that happens to be a working program for the Commodore 64 that generates a pattern very much like you see here.
I want to reiterate, processing.js is a fun tool for stuff like this (despite the lack of IE support) and http://sketchpad.cc/ is one of the easier ways of getting something up and running in a hurry.
I'm looking forward to the book! Should be a good read.
Friday, May 11, 2012
it's pronounced 'wolfen-STEEN'
So Bethesda released a playable online port of the 1992 PC classic Wolfenstein 3D - it was a great game with awesome music, the first FPS worthy of the name, and the precursor to DOOM. When Peter Cooper's JavaScript Weekly (kind of a must-read for keeping up with the whole HTML5/js/jQuery world) linked to it they mentioned
Quite the tour de force! I've seen recreations of the basic technique in minimalist programming competitions, but it's cool to see my old friend Wolf3D.
Here's one of the sprite sheets from it, the basic soldier...
At first I was going to slice this by hand to fit in this site (the original file is a horizontal row 3136 pixels across), but then I realized I could just use some CSS shuffling. (In theory I could have then baked the result into a single image, but but it was a a bit more fun this way)
And check out this cool walk through with Wolf3D creator John Carmack!
Interestingly, it doesn't use Canvas, etc, but a lot of CSS and DOM manipulation.So I took a peek with Firebug, and wow, they're right! I always wondered if you could build a game this way, and sure enough! (It's a testimonial to the cleverness of the original Wolf3D programmer John Carmack, how robust his ideas in rendering engines were). When you inspect the DOM, you can see that besides some divs for "ceiling" "floor" and "player-weapon" and the like, there's a giant pile of (mostly hidden) sprite divs, and the a big collection 3 pixel wide vertical slices. Each one of those then holds a carefully manipulated piece of a wall texture. There's a lot of manipulation of the z-index to get everything to appear in the right order as well. (the Wikiepedia article talks a bit about this technique, called "Ray Casting".
Quite the tour de force! I've seen recreations of the basic technique in minimalist programming competitions, but it's cool to see my old friend Wolf3D.
Here's one of the sprite sheets from it, the basic soldier...
And check out this cool walk through with Wolf3D creator John Carmack!
Subscribe to:
Posts (Atom)