john doe
john doe

Reputation: 125

Table not using Tailwind CSS

I am successfully using Tailwind so I'm not having a problem with importing it. I'm using a grid for example. However, I am unable to create a table that is in their examples. The table is not getting any of the colors. No styling is added to the table, what am I missing?

tailwind.config.js:

module.exports = {
purge: ['./src/**/*.{js,jsx,ts,tsx}', './public/index.html'],
darkMode: false, // or 'media' or 'class'
theme: {
    extend: {},

},
variants: {
    extend: {
        tableLayout: ['hover', 'focus'],
    },
    container: {
        center: true,
    },
},
plugins: [],}

Table that isn't rendering as expected:

    selectedView(){
    return (
        <table className="table-auto">
            <thead>
            <tr>
                <th>Title</th>
                <th>Author</th>
                <th>Views</th>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td>Intro to CSS</td>
                <td>Adam</td>
                <td>858</td>
            </tr>
            <tr className="bg-emerald-200">
                <td>A Long and Winding Tour of the History of UI Frameworks and Tools and the Impact on Design
                </td>
                <td>Adam</td>
                <td>112</td>
            </tr>
            <tr>
                <td>Intro to JavaScript</td>
                <td>Chris</td>
                <td>1,280</td>
            </tr>
            </tbody>
        </table>
);

}

Upvotes: 3

Views: 9423

Answers (2)

Drew Johnston
Drew Johnston

Reputation: 327

The emerald color scheme is not enabled in the default configuration.
The default colors are gray, blue, red, yellow, green, pink, indigo, purple.
Enabling emerald requires a change to your tailwind.config.js file:

const colors = require('tailwindcss/colors');

module.exports = {

  ......

  theme: {
    fontFamily: {
    },
    extend: {
      fontFamily: {
      },
      colors: {
        emerald: colors.emerald
      }
    },
  },
   .........
}

Upvotes: 0

mahan
mahan

Reputation: 14935

Well, tailwind doe not uses the same code under the hood. If you want to produce the same result as in thier documentation, you should use this code

<div class="rounded-t-xl overflow-hidden bg-gradient-to-r from-emerald-50 to-teal-100 p-10">
  <table class="table-auto">
    <thead>
      <tr>
        <th class="px-4 py-2 text-emerald-600">Title</th>
        <th class="px-4 py-2 text-emerald-600">Author</th>
        <th class="px-4 py-2 text-emerald-600">Views</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="border border-emerald-500 px-4 py-2 text-emerald-600 font-medium">Intro to CSS</td>
        <td class="border border-emerald-500 px-4 py-2 text-emerald-600 font-medium">Adam</td>
        <td class="border border-emerald-500 px-4 py-2 text-emerald-600 font-medium">858</td>
      </tr>
      <tr class="bg-emerald-200">
        <td class="border border-emerald-500 px-4 py-2 text-emerald-600 font-medium">A Long and Winding Tour of the History of UI Frameworks and Tools and the Impact on Design</td>
        <td class="border border-emerald-500 px-4 py-2 text-emerald-600 font-medium">Adam</td>
        <td class="border border-emerald-500 px-4 py-2 text-emerald-600 font-medium">112</td>
      </tr>
      <tr>
        <td class="border border-emerald-500 px-4 py-2 text-emerald-600 font-medium">Intro to JavaScript</td>
        <td class="border border-emerald-500 px-4 py-2 text-emerald-600 font-medium">Chris</td>
        <td class="border border-emerald-500 px-4 py-2 text-emerald-600 font-medium">1,280</td>
      </tr>
    </tbody>
  </table>
</div>

Source: copied from the same page's source code.

Upvotes: 1

Related Questions