DeveloperBreeze

To automatically add Tailwind CSS and jQuery classes to any table on a page, use the following approach.


1. Include jQuery and Tailwind CSS

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Table Styling with Tailwind CSS</title>
    <!-- Include Tailwind CSS -->
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
    <!-- Include jQuery -->
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>

<!-- Example table -->
<table>
    <thead>
        <tr>
            <th>Header 1</th>
            <th>Header 2</th>
            <th>Header 3</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Data 1</td>
            <td>Data 2</td>
            <td>Data 3</td>
        </tr>
        <tr>
            <td>Data 4</td>
            <td>Data 5</td>
            <td>Data 6</td>
        </tr>
    </tbody>
</table>

<!-- jQuery script to apply classes -->
<script>
    $(document).ready(function() {
        $('table').each(function() {
            $(this).addClass('min-w-full bg-white border border-gray-200');
            $(this).find('thead').addClass('bg-gray-50');
            $(this).find('th').addClass('px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider border-b border-gray-200');
            $(this).find('tbody').addClass('bg-white divide-y divide-gray-200');
            $(this).find('tr').addClass('hover:bg-gray-100');
            $(this).find('td').addClass('px-6 py-4 whitespace-nowrap text-sm text-gray-900');
        });
    });
</script>

</body>
</html>

Explanation

Tailwind CSS:

The <link> tag includes Tailwind CSS via CDN, enabling use of utility classes.

jQuery:

The <script> tag includes jQuery, which is used to apply classes dynamically to the table elements.

jQuery Script Behavior:

  • Runs when the document is ready.
  • Selects all <table> elements.
  • Applies Tailwind CSS classes to each table and its child elements.

Tailwind Classes Applied

table:

  • min-w-full: Full-width table.
  • bg-white: White background.
  • border border-gray-200: Adds border.

thead:

  • bg-gray-50: Light gray header background.

th:

  • px-6 py-3: Padding.
  • text-left text-xs font-medium text-gray-500 uppercase tracking-wider: Header text styling.
  • border-b border-gray-200: Bottom border.

tbody:

  • bg-white divide-y divide-gray-200: White background and row separators.

tr:

  • hover:bg-gray-100: Hover effect.

td:

  • px-6 py-4 whitespace-nowrap text-sm text-gray-900: Data cell styling.

Feel free to adjust the class names to fit your design requirements.

Continue Reading

Discover more amazing content handpicked just for you

10 Insanely Game-Changing Hacks for Web Developers in 2025: Code Smarter, Not Harder
Article

10 Insanely Game-Changing Hacks for Web Developers in 2025: Code Smarter, Not Harder

The Jamstack architecture (JavaScript, APIs, and Markup) allows you to build fast, secure, and scalable web apps. Pre-build your pages for speed, then enhance them with dynamic API calls when needed.

Challenge: Build a personal blog with a static site generator like Gatsby or Next.js, then spice it up with real-time data from an API.

Feb 11, 2025
Read More
Article

Mastering Modern Web Development: Trends, Tools, and Tutorials for 2025 and Beyond

Containerization and orchestration tools are essential for deploying modern web applications efficiently. Docker allows you to create lightweight, portable containers, while Kubernetes manages container clusters.

  • Why They Matter: They ensure consistency across development, testing, and production environments, and facilitate seamless scaling.
  • Getting Started: Learn by containerizing a small web app and deploying it on a local Kubernetes cluster using Minikube or Docker Desktop.

Feb 11, 2025
Read More
Tutorial
php

Building a Laravel Application with Vue.js for Dynamic Interfaces

Add the following configuration:

   import { defineConfig } from 'vite';
   import laravel from 'laravel-vite-plugin';
   import vue from '@vitejs/plugin-vue';

   export default defineConfig({
       plugins: [
           laravel({
               input: ['resources/css/app.css', 'resources/js/app.js'],
               refresh: true,
           }),
           vue(),
       ],
       resolve: {
           alias: {
               vue: 'vue/dist/vue.esm-bundler.js', // Ensures runtime template compilation works
           },
       },
   });

Nov 16, 2024
Read More
Code
javascript

Dynamic and Responsive DataTable with Server-Side Processing and Custom Styling

  • The columns array specifies how data fields (e.g., username, points) map to table columns.
  • language.emptyTable: Custom message displayed when no data is available.

Oct 24, 2024
Read More
Article

Integrating Flowbite with Tailwind CSS: A Step-by-Step Tutorial

Open your terminal or command prompt and create a new directory for your project:

   mkdir tailwind-flowbite-project
   cd tailwind-flowbite-project

Oct 24, 2024
Read More
Article

Google Chrome vs. Chromium: Understanding the Key Differences

One of the most noticeable differences between the two browsers lies in their branding and user interface (UI). Google Chrome boasts a sleek and polished UI with Google's distinctive design language, featuring elements like the colorful Chrome logo, smooth animations, and a streamlined interface that emphasizes ease of use. This branding extends to features such as Google account integration, allowing users to sync bookmarks, history, and settings across devices seamlessly.

Chromium, on the other hand, maintains a more minimalistic and utilitarian UI. While it shares the basic layout and functionality with Chrome, Chromium lacks some of the refined aesthetic touches and proprietary design elements found in Chrome. This barebones approach appeals to users who prefer a lightweight browser without additional branding or who wish to customize the UI extensively.

Oct 24, 2024
Read More
Cheatsheet

Best Tools for Generating Backgrounds Patterns for Your Website

You can visit the individual websites to try out their features and start generating stunning, professional patterns for free.

Oct 21, 2024
Read More
Tutorial
css

CSS Variables and Custom Properties: Dynamic Theming and Beyond

You can create interactive UI elements, such as sliders, that update CSS variables in real-time.

const slider = document.getElementById('slider');

slider.addEventListener('input', (e) => {
    document.documentElement.style.setProperty('--spacing-medium', `${e.target.value}px`);
});

Sep 05, 2024
Read More
Tutorial
css

Advanced Flexbox Techniques: Creating Responsive and Adaptive Designs

.gallery {
    display: flex;
    flex-wrap: wrap;
}

.image {
    flex: 1 1 300px;
    margin: 5px;
}

Images will resize and wrap into rows based on available screen width.

Sep 05, 2024
Read More
Tutorial
javascript

Creating a Dropdown Menu with JavaScript

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Dropdown Menu</title>
  <link rel="stylesheet" href="styles.css">
</head>
<body>
  <nav class="navbar">
    <ul class="menu">
      <li class="menu-item">
        <a href="#">Home</a>
      </li>
      <li class="menu-item dropdown">
        <a href="#" class="dropdown-toggle">Services</a>
        <ul class="dropdown-menu">
          <li><a href="#">Web Development</a></li>
          <li><a href="#">App Development</a></li>
          <li><a href="#">SEO Optimization</a></li>
        </ul>
      </li>
      <li class="menu-item">
        <a href="#">Contact</a>
      </li>
    </ul>
  </nav>
  <script src="script.js"></script>
</body>
</html>

Next, we’ll style the menu using CSS. We’ll start by styling the basic menu and then hide the dropdown menu by default.

Sep 02, 2024
Read More
Cheatsheet

Comprehensive React Libraries Cheatsheet

No preview available for this content.

Aug 21, 2024
Read More
Cheatsheet

Responsive Design Frameworks Cheatsheet

  • Clean, modern look following Material Design.
  • Easy to use for rapid prototyping.
  • Less flexible than Tailwind CSS.
  • Heavier, may impact performance.

Aug 21, 2024
Read More
Cheatsheet

Ultimate Front-End Development Design Tips Cheatsheet: Essential Pro Tips for Mastering Web Design

This cheatsheet provides a comprehensive overview of design principles, tips, and best practices essential for becoming a great front-end developer. By mastering these aspects, you can create visually appealing, user-friendly, and accessible websites that provide an outstanding user experience across all devices and browsers.

Aug 21, 2024
Read More
Cheatsheet

Front-End Development Tools and Libraries Cheatsheet

No preview available for this content.

Aug 21, 2024
Read More
Cheatsheet
javascript css +1

Building a Chrome Extension: A Step-by-Step Tutorial

  • Use chrome://extensions/ to inspect your extension and check for any errors.
  • Use Chrome DevTools to debug your extension's popup and content scripts.
  • Add more features, such as saving the user's color preference.
  • Integrate with APIs to fetch data or interact with web services.
  • Add options to customize the extension via an options page.

Aug 20, 2024
Read More
Cheatsheet
javascript

React Performance Optimization Cheatsheet: Hooks, Memoization, and Lazy Loading

This ensures that the Fibonacci number is only recalculated when num changes, improving performance.

Lazy loading is a technique that delays the loading of non-critical resources until they are needed, which improves the initial load time of your application.

Aug 20, 2024
Read More
Tutorial
python

Optimizing HTML Delivery in Flask with Minification and Compression

  • Cache-Control: public, max-age=3600: Instructs the browser to cache the HTML content for 3600 seconds (1 hour), reducing the number of requests made to the server.

After minifying your HTML, you can further reduce its size by compressing it with gzip. This can significantly decrease the amount of data transferred over the network.

Aug 20, 2024
Read More
Tutorial
javascript nodejs

Building a React Application with Vite and Tailwind CSS

npm install -D tailwindcss postcss autoprefixer

Next, generate the tailwind.config.js and postcss.config.js files:

Aug 14, 2024
Read More
Tutorial
javascript php

Integrating Laravel and React with Vite: Using Databases and PHP in a Full-Stack Project

Generate a controller to handle the logic for your Post model:

php artisan make:controller PostController

Aug 14, 2024
Read More
Tutorial

Integrating Vite with Laravel for Modern Web Development

Your Laravel application will now use Vite's HMR, making your development process faster and more efficient.

When your application is ready for deployment, you can build your assets for production:

Aug 14, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Start the discussion!