The mystery of attributes used by column elements

Source: Internet
Author: User

In the table table element, there is a COL element (it also has a twin elder brother Colgroup Element), which is called the column element in the universal standard, and is used to define representations in certain columns in the table, and in the current and common tutorials, it is considered that the COL element can use common global properties. And align, valign, width and so on attributes (even HTML 4.1 and 5.0 specification documents, also agree that the element can use global properties), many demo also use it to illustrate how to make a table in the center of a column, right to align or change the text color of a column, In fact, in the practice of all the year round, has proved a very scary thing ... align or valign, even the color properties in the global properties are completely ineffective, this is what happened.

The usual conclusion:

In CSS 2, column elements can only use the four properties of border, background, width, and visibility, and other attributes, such as alignment and color, are not valid.

IE6, IE7, and IE8 (Q) Follow the common tutorials and you can use a variety of alignment and text-related settings.

IE9 start and now all commonly used non-IE browsers support: nth-child (n) selector, you can use this selector to implement column selection, and support all global CSS properties.

IE8 (S) has no solution (because it does not support the selector above), the alignment and color of the column cannot be uniformly changed except for the 4 CSS properties described in the first article.

and Col and colgroup elements, in addition to IE6, 7, 8 compatible, has been useless.

Why, this is why ...

From a simpler and more obvious point of view, the attributes of all elements are "inherited" in the undefined case, which is the same as their parent element attributes. The form's HTML writing is based on behavior, the cell is a child of the row, but not a column, so it does not inherit the properties of the column.

From a more fundamental point of view, it is the working mode of CSS decided. All the performance of the page is calculated and rendered by CSS, and the basic way of working with CSS follows these steps:

Parsing style sheets and documents

For each element in the document:

Decide which CSS rule to apply.

Use these rules to make CSS cascading.

If the result of the cascade is the keyword "inherit" (or the inherited property has no specified value), Inherit

Perform calculations (Turn ' em ' into ' px ', and so on). In CSS 2.1, the getComputedStyle () Dom method is responsible for returning these values.

At this point, all properties of each element have a value.

Arrange document layout

Drawing documents

In this order of work, because the column elements are display:table-column and the cell elements are Display:table-cell, the specific relationship between them is to be confirmed in the third step, because you need to compute a cell across a few columns or rows, To determine how many columns a cell is. And before that, that is the second step, the attribute value of each element has been calculated! But you don't know which cell is the first column, so you can't know the value of the column.

Then I did a very boring demo, using the CSS 3 selector mentioned above, select all the cells of the even sequence to become blue, and make all the third column cells yellow. The cells in n rows n columns are then merged (that is, the first cell in the first row occupies 3 cells, the second cell in the second row occupies 3 cells, and so on). The results are as follows:

Because column merging is done on the cell, and the selector's nature is chosen by row rather than column, the result becomes the above (not being able to visually render a column vertically).

That said, but in the form of the layout so many years out of today, in the form can finally return to its original application of the purpose of today, this wonderful layout of the table should also be very few.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.