English 中文(简体)
Tailwind background color not working as I expect
原标题:

I m trying to set a background color for a div in a component, for light and dark themes, but I m not getting the result I expect.

On one side, bg-gray-400 and dark:bg-gray-100 are not changing anything. Also, bg-[#2a2e35] and dark:bg-[#3b65ae] shows color #2a2e35 on dark mode.

---
export interface Props {
  title: string;
  body: string;
  ogImage?: string;
  href: string;
  published: Date;
}

const { href, title, body, ogImage, published } = Astro.props;
---

<a href={href}>
  <div
    class="bg-gray-400 dark:bg-gray-100 w-full rounded-lg border shadow duration-200 ease-in hover:scale-105"
  >
    <img class="rounded-t-lg" src={ogImage} alt="" />
    <div class="p-5 bg-[#2a2e35] dark:bg-[#3b65ae]">
      <h5
        class="text-gray-900 dark:text-white mb-4 text-sm font-bold tracking-tight"
      >
        {title}
      </h5>
      <p
        class="text-gray-700 dark:text-gray-400 mb-12 text-sm font-normal"
      >
        {body}
      </p>
    </div>
  </div>
</a>

tailwind.config.cjs

/** @type {import( tailwindcss ).Config} */

function withOpacity(variableName) {
  return ({ opacityValue }) => {
    if (opacityValue !== undefined) {
      return `rgba(var(${variableName}), ${opacityValue})`;
    }
    return `rgb(var(${variableName}))`;
  };
}

module.exports = {
  content: ["./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}"],
  theme: {
    // Remove the following screen breakpoint or add other breakpoints
    // if one breakpoint is not enough for you
    screens: {
      sm: "640px",
      md: "768px",
      lg: "1024px",
      xl: "1280px",
    },

    // Uncomment the following extend
    // if existing Tailwind color palette will be used

    // extend: {
    textColor: {
      skin: {
        base: withOpacity("--color-text-base"),
        accent: withOpacity("--color-accent"),
        inverted: withOpacity("--color-fill"),
      },
    },
    backgroundColor: {
      skin: {
        fill: withOpacity("--color-fill"),
        accent: withOpacity("--color-accent"),
        inverted: withOpacity("--color-text-base"),
        card: withOpacity("--color-card"),
        "card-muted": withOpacity("--color-card-muted"),
      },
    },
    outlineColor: {
      skin: {
        fill: withOpacity("--color-accent"),
      },
    },
    borderColor: {
      skin: {
        line: withOpacity("--color-border"),
        fill: withOpacity("--color-text-base"),
        accent: withOpacity("--color-accent"),
      },
    },
    fill: {
      skin: {
        base: withOpacity("--color-text-base"),
        accent: withOpacity("--color-accent"),
      },
      transparent: "transparent",
    },
    fontFamily: {
      mono: ["Open Sans", "sans-serif"],
    },
    // },
  },
  plugins: [require("@tailwindcss/typography")],
};

I want to have color #3b65ae on dark theme and #2a2e35 on light theme.

I m not very used to Tailwind but I m doing what I saw in some documentation.

Light Theme Dark Theme

问题回答

暂无回答




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

Drop down background url in Safari Issue

selectBox.selectCSS { background: url(/Images/replacementSelectBackground.png) top left no-repeat height:auto; } I have an issue in Safari only where the image is not rendering on top ...

CSS specific for Safari

How do you target specifically safari in css with styles?

Aligning textarea in a form

Ive used the following css code to align my form elements: form { position:relative; } form input { position:absolute; left:11em; } However, the textarea element is not aligned correctly with the ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

CSS problem with page footer

I have defined my page footer in the css file as: #footer { position: absolute; height: 50px; text-align: center; background: #66CCCC; bottom: 0px; left: 0px; width: 100%; height: ...

热门标签