HTML Forms: Guide to Creating Responsive and Mobile-Friendly Forms
HTML tables are used to display table data on web pages. They are great for displaying information in an organized way and can be styled using CSS to match the look and style of a website. This tutorial will cover the basics of creating HTML tables and adding styles to make them responsive and mobile-friendly.
Key Points
- HTML tables are powerful tools for displaying table data on web pages, and can create tables, rows, and cells using
<table>, <code><tr> and <code><td> tags. <li>CSS properties such as borders, fills, background colors, and media queries for different screen sizes can be implemented to make HTML tables responsive and mobile-friendly. </li> <li> Accessibility of HTML tables can be enhanced by adding titles with <code><caption></caption>
tags and summaries with<summary></summary>
tags that provide descriptions and summaries for non-visual users.
Create HTML table
To create an HTML table, we need to use the <table> tag. Within the <code><table> tags, we need to create one or more <code><tr> tags that define each row of the table. Within each <code><tr> tag, we can create one or more <code><td> tags that define the cells of the table. Here is an example of a basic HTML table:
<pre class='brush:php;toolbar:false;'><table>
<tr>
<td>單元格1</td>
<td>單元格2</td>
<td>單元格3</td>
</tr>
<tr>
<td>單元格4</td>
<td>單元格5</td>
<td>單元格6</td>
</tr>
</table></pre>
<p> This creates a table with two rows and three columns, each cell showing its contents. </p>
<p><a href="http://miracleart.cn/link/a382db0a40615cdbe363ae0b4b2eb262">View CodePen example</a> (Replace with the actual CodePen link, if present)</p>
<h2 id="Add-rows-and-columns">Add rows and columns</h2>
<p>To add a new row to the table, we just need to create a new <code><tr>
tag. To add a new cell to a table, we can create a new <tr>
tag within the existing <td>
tag. Here is an example table with four rows and three columns:
<table> <tr> <td>單元格1</td> <td>單元格2</td> <td>單元格3</td> </tr> <tr> <td>單元格4</td> <td>單元格5</td> <td>單元格6</td> </tr> <tr> <td>單元格7</td> <td>單元格8</td> <td>單元格9</td> </tr> <tr> <td>單元格10</td> <td>單元格11</td> <td>單元格12</td> </tr> </table>
This will create a table with four rows and three columns.
Set HTML table style
You can use CSS to style HTML tables to change their appearance. Some of the most common CSS properties used to style tables include borders, fills, and background colors. Here is an example of how to style a table using borders and background colors:
table { border: 1px solid black; background-color: #f2f2f2; } td { padding: 8px; }
This will create a table with black borders and light gray background colors, each cell filled with 8 pixels.
View CodePen example (Replace with the actual CodePen link, if present)
Create responsive and mobile-friendly forms
One of the challenges of using HTML tables is to make them responsive and mobile-friendly. One way to achieve this is to use CSS to adjust the layout of the table according to the screen size. One way is to use the display
attribute to change the layout of the table from a fixed layout to a responsive layout. This can use media queries to locate specific screen sizes. Here is an example of how to make a table responsive:
<table> <tr> <td>單元格1</td> <td>單元格2</td> <td>單元格3</td> </tr> <tr> <td>單元格4</td> <td>單元格5</td> <td>單元格6</td> </tr> </table>
When the screen width is less than 600 pixels, this changes the table layout from fixed layout to responsive layout.
View CodePen example (Replace with the actual CodePen link, if present)
Add Title and Summary
Another important aspect of using HTML tables is to make them accessible to non-visual users. One way is to add a title and summary to the table. The <caption>
tag can be used to add a title to a table that describes the content of the table. Here is an example of how to add a title to a table:
<table> <tr> <td>單元格1</td> <td>單元格2</td> <td>單元格3</td> </tr> <tr> <td>單元格4</td> <td>單元格5</td> <td>單元格6</td> </tr> <tr> <td>單元格7</td> <td>單元格8</td> <td>單元格9</td> </tr> <tr> <td>單元格10</td> <td>單元格11</td> <td>單元格12</td> </tr> </table>
This will add a title to the table that shows sales by month. <summary>
tags can be used to provide summary of forms for screen readers and other assistive technologies. Here is an example of how to add a summary to a table:
table { border: 1px solid black; background-color: #f2f2f2; } td { padding: 8px; }
This will provide a summary of the table for screen readers and other assistive technologies, indicating that it shows sales by month.
Is it not good to use the form?
No! Tables are an important part of HTML. They are essential for displaying tabular data in a semantic and accessible way. In the early days of the World Wide Web, before CSS came into being, tables provided a way to layout web design, but this was not its intended purpose. Thankfully, those days have passed long (well, mostly, but for some email clients!), we can now focus on how HTML tables really — and extremely important in displaying data ——The function.
Conclusion
HTML tables are powerful tools for displaying table data on web pages. With CSS, you can style the table to match the look and style of a website and make it responsive and mobile-friendly to users on different devices. Adding titles and summary to a table can help improve accessibility for users with disabilities. Using these techniques, we can create effective forms that are both visually attractive and powerful.
HTML Form FAQ (FAQ)
How to merge cells in HTML table?
Cells in HTML tables can be merged using the "colspan" and "rowspan" properties. The "colspan" property allows cells to span multiple columns, and the "rowspan" property allows cells to span multiple rows. For example, if you want to make a cell span two columns, you can use the following code: <td colspan="2">內(nèi)容</td>
. Similarly, if you want to make a cell span two rows, you can use the following code: <td rowspan="2">內(nèi)容</td>
.
How to add borders to HTML tables?
You can use the "border" property in the <table> tag to add borders to HTML tables. For example, <code><table border="1"> will create a bordered table. However, this property is not supported in HTML5. Instead, you can add borders using CSS. For example, you can add borders using the following code: <code>table, th, td {border: 1px solid black;}
.
How to style HTML tables using CSS?
CSS can be used to style HTML tables by positioning "table", "th" and "td" elements. For example, you can change the background color of the table title (th) and table data (td) using the following code: th {background-color: #f2f2f2;} td {background-color: #ffffff;}
. You can also add fills, change text colors, and more.
How to make HTML tables responsive?
CSS can be used to make HTML tables responsive. You can use the "overflow" property to add scroll bars to the table when the width of the table is less than the screen size. For example, you can use the following code to make a table responsive: table {width: 100%; overflow: auto;}
.
How to add a title to an HTML table?
You can use the "caption" tag to add a title to an HTML table. The "caption" tag must be inserted after the You can use the "text-align" property in CSS to align text in HTML tables. For example, you can use the following code to center the text: You can add background color to HTML tables using the "background-color" property in CSS. For example, you can add background color to a table using the following code: You can use the ":hover" pseudo-class in CSS to add a hover effect to HTML tables. For example, you can use the following code to change the background color of a table row when the mouse pointer hovers over a table row: You can use the "overflow" property in CSS to add scrollbars to HTML tables. For example, you can add a scrollbar to a table using the following code: You can add alternating row colors to HTML tables using the ":nth-child" pseudo-class in CSS. For example, you can add alternating line colors using the following code: tag. For example,
.
<caption>表格標(biāo)題
How to align text in HTML table?
th, td {text-align: center;}
. How to add background color to HTML table?
table {background-color: #f2f2f2;}
. How to add hover effect to HTML table?
tr:hover {background-color: #f5f5f5;}
. How to add scrollbars to HTML tables?
table {overflow: auto;}
. How to add alternating row colors to HTML tables?
tr:nth-child(even) {background-color: #f2f2f2;}
.
The above is the detailed content of Getting Started with HTML Tables. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

When developing learning platforms similar to Udemy, the focus isn't only on content quality. Just as important is how that content is delivered. This is because modern educational platforms rely on media that is accessible, fast, and easy to digest.

In a world where online trust is non-negotiable, SSL certificates have become essential for every website. The market size of SSL certification was valued at USD 5.6 Billion in 2024 and is still growing strongly, fueled by surging e-commerce business

A payment gateway is a crucial component of the payment process, enabling businesses to accept payments online. It acts as a bridge between the customer and the merchant, securely transferring payment information and facilitating transactions. For

In what seems like yet another setback for a domain where we believed humans would always surpass machines, researchers now propose that AI comprehends emotions better than we do.Researchers have discovered that artificial intelligence demonstrates a

A new artificial intelligence (AI) model has demonstrated the ability to predict major weather events more quickly and with greater precision than several of the most widely used global forecasting systems.This model, named Aurora, has been trained u

Like it or not, artificial intelligence has become part of daily life. Many devices — including electric razors and toothbrushes — have become AI-powered," using machine learning algorithms to track how a person uses the device, how the devi

Artificial intelligence (AI) began as a quest to simulate the human brain.Is it now in the process of transforming the human brain's role in daily life?The Industrial Revolution reduced reliance on manual labor. As someone who researches the applicat

The more precisely we attempt to make AI models function, the greater their carbon emissions become — with certain prompts generating up to 50 times more carbon dioxide than others, according to a recent study.Reasoning models like Anthropic's Claude
