Why use tables to structure your layout?

后端 未结 14 699
孤城傲影
孤城傲影 2020-12-23 23:02

Looking at the source code for Stack Overflow, I noticed they have used tables and inline CSS quite a bit, also something I found odd was use of inline table attribute forma

相关标签:
14条回答
  • 2020-12-23 23:25

    CSS is great and can really simplify your markup, however, sometimes aligning content with tables is just easier and more reliable. Also for code generated dynamically some of the pain points for non-CSS based styling are less bad. Specifically, since you are dynamically, creating the markup you can re-factor the styling elements in the functional code.

    As for the in-line styles, I often use these when I'm building a page and then try to re-factor them into an external sheet later. This makes it a little easier for my testing (no need to do a hard refresh) and changes are in one file instead of two.

    0 讨论(0)
  • 2020-12-23 23:29

    Because Internet Explorer does not support the display:table CSS property, which is what provides the grid-like layout model (equivalent to how html tables are rendered). The grid-model is the simplest and most flexible way to model many layouts.

    So you have three choices, none of them attractive:

    • sacrifice support for Internet Explorer (all other modern browsers supports display:table property, which have been part of the CSS2 standard for more than a decade)
    • use cumbersome CSS workarounds which are costly and hard to maintain.
    • sacrifice semantic purity and use TABLE-elements.

    SO chose the last option, probably because they think support for Internet Explorer users is more important than support for disabled users, and because they wanted something that was quick to develop and simple to maintain.

    0 讨论(0)
  • 2020-12-23 23:31

    My thougths would be they went with table because (apart from the argument table vs css)

    • They needed to get the functionality get out rolled quickly to have an opinion
    • After all this is just the public beta.
    • They were experimenting with ASP.NET MVC more and layout issues less
    • SO is all about programming questions and answers and at the end that what matters.
    • SO is all about recognizing the contributors by rewarding points and badges which it does quite decently (this may also be a controversial topic).
    • and so on....
    0 讨论(0)
  • 2020-12-23 23:33

    Jeff and his team were getting it done quick and dirty. This was a very quick development cycle, without the time to refactor out much of the clutter.

    And face it - unless you are an expert, CSS is time consuming for table structures.

    Inline styles and included css are just a sign they were trying to get it done, not worrying (at least for the first iteration) about the "right" way of doing it. The right way was whatever worked and got it done fast.

    0 讨论(0)
  • 2020-12-23 23:36

    Tables vs. Divs is a pointless holy war.

    There are specific issues with using tables in particular ways for layout that can cause problems. One of these is building an entire site layout in a single table in order to handle margins and placement -- because of the way tables are rendered this frequently means a website will not render progressively by the browser engine as the content downloads, and can only be rendered after the entire thing has been received. For a large page or slow modem user, they may be staring at a blank page for quite a while, which is a "Bad Thing". Never mind a lot of the inconsistencies in table rendering in the mozilla/ie5 generation of browsers that made consistent cross-browser table layouts somewhat painful, especially with images in the cells.

    Supporters of the pure div path like to talk about content vs. presentation, because in theory HTML 4.01 is pure content, all of it meaningful. The divs provide meaningful organizational structure in an abstract sense, which is then given presentation exclusively by CSS. In these arguments, tables are valid only if being used to contain actual tabular data. Of course, this ignores the fact that for any sufficiently complex layout, there are almost always quite a few empty divs floating around simply to support the necessary hooks for presentation CSS, breaking the first level of this abstraction. Once this abstraction is broken, there's no law stating that, when your layout simply requires a presentation hook in the HTML that has no meaningful content, a div is somehow more appropriate than a table. If you are stuck with the choice of a meaningless div or a meaningless table in order to make your layout work, choose whichever is easier.

    In the end, it's about being aware of the limitations in all methods and using the one that is most appropriate. There are many cases where using a table is simply easier than setting up a pointless (i.e. not-content-meaningful) array of divs, and the table rendering limitations don't apply. If the table is small and represents a minor chunk of the interior content, the rendering delay is not relevant.

    0 讨论(0)
  • 2020-12-23 23:37

    SO was probably written by programmers, not web developers.

    0 讨论(0)
提交回复
热议问题