When adding text size classes for multiple screens, the line-height (leading) class gets overwritten because there is a line-height property on the text-size class (i.e. text-6xl).
.xl\:text-6xl {
font-size: 3.75rem;
line-height: 1; //this overrides .leading-tight
}
Below are the classes I'm needing just to include the same line-height (leading) at every breakpoint.
<h1 class="text-4xl leading-tight tracking-wide lg:text-5xl lg:leading-tight xl:text-6xl xl:leading-tight">My Title</h1>
Is there a way to avoid having to re-state the leading at each breakpoint and just state leading-tight once?
You can change the default line-height (that the font size utility provides) in tailwind.config.js:
Providing a default line-height - Docs.
In your case, I would set the default line-height to 1.5 rem, which is the value of the leading-tight utility. Then, whenever you want to override your default line-height (which is 1.5rem), you can simply add a custom line-height utility such as leading-[5rem].
Here's an example:
Setting custom fonts / custom line-heights. The second attribute in the array is the default line-height value:
module.exports = {
theme: {
fontSize: {
sm: ['14px', '1.25rem'],
base: ['16px', '1.25rem'],
lg: ['20px', '1.25rem'],
xl: ['24px', '1.25rem'],
header: ['36px', '1.25rem'],
}
}
}
HTML:
Note that the first paragraph has a different leading value while all the other paragraphs get the default value.
<div class="border-2 border-rose-200 m-24 p-12 flex flex-col items-center">
<header class="pb-12 underline text-header">A random header</header>
<p class="text-xl leading-[5rem]">A random paragraph 1</p>
<p class="text-xl">A random paragraph 2</p>
<p class="text-xl ">A random paragraph 3</p>
<p class="text-xl">A random paragraph 4</p>
<p class="text-xl">A random paragraph 5</p>
</div>
Result:
Tailwind-play link with the example.
Related
I am trying to apply an onhover effect for a viewport larger than 768px. Below 768px it should look like the elements are "always onhover".
Specifically, on desktop or larger devices in general, there should be a background in a box at onhover. This background should always be shown on mobile, i.e. <768px in my case.
What am I doing wrong?
Here are the snippets.
JSX-Snippet:
import { features } from "../constants"; import styles from "../style";
const FeatureCard = ({ icon, title, content, index }) => (
<div className=
{`
flex flex-row p-6 rounded-[20px]
ss:max-sm:feature-card-small
sm:feature-card
${index !== features.length - 1 ? "mb-6" : "mb-0"}
`}
>
<div className={`
w-[64px]
h-[64px]
rounded-full
${styles.flexCenter}
bg-dimBlue`
}>
<img
src={icon}
alt="star"
className="
w-[50%]
h-[50%]
object-contain"
/>
</div>
<div className="flex-1 flex flex-col ml-3">
<h4 className="
font-poppins
font-semibold
text-white
text-[18px]
leading-[23.4px]
mb-1">
{title}
</h4>
<p className="
font-poppins
font-normal
text-dimWhite
text-[16px]
leading-[24px]
">
{content}
</p>
);
export default FeatureCard;
CSS-Snippet:
.feature-card:hover { background: var(--black-gradient); box-shadow: var(--card-shadow); }
.feature-card-small { background: var(--black-gradient); box-shadow: var(--card-shadow); }
simply apply feature-card as class without viewport specification works as expected; onhover --> background changes
different viewport-specifications (sm:..., ss:max-sm and sm:) and creation of different CSS classes (so there can be no overlap for sure) did not work
sorry if the code block looks like a mess here on stackoverflow. my first post, still learning.
I have a div that is absolute and should take the full width of the page up to the md breakpoint. The width of div from the md breakpoint upward, should also be the full width of the page minus the width of a sidebar navigation menu that's on the left.
My issue is that since I'm using an ref in an Tailwind class instead of a hardcoded value the JIT compiler isn't applying the md:w-[calc(100%-${sidebarRef.current.clientWidth}px)].
What would be the correct way to implement this?
<div
className={`absolute top-0 right-0 w-full h-full md:w-[calc(100%-${sidebarRef.current.clientWidth}px)]`}>
// Content
</div>
You can compute the value outside the class decoration.
render() {
let divWidth = this.myRef.current ? this.sideBarRef.current.clientWidth : 0;
return (
<div
className={`absolute top-0 right-0 w-full h-full md:w-[calc(100%-${divWidth}px)]`}>
</div>
)
}
}
Tailwind doesn't handle dynamic classes. One solution might be to use a CSS variable in your class list and then set the value using JS. Something like:
render() {
return (
<style>
:root {
--content-width: calc({`100%-${sidebarRef.current.clientWidth}px`});
}
</style>
<div class="absolute top-0 right-0 w-full h-full md:w-[var(--content-width)] bg-red-50">
Content
</div>
)
}
Working example (in straight HTML): https://play.tailwindcss.com/xqiep4ObPt - resize by moving the partition.
I want to have two text color and font-weight within the same text element like below.
<div className={s.mainTitle}>
I want to keep this color white! <br />
But I want to only change the end word **green and bold**!
</div>
In the above example, I want to change only green and bold to green/bold, i.e. apply text-green-500 and font-bold using tailwind css.
In my current css file, I write something like
.mainTitle {
#apply text-white-default
#apply font-normal
}
How can I apply additional tailwind css properties only specific word?
You could wrap a <span> tag around the text you want to style. A <span> tag is an inline element so it won't break the words inside of it on to a new line.
For example:
<div className={s.mainTitle}>
I want to keep this color white! <br />
But I want to only change the end word <span className={s.greenAndBold}>green and bold</span>!
</div>
.greenAndBold {
#apply text-green-500
#apply font-bold
}
I created a component named Header with a simple css class:
<template>
<nav
class="flex fixed w-full items-center justify-between px-6 h-16 bg-white text-gray-700 border-b border-gray-200 z-10"
>
<!-- Etc... -->
</nav>
In Home component I registred Header but it is overlapping the home:
<template>
<div class="container">
<Header />
<div class="flex m-5">
<h3>Hello</h3>
</div>
</div>
</template>
<script>
export default {
name: 'Home',
components: {
Header: () => import('#/components/Header.vue')
}
}
</script>
The Hello is behind, even including block class in Home component is not worked. Anyone can helped?
There are may ways you could achieve this, but building on the code you already have, you could:
Add a top-0 class to your header. This will ensure that your header which is now positioned fixed will stick to the top of the viewport.
Add a top padding class equavliant to the height of your header (e.g. pt-16) to your container.
Here's a live demo for your reference.
overlapping component each others because of height of your component and in flex height taking automaticly so remove your height
remove css h-16
I am using bootstrap css and have defined subtitle.
Fiddle: Fiddle
<div class="center-container">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRzqEv5GXTFGZ1jOzAMNldPJAB6qCU2LRaiiWsld9o7zN1gz_jKaQ" class="img-responsive" alt="Responsive image">
<div class="subtitle">Intention from past</div>
</div>
I want to make first letter font size 36 for I in subtitle.
CSS:
subtitle:first-letter {
font-size: 34px !important;
}
but it does not make affect. what is the issue here?
OOPs ... You just forgot the period there . so it will search for an element called subtitle and not the class
.subtitle:first-letter {
font-size: 34px !important;
}
Demo (Added color to indicate)
Also, don't use !important as you won't need that..
Put your 'I' of "Intention from past" in span tag.
<div class="subtitle"> <span style="font-size:32px";>I</span>ntentio from past </div>
I have used inline css. You can change it to whatever size you want;
You forgot to put . in css before subtitle:first-letter.