Show HN: A simple lightweight CSS grid, not a bloated framework
thisisdallas.github.com
thisisdallas.github.com
So dear HN, please help me convince myself that CSS and its hacks are superior than tables.
My mind's first objection: "to make a simple two column layout that would typically take a few lines with the table tag and be compatible across browsers. The same thing in css would require the use of an open-source grid or bunch of hacks and testing--taking much more effort than the table tag". How do I respond to this objection?
A CSS layout is better than a table-based layout, due to:
- Maintenance: Maintaining or redesigning a table-based layout is very cumbersome, especially with nested tables, because:
- Seperation of content and design: The content has to be changed, to change the design, and that is not a nice workflow.
- Accessibility: CSS designs allow much better for a user-specified stylesheet. Resize the browserwindow and tables keep sticking out, where with CSS you can change the order (put columns under each other). Screenreaders behave in a specific way for tables, they try to read the "summary", or they assume the table holds tabular data, reading it row by row. A table lay-out can therefor confuse.
- SEO: CSS designs make content stacking possible, tables only allow to put the content in the order of the table cells. Webmaster guidelines ask you to check for correct use of HTML, which tables for lay-out isn't:
- Semantics/standards: Use tables for tabular data. Provide a summary and table header if relevant and possible. Using tables for lay-out semantically turns your entire page into tabular data.
- Pagespeed: CSS allows for faster, progressive rendering. HTML tables take their width from the resulting table-cell: Content will jump around while rendering or some browsers even show a blank table before all content is loaded.
A CSS framework like this is far from hacky. Using tables for layout, because CSS is deemed too complex, now that is hacky.
Also, don't forget support for "display: table" is in near all modern browsers. If you really want to design lay-out like you are using tables, it is possible with CSS too.
For responsive designs, much more is possible with CSS than a 100% width table. You can't just slap a few lines of table and expect it to work well on an ipad.
<div class="table">
<div class="tr">
<div class="td">...</div>
<div class="td">...</div>
</div>
</div>
remind me of tables too. They tend to add a few unneeded or non-semantic div's. And they don't really separate content and design. It is a lesser-of-two-evils thing for me, because sometimes grids/frameworks can save me a lot of time. Ideally you'd use semantic-sounding classnames and don't include unnecessary div's.We're finally getting some progress on constraint-based layout in the form of the flexible box model (great modern browser support), and CSS grid layout, which surprisingly enough is coming from MS.
I agree, the fact that it's almost 2013 and we're still wasting valuable brainpower on f*ing around with what should be trivial layouts is a bit of a shame.
[1] - http://www.cs.washington.edu/research/constraints/solvers/ui...
Anyway, use compass sass or less. Use frameworks.
A table for layout is semantically meaningless. If you view a webpage as vaguely structured data, then using a table for layout is akin to using a String to represent an enumerated value. Sure, you can do it and it will work, but you're diminishing our ability to reason about your data and access it with our tools.
If I'm working in a codebase and wanted to see where we're presenting tabular data to the user and we're using tables for layout, I now cannot know which kind of table I'm looking at: presentational or structured.
If a user is using a screenreader to access a site, the screenreader will see the table and read it line-by-line. In a presentational case, that means <tr> by <tr>. This is meaningless to a non-sighted person and lowers the usability of the site.
Tables don't respond to CSS as well as other block elements. Try setting the width or height of an individual cell in relation to the container. You'll likely end up using spanning columns or spanning rows or setting the width using table attributes. Now we're breaking the abstraction between HTML (structured data, our model) and CSS (presentation, our view). We're now scattering view-related semantics inside of our model.
Are those good enough reasons?
This is just the first reason I can think about right now.
But, I think tables are best for tabular data. CSS is best for layouts. With CSS you can have your layout more easily adjust for different browsers, mobile, etc. with tables you're locking yourself into one layout.
Also though using styles - the CSS can tend to be a bit more code, but the HTML can wind up looking very clean.
The web started a move to being all about semantics, machine readability and interpretation of pages by robots (like Googlebot). Personally I threw my lot in with XHTML and started moving to XFN and other microformats.
One of the big things with tables was screenreaders. Screenreaders assume a table is tabular data and treat it as such leading to a terrible UX. Where I am, a business that doesn't make reasonable changes to accommodate disabled users is acting unlawfully.
Screenreaders basically amplified the error of using semantic markup where non-functional style is intended. Semantics was the in thing for a while and separation of function and style pushed people towards using pure [X|]HTML with no extraneous tags and all styling performed outside the markup via CSS files. Tables for tabular data only.
CSS promised to bring table-layouts to 'display:' in CSS1 but IIRC MSIE put the kibosh on that one [that's en-gb euphemism for 'stopped it'] and indeed it's only just become fully supported in IE9 I think.
Markup philoshopies aside it was a real bitch trying to edit tables or change layout with tables without decent visual layout tools. You'd have a page-table (for body centering), then that would have a table for a main grid, then you'd have a table for the visual header, a table for the menu, a table for the ads column(s), tables for the footers, tables to put pull out quotes in, tables for aligning images. All those tables made page markup significant at a time when home users didn't have ADSL connection yet.
You'd end up with nests of tables easily 10 deep on some sites and working out in the markup what was happening in such a site was a nightmare. In contrast a well CSS formatted page is (was?) slim, the content is simple and changing layout is just a matter of altering the CSS and not re-writing the whole page.
It became a point of pride for many to avoid frames, a way to show one knows ones game. For a while it seemed that as no really needs to wrangle with IE6 all the fun would have gone out of CSS layout ... but then we got iPad and a million different android resolutions to worry about and so again there is pressure to use liquid responsive layouts where in the interim things have gotten very much focussed on pixel-perfect presentation.
That all said I was having the same thought the other day - that CSS grids are starting to look a bit messy and that I'm ready for the next iteration.
It's always good to have a template to start from like this, but I don't see it being much different than an on-the-fly one that I would throw together myself if I'm not using a framework.
That's actually why I created this grid, to fit a specfic project of mine. I am picky and wanted something that I couldn't already find so I decided to build one and throw it up on github.
Edit any of the H3 elements in any of the gray rows and simulate a tooltip:
<h3>col-1-1</h3>
Replace it in Firebug with a basic tooltip:
<h3 style="position:relative"> col-1-2 <span style="border:1px solid blue;background:yellow;display:block;position:absolute;width:300px;height:50px;left:0;top:-55px">Hi there</span> </h3>
The tooltips get cut off. :(
User guide: http://yuilibrary.com/yui/docs/cssgrids/ Code: https://github.com/yui/yui3/blob/master/build/cssgrids/grids...
Why did you decide to go with ".col-1-2" over something like (foundation's) ".one.column"?
.col-2-12 & col-10-12
In your example, the first section would take 2 columns out of twelve. The second section takes the remaining 10 columns.
Or, col-3-12 & col-9-12; first section would take 3 columns out of twelve and the second takes the remaining nine.
What I'm curious about is if doing something like this: col-2-12 & col-8-12. But I'm too lazy to download the css to see for myself.
Also, what made you choose to go fluid instead of fixed?
Also, would love feedback on a project I've been working on: http://wail.es/opendaws/ | HN thread: http://news.ycombinator.com/item?id=4669809
One suggestion - use HTML5 semantic tags (header, section, etc) in your example page and code snippets. Too many divs scattered everywhere makes it a bit difficult to read.
> perfect on IE8
> use HTML5 semantic tags (header, section, etc)
You can only have two of the three things that you have on your wishlist. IE8 doesn't know how to apply CSS to HTML5 tags. This is typically fixed with html5shiv, a JavaScript library. But including html5shiv would make this grid less simple and less lightweight.
Here's a snippet I've used on a number of production sites: https://gist.github.com/3915474
Edit: you can probably just change margin-left to left and create the same steam effect that is offscreen when the browser is too narrow
Deleted comment
I'd actually say to stay away from them until you've been doing front-end for awhile as the non-semantic naming conventions are not something beginners should be using.
I'm sure you could adjust positions with specificity, but in my opinion, that goes against a Grid Frameworks purpose.
img { max-height: 100%; max-width: 100%; min-width: 400px; min-height: 300px; }
http://jsfiddle.net/N8GKd/ -- resize the window.
and then the jsfiddle link provided by fourstar.