[Feature Proposal]: Add "line-clamp" utility #1303
Replies: 5 comments 4 replies
-
FWIW, it is on the standards track: https://www.w3.org/TR/css-overflow-3/#line-clamp |
Beta Was this translation helpful? Give feedback.
-
I implemented this as a component as it requires a few properties in order to work properly - including some const _ = require('lodash');
const plugin = require('tailwindcss/plugin');
module.exports = plugin.withOptions(function (lineCounts = []) {
return function ({ addComponents, e }) {
const components = _.map(lineCounts, lineCount => ({
[`.${e(`clamp-${lineCount}`)}`]: {
'-webkit-box-orient': 'vertical',
'-webkit-line-clamp':`${lineCount}`,
'display': '-webkit-box',
'lineClamp': lineCount,
'overflow': 'hidden',
}
}));
addComponents(components);
};
}); Had to use string interpolation on Would be good to see this feature make it into the core. |
Beta Was this translation helpful? Give feedback.
-
This is what I do in the scss utility library I'm working on –you won't find in in github yet, as it is a private repository. /* _base.scss */
/* Required pre-setup declarations for `line-clamp-{size} */
[class*=line-clamp-] {
overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
} /* _line-clamp.scss */
.line-clamp#{$modifier} {
-webkit-line-clamp: $value;
} Note: I omitted a lot of scss code for the shake of simplicity. Those variables came from an
Then the config file will hold all values for the Update: The attribute selector avoids repeating the required properties for |
Beta Was this translation helpful? Give feedback.
-
FYI - I published a plugin 3 months ago with this functionality, hope it helps. https://www.npmjs.com/package/@neojp/tailwindcss-line-clamp-utilities |
Beta Was this translation helpful? Give feedback.
-
There's now an official line-clamp plugin: https://github.com/tailwindlabs/tailwindcss-line-clamp |
Beta Was this translation helpful? Give feedback.
-
I think there should be a
line-clamp
utility, even though it's non-standard, it has good support across the board. I'm interested in adding it myself if you think it's a good idea.Beta Was this translation helpful? Give feedback.
All reactions