How to Create Vertical Tables in HTML?

DDD
Release: 2024-10-24 11:18:29
Original
798 people have browsed it

How to Create Vertical Tables in HTML?

Vertical Table Rendering in HTML

Traditionally, HTML tables display data horizontally with rows across the page. However, there are instances where you may require vertical tables with rows displayed vertically, with headers positioned on the left.

To achieve this, CSS can be employed to modify the table's display properties:

tr { display: block; float: left; }
th, td { display: block; }
Copy after login

This CSS will cause the table rows ( elements) to behave like columns, displayed vertically. Both table headers () and table data () will also be displayed vertically.

However, it's important to note that this approach eliminates the table behavior, making it unsuitable for typical table operations. To resolve this, you can employ CSS border collapse:

/* border-collapse */
tr>* { border-top: 0; }
tr:not(:first-child)>* { border-left: 0; }
Copy after login

This CSS ensures that the borders only appear between table cells (not around the entire column), giving the appearance of a properly bordered table.

By implementing these CSS rules, you can create vertical tables in HTML, providing greater flexibility in presenting your data.

The above is the detailed content of How to Create Vertical Tables in HTML?. For more information, please follow other related articles on the PHP Chinese website!

source:php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!