Why is the ellipsis floating at center of the string? - css

I ran into this problem while trying to truncate my text with an ellipsis. I'm using Tailwind CSS classes to achieve this.
Description:
The string should be truncated like John D... if it's too long, the ellipsis should be aligned at the bottom of the string.
But instead, the ellipsis is floating in the middle of the string like this:
I'm using 'Noto Sans JP', sans-serif font here. I tried changing to another default fonts but it's still behave in the same way.
Here's the code I use to truncate the text:
.truncate {
overflow: hidden !important;
text-overflow: ellipsis !important;
white-space: nowrap !important;
}
JSX:
<div className="rounded-t opacity-80 z-10 flex items-center absolute max-w-[17ch] text-black bg-white py-px px-2 bottom-0 right-4 transform-3d">
<Icon />
<p className='truncate mb-0'>{attendeeName}</p>
</div>

The ... may be occurring due to some other dependency/class like if you have item-center class somewhere in the div wrapping this text.
Assuming this is the code and had no dependency
Otherwise, you don't need to add any additional CSS and !important. Just add truncate text-elipsis class to the text.
Below is the implementation where I had shown the text-elipsis functionality
<script src="https://cdn.tailwindcss.com"></script>
<div class="p-5 space-y-4">
<div class="max-w-[5rem] bg-slate-200">
<Icon />
<p class='truncate text-ellipsis mb-0'>attendeeName</p>
</div>
<div class="max-w-[8rem] bg-slate-200">
<Icon />
<p class='truncate text-ellipsis mb-0'>attendeeName</p>
</div>
</div>
You can see if you use it normally then the ... appears at the bottom. So try to check the complete code again.
Edit after discussion with presenter
I had added the flex class in a span and removed some unnecessary classes.
<script src="https://cdn.tailwindcss.com"></script>
<div class="transform-3d bottom-0 right-4 z-10 max-w-[17ch] rounded-t bg-red-300 py-px px-2 text-black opacity-80">
<span class="flex flex-row space-x-2">
<img src="http://commondatastorage.googleapis.com/codeskulptor-assets/week5-triangle.png" class="h-6 w-6" />
<p class="mb-0 truncate text-ellipsis">attendeeName is very short</p>
</span>
</div>

Related

Tailwindcss: How to focus-within and focus-visible at the same time

I want to focus a div surrounding a button but only when keyboard focused. Usually focus-within works, but in this case it should only focus on keyboard focus (focus-visible:) and not when clicking with the mouse(focus:).
Essentially, I need to combine focus-within and focus-visible. How can this be done?
Tailwind Play: https://play.tailwindcss.com/ApDB5gSjqv
<div class="flex h-screen items-center justify-center">
<div class="rounded-lg bg-green-100 px-20 py-20 focus-within:ring-4 focus-within:ring-blue-300">
<button class="bg-green-200 px-6 py-3 focus:outline-none">Focusable Button</button>
</div>
</div>
Notes:
Based on this thread, it looks like w3c doesn't have support for focus-within-visible. What's an alternative or round-about way to achieve this?
It looks like there is support for :has(:focus) selector in some browsers but how should this be applied in Tailwind...? Source
Instead of using focus-within you could add relative to the div you want to make look focused with the ring. Then make the button a peer and have an absolutely positioned div after it use the peer-focus-visible modifier to add any "focused" styles you want.
EDIT: You'll need to make the div be behind the button by adding relative to the button and assigning an appropriate z-index value to both the inset div and button.
<div class="flex h-screen items-center justify-center">
<div class="rounded-lg bg-green-100 px-20 py-20 relative">
<button class="bg-green-200 px-6 py-3 focus:outline-none peer relative z-[1]">Focusable Button</button>
<div class="absolute inset-0 rounded-lg peer-focus-visible:ring-4 peer-focus-visible:ring-blue-300 z-[0]"></div>
</div>
Here is an edited example on Tailwind Play https://play.tailwindcss.com/us5kpJg6cV

Form going off of page

I'm trying to style a form using, but when I put in the margin for the left and right (mx-4), it is only add the margin on the left side and on the right side it's going off of the page.
export default function TextArea() {
return (
<div className="w-full mt-1 ">
<p className="text-purple-800 font-medium px-4 py-1">
What are you thinking?
</p>
<textarea
rows={4}
name="comment"
id="comment"
className="w-full sm:w-auto md:w-2/3 mx-4 h-96 rounded-md border-white sm:text-md placeholder-gray-300 text-black"
placeholder="Type your idea here..."
/>
</div>
)
}
I see you are using full width w-full for the div also the same thing for text area.
Here when you give w-full it will take the full with of the parent. Here Div is taking full width of its parent and text area is taking the width of div. Here you need to check the div's parent and set the correct width to it.
I believe mx-4 is being applied at the other end of the text area. You can inspect and see this in your browser
The problem is due to w-full. The class w-full on the parent div is causing the form to take up the full width of its parent container.
Change it to mx-auto
Change this
<div className="w-full mt-1 ">
to
<div className="mx-auto mt-1">

How to Put Image Slightly Above the Card using Tailwind CSS in Mobile and Tablet

Note: It works well on Desktop but in Mobile and Tablet does not work on. Hoping for a help at the StackOverflow Community.
<div>
<div className='justify-center mt-16 md:pb-6 lg:pb-0 lg:flex lg:mx-36 md:mx-auto rounded-2xl bg-neutral-800'>
{/* Column 1 */}
<div className="-mt-10 lg:relative">
<Image
src="/images/review/image-jeremy-large#2x.png"
width={290}
height={290}
alt="people"
className="w-56 mx-auto rounded-xl lg:w-72"
/>
</div>
{/* Column 2 */}
<div>
<Image
src="/images/review/patternCurveDiagonalLine.png"
width={60}
height={60}
alt="Curve Diagonal Line"
className="mx-auto mt-10 lg:mt-32 lg:mx-14"
/>
</div>
{/* Column 3 */}
</div>
</div>
</div>
Check Tailwind's documentation on Position.
There is section "Absolutely positioning elements" where it is described same thing you want to do: https://tailwindcss.com/docs/position#absolutely-positioning-elements
You have defined mt-16 in the parent div. So
-mt-10 is cut from mt-16 , so you can witness 16 - 10 = 6 i.e mt-6 in the mobile.
To overcome that remove mt-16 in the parent div.
Change
<div className='justify-center mt-16 md:pb-6 lg:pb-0 lg:flex lg:mx-36 md:mx-auto rounded-2xl bg-neutral-800'>
to
<div className='justify-center md:pb-6 lg:pb-0 lg:flex lg:mx-36 md:mx-auto rounded-2xl bg-neutral-800'>

How can I place elements between sections using CSS?

I've looking for a way to place elements between sections, I tried using margins but the elements stay "behind" the next section in the page. What's the CSS property I need to use? I use Tailwind CSS but would like to know what property handles it so I can look about it in the documentation. Also, I'm using components (React / JSX) in my project.
I attached an image for reference.
Thanks!
[Elements inside red square][1]
[1]: https://i.stack.imgur.com/vVLbS.png
try codes below in TailwindCSS playground
hope u get what u want
<div class="bg-sky-400">
<p>test</p>
</div>
<div class="bg-indigo-400">
<div class="absolute z-10 -translate-y-1/2">
<div class="inline-block h-4 w-4 rounded-full bg-white"></div>
<div class="inline-block h-4 w-4 rounded-full bg-white"></div>
</div>
<p>hello</p>
</div>

How to position an element to use the remaining space of the screen without overflowing it [TailwindCSS]

I'm using TailwindCSS -a utility class framework- to style my elements. Altough this is more a generic CSS question.
I can't manage to position the box so this gets the remaining space without overflowing it. This is my actual state:
<div class="flex flex-col h-screen mx-8 bg-white rounded p-4 mb-8">
<!-- SUBTITLE -->
<div>
<h2 class="text-lg font-bold text-gray-700 pb-4">Subtitle</h2>
</div>
<div class="relative self-auto mb-8">
<!-- ELEMENTS -->
<a href="#">
<img class="absolute z-10" style="top: 131px; left: 235px;"
src="{{ asset('some.svg') }}">
</a>
</div>
</div>
Output (omitting some of the inside elements):
As you can see, the scrollbar shows because the div is too big. In order to see the bothom of the box I have to scrolldown:
This is my desired output:
Thanks in advance.
Fiddle
Link.
The class .h-screen is 100vh. .mb-8 has an margin-bottom:2rem. So the height is 100vh + 2rem. You can use [calc][1] to subtract the margin from the height.
.h-screen{
height:calc(100vh - 2rem)!important;
}
https://jsfiddle.net/c28145au/
https://developer.mozilla.org/en-US/docs/Web/CSS/calc
This is the solution I found: w-[calc(100%_-_10px)]
you are using class h-screen which has height: 100vh; remove that class from the div.

Resources