Learn CSS from the Best Tutors
Search in
To collapse one table out of many using CSS, you can utilize the `display` property and toggle between `none` and `table` values. Here's a simple example using HTML and CSS:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
.hidden-table {
display: none;
}
</style>
<title>Collapsible Table</title>
</head>
<body>
<button onclick="toggleTable()">Toggle Table</button>
<table id="table1">
<caption>Table 1</caption>
<!-- Table content goes here -->
<tr>
<td>Row 1, Cell 1</td>
<td>Row 1, Cell 2</td>
</tr>
<!-- Add more rows and cells as needed -->
</table>
<table id="table2" class="hidden-table">
<caption>Table 2</caption>
<!-- Table content goes here -->
<tr>
<td>Row 1, Cell 1</td>
<td>Row 1, Cell 2</td>
</tr>
<!-- Add more rows and cells as needed -->
</table>
<!-- Add more tables with unique IDs and content -->
<script>
function toggleTable() {
const table2 = document.getElementById('table2');
table2.classList.toggle('hidden-table');
}
</script>
</body>
</html>
```
In this example:
- Each table has a unique ID (e.g., `table1`, `table2`).
- The `hidden-table` class is defined with `display: none;` to hide the table.
- The `toggleTable` function uses JavaScript to toggle the presence of the `hidden-table` class on the second table, making it visible or hidden.
- A button triggers the `toggleTable` function when clicked.
You can extend this example for as many tables as needed, each with a unique ID. Adjust the HTML and JavaScript accordingly based on your project requirements.
Related Questions
Why is HTML is used in Web Application?
Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com
Ask a QuestionRecommended Articles
Skills Required to Become a Front End Web...
Today, no business can exist without having its own website to interact with its customer base. Having a website is no more restricted to the big MNCs. With the advancement in technology and global business, even the small enterprises are spending on having their own websites and development teams. The person works on web...
Why Should you Learn HTML
Since the world today is ruled by the Internet, everyone desires to build a website for either business or personal interests. HTML or Hyper-text Mark-up Language is a globally standardized language which used to format web pages. By using HTML, the appearance of text, links, images and almost every part of a web page could...
Why Should you Become an IT Consultant
Information technology consultancy or Information technology consulting is a specialized field in which one can set their focus on providing advisory services to business firms on finding ways to use innovations in information technology to further their business and meet the objectives of the business. Not only does...
Make a Career in Mobile Application Programming
Almost all of us, inside the pocket, bag or on the table have a mobile phone, out of which 90% of us have a smartphone. The technology is advancing rapidly. When it comes to mobile phones, people today want much more than just making phone calls and playing games on the go. People now want instant access to all their business...
Looking for CSS Training?
Learn from the Best Tutors on UrbanPro
Are you a Tutor or Training Institute?
Join UrbanPro Today to find students near youThe best tutors for CSS Classes are on UrbanPro
The best Tutors for CSS Classes are on UrbanPro