How to specify height: fit-content with TailwindCSS? - css

Using TailwindCSS I'm trying to have a <div> fit to the height of its child, a <button>. My code is as follows:
<form className="w-full flex h-96 gap-2 mt-8 flex-wrap">
<textarea
role="text-input"
className="resize-none flex-1"
placeholder="INPUT"
/>
<textarea
role="text-output"
className="resize-none flex-1"
placeholder="OUTPUT"
readOnly
/>
<div className="w-full flex flex-none"> // This is the troublesome div
<button>
Submit!
</button>
</div>
</form>
Reading through the docs and doing a google search I can't seem to find a way to do this, ideally I'd like to set a class such as h-fit-content (something like this) but it doesn't seem to exist.
Thanks in advance!

Tailwind has now the class w-fit.

Tailwind has now the class h-fit.

you can create custom classes in your tailwind configuration for future use.
example:
module.exports = {
important: true,
purge: ['./src/**/*.{js,jsx,ts,tsx}', './public/index.html'],
darkMode: 'class', // or 'media' or 'class'
theme: {
extend: {
colors: {
...
},
animation: {
...
},
width: {
...
},
margin: {
...
},
height: {
76: '18rem',
78: '19rem',
82: '22rem',
97: '28rem',
98: '31rem',
99: '38rem',
100: '40rem',
'fit-content': 'fit-content(20em)',
},
fontFamily: {
mps: ['Clarkson', 'Helvetica', 'sans-serif']
},
flex: {
2: '1 1 25%',
3: '1 1 30%',
4: '1 1 40%',
5: '1 1 50%',
6: '1 1 60%',
}
},
},
variants: {
extend: {},
},
plugins: [],
}

I managed to fix my issue by setting h-full in both <textarea> and setting flex-none in my problematic <div>, resulting in the following code:
<form className="w-full flex h-96 gap-2 mt-8 flex-wrap">
<textarea
role="text-input"
className="h-full resize-none flex-1"
placeholder="INPUT"
/>
<textarea
role="text-output"
className="h-full resize-none flex-1"
placeholder="OUTPUT"
readOnly
/>
<div className="w-full flex flex-none"> // This is the troublesome div
<button>
Submit!
</button>
</div>
</form>

Related

Tailwind CSS custom responsive breakpoints are not working

I want to make a responsive web site using Tailwind CSS and Next.js, but I can't apply my custom responsive utility classes. I added my custom breakpoints in tailwind.config.js.
Other media queries are working fine.
I designated w-[600px] in max-1280px and w-[400px] in max-768, but I can't apply max-768 and another media query only applied max-1280px.
import React from 'react';
import profile from '../../assets/images/me.jpg';
import Image from 'next/image';
import Link from 'next/link';
import { aboutContent } from '../../data/aboutContent';
const about = () => {
return (
<div className='animate-fade-in-up'>
<h1 className='text-5xl font-appleSemiBold laptopM:text-center laptopM:underline laptopM:mb-12 tablet:text-4xl'>
About Me
</h1>
<div className='border-2 w-40 ml-[142px] mb-12 laptopM:hidden'></div>
<div className='flex flex-row justify-between items-center font-appleRegular laptopM:flex-col laptopM:gap-10'>
<Image
className='w-[600px] tablet:w-[400px]'
src={profile}
alt='Picture of me'
/>
<div className='w-6/12 laptopM:w-[600px] tablet:w-[400px]'>
<div className='text-2xl mb-8 tablet:text-xl'>
<p>test</p>
<p>
test
</p>
</div>
</div>
</div>
<div className='font-regular'></div>
</div>
);
};
export default about;
/** #type {import('tailwindcss').Config} */
module.exports = {
content: [
'./pages/**/*.{js,jsx,ts,tsx}',
'./components/**/*.{js,jsx,ts,tsx}',
],
theme: {
extend: {
screens: {
mobileS: { max: '320px' },
mobileM: { max: '375px' },
mobileL: { max: '425px' },
tablet: { max: '768px' },
laptop: { max: '1024px' },
laptopM: { max: '1280px' },
laptopL: { max: '1440px' },
},
},
plugins: [],
};

React-Slick - transform: translate3d - Not working on smaller resolutions

I am using next.js and fetching data via API to slides. React-slick works great until the first break point on lower resolution (890px in this example).
.slick-track class has a property that is causing this problem.
.slick-track {transform: translate3d((wrong calc here)px, 0px, 0px)}
So instead 0px on first value inside translate 3d I'm getting value that is width of element where the list of slides should be shown. And List is moved to right so it cant bee seen.
After click on next button, list is coming to its normal place, but skipping first element in list...
Screenshot:
I have tried to overwrite this property inside module.css via :global and inside base CSS file, but it is still applied. I i put !important at end of my property it will be applied but I wont be able to scroll/navigate through elements of slide (first element will be stuck to left).
I also have tried older versions of react-slick 26.0; 26.1; 27.0; 28.0... But problem is still here.
Does anyone has some idea for solution?
Here is my component:
const Accessories = () => {
const { query } = useRegions();
const { error, data } = useAccessoriesSubcategoriesQuery({
variables: { ...query },
});
if (error) {
console.error("Accessories section component error", error.message);
}
const subcategoryItems = data?.categories.edges[0].node.children.edges || [];
// Slick slider settings
const settings = {
dots: false,
infinite: false,
speed: 500,
slidesToShow: 4,
slidesToScroll: 1,
nextArrow: <AccessoriesNextBtn currentSlide={0} slideCount={0} />,
prevArrow: <AccessoriesPrevBtn currentSlide={0} slideCount={0} />,
responsive: [
{
breakpoint: 890,
settings: {
slidesToShow: 3,
},
},
{
breakpoint: 620,
settings: {
slidesToShow: 2,
},
},
{
breakpoint: 420,
settings: {
slidesToShow: 1,
},
},
],
};
return (
<div className={"flex items-center justify-center w-full h-full bg-white"}>
<Container className="flex-col relative overflow-hidden">
<div className="flex flex-col lg:flex-row w-full mb-[50px] gap-[30px] lg:gap-[20px] justify-between">
<H2Headline className="text-[26px] text-left ">
Pool equipment & water treatment
</H2Headline>
<Button
className={`${styles.accessoriesSeeAllBtn} mb-[50px] mr-[0px] ml-auto xs:mb-0 xs:ml-0 xs:mr-auto max-w-[112px] h-[45px] box-border text-solidGray font-semibold text-[16px] leading-[157%] bg-white border border-solidGray hover:bg-solidGray hover:text-white`}
>
{/* <LinkBuilder linkItem={data?.categories.edges[0].node}>See all</LinkBuilder> */}
See All
</Button>
</div>
<div className={`${styles.accessoriesSliderWrapper} md:min-w-[500px] w-full`}>
<style jsx global>{`
.slick-track {
display: block;
transform: translate3d(0px, 0px, 0px);
}
`}</style>
<Slider {...settings}>
{subcategoryItems.map((item) => (
<div
key={item?.node.id}
className="flex flex-col max-w-[366px] md:max-w-[263px] transform hover:-translate-y-3 duration-500 ease-in-out "
>
{item.node.backgroundImage ? (
<div className="flex justify-center items-center content-center h-[280px] bg-lightGray rounded-[12px] overflow-visible z-50">
<Image
src={item.node.backgroundImage?.url}
width={218}
height={218}
alt="Category image"
className="object-cover object-center w-auto h-auto"
placeholder="blur"
blurDataURL={item.node.backgroundImage?.url}
/>
</div>
) : null}
<h3 className="text-solidGray text-[16px] leading-[160%] font-medium mt-[12px] mb-[3px]">
{item.node.name}
</h3>
<ParagraphText className="text-[14px] text-gray opacity-100 mt-[3px] mb-[12px]">
{item.node.description}
</ParagraphText>
<Button className="mx-auto text-[14px] border border-lightGray bg-white w-full hover:bg-solidGray hover:border-solidGray hover:text-white">
<LinkBuilder linkItem={item}>See all</LinkBuilder>
</Button>
</div>
))}
</Slider>
</div>
</Container>
</div>
);
};

I am trying to change the text color but for some reason it is not working

I am trying to change the color of the text of my p tag but for some reason it is not working. I am very new to coding so any advice would help.
import React from 'react'
import { SocialIcon } from 'react-social-icons';
type Props = {}
export default function Header({}: Props) {
return (
<header className="sticky top-0 flex items-start justify-between max-w-7xl mx-auto z-20 xl:items-center">
<div className="flex flex-row items-center">
{/* Social Icons */}
<SocialIcon
url="https://"
fgColor="gray"
bgColor="transparent"
/>
<SocialIcon
url="https://"
fgColor="gray"
bgColor="transparent"
/>
</div>
<div className="flex flex-row items-center text-gray-300 cursor-pointer">
<SocialIcon
className="cursor-pointer"
network="email"
fgColor="gray"
bgColor="transparent"
/>
<p className="text-gray-400">Why wont this work</p>
</div>
</header>
);
}
**tailwind.config.js**
/** #type {import('tailwindcss').Config} */
module.exports = {
content: [
"./pages/**/*.{js,ts,jsx,tsx}",
"./compnents/**/*.{js,ts,jsx,tsx}",
],
theme: {
extend: {},
},
plugins: [],
}
the line of code Why wont this work does not do anything and simply leaves the text black
I honestly have no idea what to do here. I thought the other div classNames might be affecting the p tag somehow so I tried deleting them but that didn't work either. Below I attached an image of it as proof.
enter image description here
Maybe your tailwind.confing.js is not correct or something wrong.
Tailwind Css supplies the public document.
please check here.
https://tailwindcss.com/docs/customizing-colors
For example, can you set your customize color on theme.extend.colors in tailwind.config.js ?
you can customize for what you expect.
Here is sample.
tailwind.config.js
module.exports = {
theme: {
extend: {
colors: {
gray: {
400: '#303030', // custom
},
}
},
},
}
Please rebuild your app after changing that config at last.
try it.

Unexpected<hr> line appear when having scrollbar vertically (when height exceed 100%)

how the title says the problem is with a line that can be seen in the next image:
If I remove the table, let's say to not have scrollbar vertically, the line also dissapear:
What I tried:
To see If html, body, div root (I use react) use height 100% but not.
To see with inspect element if that line is a hr or an element that can be removed, it's not
The only one solution seems to remove padding left-right to override the line or I don't know.
React HTML code:
return (
<React.Fragment>
<Navbar/>
<section className="container__ide">
<div className="container__settings">
<Tooltip title={'Schimbarea marimii textului pentru editorul text'} placement="left">
<Select
value={codeFontSize}
onChange={handleChangeFontSize}
MenuProps={{
anchorOrigin: {
vertical: "bottom",
horizontal: "left"
},
transformOrigin: {
vertical: "top",
horizontal: "left"
},
getContentAnchorEl: null
}}
>
{
selectFontSizeOptions.map((fontSize) => {
return <MenuItem key={fontSize} value={fontSize}>{fontSize} px</MenuItem>
})
}
</Select>
</Tooltip>
<Button>
<FaBug/>
</Button>
</div>
<div className="container__problem">
<div
className="container__statement"
>
<div className="container__top__statement">
<span>
Descriere
</span>
</div>
<div className="container__inner__statement">
</div>
</div>
<div
className="container__code"
>
<div className="container__top__code">
<span>
Solutie
</span>
<button>
Rulare cod
</button>
</div>
<div className="container__inner__code">
<Editor
height="300px"
defaultLanguage="sql"
defaultValue="// some comment"
theme="my-theme"
fontSize="20px"
onMount={handleEditorOnMount}
/>
</div>
</div>
</div>
<div className="container__result">
<MaterialTable
columns={[
{ title: 'Adı', field: 'name' },
{ title: 'Soyadı', field: 'surname' },
{ title: 'Doğum Yılı', field: 'birthYear', type: 'numeric' },
{ title: 'Doğum Yeri', field: 'birthCity', lookup: { 34: 'İstanbul', 63: 'Şanlıurfa' } }
]}
data={[
{ name: 'Mehmet', surname: 'Baran', birthYear: 1987, birthCity: 34 },
{ name: 'Mehmet', surname: 'Baran', birthYear: 1988, birthCity: 42 },
{ name: 'Mehmet', surname: 'Baran', birthYear: 1989, birthCity: 63 },
{ name: 'Mehmet', surname: 'Baran', birthYear: 1989, birthCity: 63 }
]}
title="Demo Title"
icons={tableIcons}
/>
</div>
<div className="container__comments">
<button>Adauga comentariu</button>
</div>
</section>
</React.Fragment>
)

ReactJS - how to style the parent?

I would like to put style on the "Forms_formline__3DRaL" div (seen below)
This div comes from a component; and it seems like this style is applied to the input , and not its parent div.
How can I, though reactjs, define the style "display: none" for the parent div?
Here is my code:
<MyInput
style={{
display:
type == 1
? 'none'
: 'block',
}}
id="name"
type="text"
label={t('elevation_loss')}
value="name"
/>
Here is the result in my chrome source:
<div class="Forms_formline__3DRaL">
<label for="name">Name *</label>
<input type="text" id="name" value="" style="display: none;">
</div>
You can try doing something like this
import { CSSProperties, FC } from 'react';
export const MyInput: FC<{
styleOverrides: {
container: CSSProperties;
};
id: string;
type: string;
label: string;
}> = ({ styleOverrides }) => {
return (
<>
<div className="Forms_formline__3DRaL" style={styleOverrides.container}>
...
</div>
</>
);
};

Resources