តារាង (table) គឺជា element ដ៏សំខាន់បំផុត នៅក្នុងការបង្ហាញទិន្នន័យផ្សេងៗនៅលើទំព័រ HTML ។ ហើយការបង្កើតតារាង ទាមទារចាំបាច់អោយយើងប្រើប្រាស់ភាសា HTML សំរាប់បង្កើតគ្រោងឆ្អឹងនៃតារាង និងភាសា CSS ក្នុងការរចនាតារាងនេះ អោយចេញជារូបរាងនិងមានលក្ខណៈទៅតាមអ្វីដែលយើងចង់បាន។ ពិនិត្យកម្មវិធីខាងក្រោមនេះ៖
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <title>Styling Table</title> <style> table, th, td { border: 1px solid black; } </style> </head> <body>Add a border to a table:
<table> <tr> <th>Firstname</th> <th>Lastname</th> </tr> <tr> <td>Peter</td> <td>Griffin</td> </tr> <tr> <td>Lois</td> <td>Griffin</td> </tr> </table> </body> </html>
Add a border to a table:
Firstname | Lastname |
---|---|
Peter | Griffin |
Lois | Griffin |
បន្ទាប់មកទៀត បើសិនជាយើងចង់អោយតារាងរបស់យើងមានខ្សែវ័ណ្ឌតែមួយ យើងត្រូវផ្តល់តំលៃអោយទៅ property border-callapse ជា collapse ដោយធ្វើដូចខាងក្រោមនេះ៖
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <title>Styling Table</title> <style> table, th, td { border: 1px solid black; border-collapse: collapse; } </style> </head> <body>Add a border to a table:
<table> <tr> <th>Firstname</th> <th>Lastname</th> </tr> <tr> <td>Peter</td> <td>Griffin</td> </tr> <tr> <td>Lois</td> <td>Griffin</td> </tr> </table> </body> </html>
Add a border to a table:
Firstname | Lastname |
---|---|
Peter | Griffin |
Lois | Griffin |
បន្ទាប់មកទៀត យើងអាចកំណត់ប្រវែងទទឹងរបស់តារាងទាំងមូល និងប្រវែងទទឹងរបសក្រឡានិមួយៗបាន ដោយធ្វើដូចខាងក្រោមនេះ៖
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <title>Styling Table</title> <style> table, th, td { border: 1px solid black; border-collapse: collapse; } table { width: 100%; } th { width: 50%; } </style> </head> <body>Add a border to a table:
<table> <tr> <th>Firstname</th> <th>Lastname</th> </tr> <tr> <td>Peter</td> <td>Griffin</td> </tr> <tr> <td>Lois</td> <td>Griffin</td> </tr> </table> </body> </html>
Add a border to a table:
Firstname | Lastname |
---|---|
Peter | Griffin |
Lois | Griffin |
បន្ទាប់មកទៀត យើងអាចដាក់ពណ៌អោយក្បាលតារាង និងធ្វើអោយមានគំលាតខាងក្នុងក្រឡានិមួយៗនៅក្នុងតារាង ដោយធ្វើដូចខាងក្រោមនេះ៖
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <title>Styling Table</title> <style> table, th, td { border: 1px solid black; border-collapse: collapse; } table { width: 100%; } th { width: 50%; } th, td { padding: 8px; } th { background-color: #4CAF50; color: white; } tr:nth-child(even) {background-color: #f2f2f2;} </style> </head> <body>Add a border to a table:
<table> <tr> <th>Firstname</th> <th>Lastname</th> </tr> <tr> <td>Peter</td> <td>Griffin</td> </tr> <tr> <td>Lois</td> <td>Griffin</td> </tr> </table> </body> </html>
Add a border to a table:
Firstname | Lastname |
---|---|
Peter | Griffin |
Lois | Griffin |