-
The current pagy tailwind css wasn't working for me, I needed to change these lines:
to this:
versions
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
How does the tailwind page of the demo app look? |
Beta Was this translation helpful? Give feedback.
-
It seems that you were facing an issue with the Tailwind CSS styles for the pagination links in your Rails application, and you found a solution by modifying the CSS styles. The initial code block you provided: a:not(.gap) {
@apply block rounded-lg px-3 py-1 bg-gray-200;
&:hover {
@apply bg-gray-300;
}
} This code applies some base styles to the pagination links ( However, in the modified version that worked for you: a:not(.gap) {
@apply block rounded-lg px-3 py-1 bg-gray-200 hover:bg-gray-300;
} Instead of using a nested selector, you combined the base styles and hover styles into a single line using the The reason this modification worked could be related to the way Tailwind CSS handles nested styles or the specific versions of the libraries you're using (Rails 7.1.3.2, Ruby 3.2.2, and tailwindcss-rails 2.5). Sometimes, there might be compatibility issues or differences in how the styles are processed, and a slightly different approach might be required to achieve the desired result. In your case, the simplified version with the combined utility classes solved the issue, and the pagination links now have the correct background color on hover. |
Beta Was this translation helpful? Give feedback.
-
I just created these styles inspired by flowbite, I hope it helps you: Demo: RepoFile: application.tailwind.css/* application.tailwind.css */
@tailwind base;
@tailwind components;
@tailwind utilities;
.pagy {
@apply inline-flex items-stretch -space-x-px;
> *:first-child {
@apply rounded-l-lg;
}
> *:last-child {
@apply rounded-r-lg;
}
}
.pagy a:not(.gap) {
@apply flex items-center justify-center text-sm py-2 px-3 leading-tight text-gray-500 bg-white border border-gray-300;
&:hover {
@apply bg-gray-100 text-gray-700;
}
&:not([href]) {
@apply text-gray-300 bg-gray-100 cursor-default;
}
&.current {
@apply flex items-center justify-center text-sm z-10 py-2 px-3 leading-tight text-primary-600 bg-primary-50 border border-primary-300;
}
}
span.pagy.info {
@apply text-sm font-normal text-gray-500;
} File: tailwind.config.jsmodule.exports = {
content: [
'./app/views/**/*.html.erb',
'./app/helpers/**/*.rb',
'./app/assets/stylesheets/**/*.css',
'./app/javascript/**/*.js',
],
plugins: [require('@tailwindcss/forms')],
darkMode: 'class',
theme: {
extend: {
colors: {
primary: {
50: '#eef2ff',
100: '#e0e7ff',
200: '#c7d2fe',
300: '#a5b4fc',
400: '#818cf8',
500: '#6366f1',
600: '#4f46e5',
700: '#4338ca',
800: '#3730a3',
900: '#312e81',
950: '#1e1b4b',
},
},
},
fontFamily: {
body: [
'Inter',
'ui-sans-serif',
'system-ui',
'-apple-system',
'system-ui',
'Segoe UI',
'Roboto',
'Helvetica Neue',
'Arial',
'Noto Sans',
'sans-serif',
'Apple Color Emoji',
'Segoe UI Emoji',
'Segoe UI Symbol',
'Noto Color Emoji',
],
sans: [
'Inter',
'ui-sans-serif',
'system-ui',
'-apple-system',
'system-ui',
'Segoe UI',
'Roboto',
'Helvetica Neue',
'Arial',
'Noto Sans',
'sans-serif',
'Apple Color Emoji',
'Segoe UI Emoji',
'Segoe UI Symbol',
'Noto Color Emoji',
],
},
},
}; Preview |
Beta Was this translation helpful? Give feedback.
-
I noticed an issue that (for me) affects those Pagy custom styles and could be the source of problems reported by others here, see tailwindlabs/tailwindcss#14092 Nesting selectors merges them when minified, breaking styling. I use |
Beta Was this translation helpful? Give feedback.
It seems that you were facing an issue with the Tailwind CSS styles for the pagination links in your Rails application, and you found a solution by modifying the CSS styles.
The initial code block you provided:
This code applies some base styles to the pagination links (
a
tags) using the Tailwind CSS utility classes. The&:hover
part is a nested CSS selector that targets the hover state of the links and applies a different background color (bg-gray-300
) when hovered.However, in the modified version that worked for you: