Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create a responsive table with CSS?
To create a responsive table with CSS, the code is as follows −
Example
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body{
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
div{
overflow-x: auto;
}
table {
border-collapse: collapse;
border-spacing: 0;
width: 100%;
border: 1px solid rgb(0, 0, 0);
}
th, td {
text-align: left;
padding: 8px;
}
tr:nth-child(even){background-color: #f2f2f2}
</style>
</head>
<body>
<h1>Responsive Table Example</h1>
<div>
<table>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>marks</th>
<th>marks</th>
<th>marks</th>
<th>marks</th>
<th>marks</th>
<th>marks</th>
<th>marks</th>
<th>marks</th>
<th>marks</th>
<th>marks</th>
</tr>
<tr>
<td>JACK</td>
<td>ROY</td>
<td>50</td>
<td>60</td>
<td>10</td>
<td>20</td>
<td>40</td>
<td>50</td>
<td>10</td>
<td>20</td>
<td>30</td>
<td>40</td>
</tr>
<tr>
<td>Evelyn</td>
<td>Monroe</td>
<td>24</td>
<td>14</td>
<td>22</td>
<td>44</td>
<td>55</td>
<td>44</td>
<td>11</td>
<td>55</td>
<td>22</td>
<td>33</td>
</tr>
<tr>
<td>Joe</td>
<td>Anderson</td>
<td>54</td>
<td>22</td>
<td>99</td>
<td>55</td>
<td>91</td>
<td>61</td>
<td>81</td>
<td>11</td>
<td>22</td>
<td>55</td>
</tr>
</table>
</div>
</body>
</html>
Output
The above code will produce the following output −

On resizing the window the scrollbar will appear as follows −

Advertisements