Responsive font sizes - plugin - tailwind-css

I have one question for u guyz (and gals ;) )
does anybody know any existing plugin for Tailwind CSS which make font sizes responsive (except for lower and upper screen size where font size is fixed) aka. like that:
body { font-size: calc(16px + (26 - 16) * ((100vw - 768px) / (1280 - 768))); }
#media screen and (max-width: 768px) { body { font-size: 16px; }}
#media screen and (min-width: 1280px) { body { font-size: 26px; }}
lower screen width - fixed font size
screen sizes in between - responsive font size from 16px to 26px
wider screen width - fixed font size

1- Define font sizes for each breakpoint on tailwind.config.js
module.exports = {
theme: {
extend: {
fontSize: {
'body-lg': '1rem',
'body': '.875rem',
}
}
}
}
2- Create classes on global.css by importing definitions from config file.
#layer base {
body {
#apply text-body;
}
#screen lg { // applying font size for lg breakpoint
body {
#apply text-body-lg;
}
}
}

Just put some rule like the following e.g.:
<project/path/to>/tailwind.css
html {
font-size: 16px;
#screen md {
font-size: 17px;
}
#screen lg {
font-size: 26px;
}
}
No need for a plugin.

Here's my setup for React with styled-components and twin.macro, it uses hardcoded breakpoints as I couldn't find a way to interpolate breakpoints within tailwind.config.js:
// tailwind.config.js
/** #type {import('tailwindcss').Config} */
const plugin = require("tailwindcss/plugin");
module.exports = {
plugins: [
plugin(function ({addUtilities}) {
addUtilities({
".fs-0": {
fontSize: "2.281rem",
lineHeight: 1.1,
"#media (min-width: 768px)": {
fontSize: "3.583rem",
},
},
".fs-1": {
fontSize: "1.802rem",
"#media (min-width: 768px)": {
fontSize: "2.488rem",
},
},
".fs-2": {
fontSize: "1.424rem",
"#media (min-width: 768px)": {
fontSize: "1.728rem",
},
},
".fs-3": {
fontSize: "1.266rem",
"#media (min-width: 768px)": {
fontSize: "1.44rem",
},
},
".fs-4": {
fontSize: "1.125rem",
"#media (min-width: 768px)": {
fontSize: "1.2rem",
},
},
".fs-5": {
fontSize: "1rem",
},
});
}),
],
};
// components/GlobalStyles.tsx
import React from "react";
import {createGlobalStyle} from "styled-components";
import tw, {GlobalStyles as BaseStyles} from "twin.macro";
const CustomStyles = createGlobalStyle`
h1 { ${tw`fs-1`} }
h2 { ${tw`fs-2`} }
h3 { ${tw`fs-3`} }
h4 { ${tw`fs-4`} }
h5, h6 { ${tw`fs-5`} }
`;
function GlobalStyles() {
return (
<>
<BaseStyles />
<CustomStyles />
</>
);
}
export default GlobalStyles;
// pages/_app.tsx
import React from "react";
import GlobalStyles from "components/GlobalStyles";
const MyApp = (): JSX.Element => {
return (
<>
<GlobalStyles />
</>
);
};
export default MyApp;
Sources
Adding utilities to Tailwind docs
createGlobalStyles with styled-components
Typographic scales (default and md) generated with Type Scale

Related

How to style label in TextField in createTheme function

I tried to change label's margin (see the attached image to the question) from px to em/rem, but i don't know where i should write styles to structure. I can't find in MUI documentation "adjacent sibling combinator".
createTheme({
MuiTextField: {
defaultProps: {
// props
},
styleOverrides: {
root: {
// styles
}
}
}
})
generated css style in inspector tab
If you are using material-ui 5:
import { createTheme } from '#mui/material';
const theme = createTheme({
components: {
MuiTextField: {
styleOverrides: {
root: {
'& label': {
margin: '2rem',
},
},
},
},
},
});
export default theme;
https://mui.com/pt/material-ui/customization/theme-components/
I finally resolve it ;) I added to InputLabel this line "& + .MuiInputBase-root" to change TextField's (and another inputs) label
MuiInputLabel: {
defaultProps: {
// props
},
styleOverrides: {
root: {
// styles
"& +.MuiInputBase-root": {
marginTop: '2em'
}
}
}
}

Is it possible to add multiple media queries at Tailwindcss plugin?

Here is my Tailwindcss version 3.0.24.
I want to create a prefix css class like this:
<div class="myTestVariant:text-red-600">hello world</div>
and try to complie css by Tailwindcss like:
#media (max-width: 400px) {
myTestVariant\:text-red-600:active {
color: rgb(220, 38, 38, var(1));
// color may setted by tailwind.config.js
}
}
#media (min-width: 401px) {
myTestVariant\:text-red-600:hover {
color: rgb(220, 38, 38, var(1));
// color may setted by tailwind.config.js
}
}
And I tried to use addVariant to customize my variant. Here is my tailwind.config.js
const plugin = require('tailwindcss/plugin')
module.exports = {
content: [
'./index.html',
'./src/**/*.{vue,js,ts,jsx,tsx}',
],
theme: {
extend: {},
},
plugins: [
plugin(function({ addVariant, e, postcss }) {
addVariant('myTestVariant', ({container, separator }) => {
const supportsRule1 = postcss.atRule({ name: 'media', params: 'screen and (min-width: 401px)' })
const supportsRule2 = postcss.atRule({ name: 'media', params: 'screen and (max-width: 400px)' })
supportsRule1.append(container.nodes)
supportsRule2.append(container.nodes)
container.append(supportsRule1)
container.append(supportsRule2)
supportsRule1.walkRules(rule => {
rule.selector = `.${e(`myTestVariant${separator}`)}${rule.selector.slice(1)}:active`
})
supportsRule2.walkRules(rule => {
rule.selector = `.${e(`myTestVariant${separator}`)}${rule.selector.slice(1)}:hover`
})
})
}),
],
}
Actually, it doesn't work.
But when I only add one media queries, it's work.
const plugin = require('tailwindcss/plugin')
module.exports = {
content: [
'./index.html',
'./src/**/*.{vue,js,ts,jsx,tsx}',
],
theme: {
extend: {},
},
plugins: [
plugin(function({ addVariant, e, postcss }) {
addVariant('myTestVariant', ({container, separator }) => {
const supportsRule1 = postcss.atRule({ name: 'media', params: 'screen and (min-width: 401px)' })
supportsRule1.append(container.nodes)
container.append(supportsRule1)
supportsRule1.walkRules(rule => {
rule.selector = `.${e(`myTestVariant${separator}`)}${rule.selector.slice(1)}:active`
})
})
}),
],
}
I think the problem is: I am not familiar with postCss API.
Can someone do me a favor? please.
You can add the custom screen breakpoint in the tailwind.config.js as follows:
module.exports = {
theme: {
screens: {
//like you can add extra-extra-small screen as
'xxs': '400px',
// => #media (min-width: 400px) { ... }
'xs': '401px',
// => #media (min-width: 401px) { ... }
'sm': '640px',
// => #media (min-width: 640px) { ... }
'md': '768px',
// => #media (min-width: 768px) { ... }
'lg': '1024px',
// => #media (min-width: 1024px) { ... }
'xl': '1280px',
// => #media (min-width: 1280px) { ... }
'2xl': '1536px',
// => #media (min-width: 1536px) { ... }
}
}
}
You can find more here https://tailwindcss.com/docs/screens#adding-smaller-breakpoints

Adjust bullet size of react-simple-image-slider

I'm trying to resize the bullets on the image carousel from 15x15 pixels to 10x10. I see there is no documentation on an available props for this.
What is the best approach to resize the five bullets?
Example: https://codesandbox.io/s/05v4s?file=/src/App.js
import "./styles.css";
import SimpleImageSlider from "react-simple-image-slider";
export default function App() {
const images = [
{ url: "https://www.w3schools.com/howto/img_nature_wide.jpg" },
{ url: "https://www.w3schools.com/howto/img_snow_wide.jpg" },
{ url: "https://www.w3schools.com/howto/img_lights_wide.jpg" },
{ url: "https://www.w3schools.com/howto/img_mountains_wide.jpg" },
{
url:
"https://images.unsplash.com/photo-1478827217976-7214a0556393?ixid=MXwxMjA3fDB8MHxzZWFyY2h8MXx8dG9wfGVufDB8fDB8&ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60"
}
];
return (
<div className="App">
<SimpleImageSlider
showNavs="true"
width={456}
height={304}
images={images}
showBullets={true}
/>
</div>
);
}
style.css
.App {
font-family: sans-serif;
text-align: center;
}

Before and after pseudo elements not working in tailwind CSS

I am using typography plugin that tailwind provides inside my NextJS project.
It displays Content inside the code tag with backtick around it. I am trying to remove these backticks. So I tried .prose code::before {content: "";} inside my globals.css file but it has no effect. It works when I change it from Firefox style editor.
Any ideas why it is not working?
/* globals.css inside NextJS Project */
.prose code::before {
content: "";
}
.prose code::after {
content: "";
}
Use !important, this works for me.
/* app.css */
.prose code::before {
content: "" !important;
}
.prose code::after {
content: "" !important;
}
You can do this in with no CSS file involved.
Just add some customization code in tailwind.config.js:
// tailwind.config.js
module.exports = {
theme: {
extend: {
typography: {
DEFAULT: {
css: {
code: {
'&::before': {
content: 'none !important',
},
'&::after': {
content: 'none !important',
},
},
},
},
}
},
},
plugins: [
require('#tailwindcss/typography'),
// ...
],
}

Setting up line-height via TinyMCE

Is there a way to give user possibility to easily changing line-height attribute of paragraph in tinyMCE editor? Something like its native "Font size" or "Format" <select> or anything else. I know I can use "edit CSS" functionality and set it up there. I'm looking for something more user-friendly.
I can't find it anywhere.
I found this PlugIn for TinyMCE version 4.1.5 (2014-09-09)
https://github.com/castler/tinymce-line-height-plugin
Setting up like this:
tinymce.init({
plugins: 'lineheight',
toolbar: 'lineheightselect'
});
Also you could configure the different heights like that:
tinymce.init({
lineheight_formats: "8pt 9pt 10pt 11pt 12pt 14pt 16pt 18pt 20pt 22pt 24pt 26pt 36pt",
});
I tested this and it works great.
As per my comment,
Someone else was experiencing an issue similar to yours and a member of the TinyMCE forums provided a solution:
http://www.tinymce.com/forum/viewtopic.php?id=28774
With TinyMCE 4 you can use "style_formats" option
http://www.tinymce.com/wiki.php/Configuration:style_formats
I have found a good way for adding custom line-height to tinymce but this is a trick.
I am using tinymce v5 and with these codes i can use line height with a nice select option.
you have to add these lines to init codes of tiny mce:
tinymce.init({
selector: 'textarea',
height: 500,
plugins: 'table wordcount',
toolbar: ' styleselect ',
content_css: [
'//fonts.googleapis.com/css?family=Lato:300,300i,400,400i',
'//www.tiny.cloud/css/codepen.min.css'
],
toolbar: 'styleselect'
content_style: '.lineheight20px { line-height: 20px; }' +
'.lineheight22px { line-height: 22px; }' +
'.lineheight24px { line-height: 24px; }' +
'.lineheight26px { line-height: 26px; }' +
'.lineheight28px { line-height: 28px; }' +
'.lineheight30px { line-height: 30px; }' +
'.lineheight32px { line-height: 32px; }' +
'.lineheight34px { line-height: 34px; }' +
'.lineheight36px { line-height: 36px; }' +
'.lineheight38px { line-height: 38px; }' +
'.lineheight40px { line-height: 40px; }' +
'.tablerow1 { background-color: #D3D3D3; }',
formats: {
lineheight20px: { selector: 'span,p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes: 'lineheight20px' },
lineheight22px: { selector: 'span,p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes: 'lineheight22px' },
lineheight24px: { selector: 'span,p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes: 'lineheight24px' },
lineheight26px: { selector: 'span,p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes: 'lineheight26px' },
lineheight28px: { selector: 'span,p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes: 'lineheight20px' },
lineheight30px: { selector: 'span,p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes: 'lineheight30px' },
lineheight32px: { selector: 'span,p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes: 'lineheight32px' },
lineheight34px: { selector: 'span,p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes: 'lineheight34px' },
lineheight36px: { selector: 'span,p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes: 'lineheight36px' },
lineheight38px: { selector: 'span,p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes: 'lineheight38px' },
lineheight40px: { selector: 'span,p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes: 'lineheight40px' }
},
style_formats: [
{ title: 'lineheight20px',format: 'lineheight20px' },
{ title: 'lineheight22px', format: 'lineheight22px' },
{ title: 'lineheight24px', format: 'lineheight24px' },
{ title: 'lineheight26px', format: 'lineheight26px' },
{ title: 'lineheight28px', format: 'lineheight28px' },
{ title: 'lineheight30px', format: 'lineheight30px' },
{ title: 'lineheight32px', format: 'lineheight32px' },
{ title: 'lineheight34px', format: 'lineheight34px' },
{ title: 'lineheight36px', format: 'lineheight36px' },
{ title: 'lineheight38px', format: 'lineheight38px' },
{ title: 'lineheight40px', format: 'lineheight40px' }
]
});
and at the end i have to say you need to find a "paragraph" word in the file of tinymce/themes/silver/theme.min.js and change it to "line-height" if you want to see the line-height name instead of paragraph name.
this word is in line of 290855 of that file.
and this job is called custom format in tinymce that if you want to find it check this link:
https://www.tiny.cloud/docs/demo/format-custom/
and I have to say you need to add this css codes to your css file:
.lineheight22px{
line-height: 22px;
}
.lineheight24px{
line-height: 24px;
}
.lineheight26px{
line-height: 26px;
}
.lineheight28px{
line-height: 28px;
}
.lineheight30px{
line-height: 30px;
}
.lineheight32px{
line-height: 32px;
}
.lineheight34px{
line-height: 34px;
}
.lineheight36px{
line-height: 36px;
}
.lineheight38px{
line-height: 38px;
}
.lineheight40px{
line-height: 40px;
}
Indeed, TinyMCE doesn't have line-height control as it has for font names or font sizes, but you can easily add it with the style_formats. I used this config:
// custom formatting is under Format > formats, so make sure it's in your menu (it is, by default)
const editorOptions = {
// Notice that it overrides Format > formats
style_formats: [
{
title: 'Line height',
items: [
{
title: 'Default',
inline: 'span',
// `inline-block` because CSS `line-height` doesn't affect multiline `span`
styles: { 'line-height': 'normal', display: 'inline-block' }
},
{
title: '40px',
inline: 'span',
styles: { 'line-height': '40px', display: 'inline-block' }
},
// add as more as you need
]
},
// ...
]
}
Working example on codepen
TinyMCE style_formats doc

Resources