Element with line-clamp too wide - html

I am using the #tailwindcss/line-clamp plugin to clamp a text element (<span>) to one line (line-clamp-1). The text element is inside a flex box, and is followed by another text element that's supposed to "stick" to its right side.
My problem is that the width of the clamped text element is not computed properly. Even though the text is clamped correctly, the width of the element remains too wide and the following text does not "stick" closely like I want to.
Below is a screenshot. The "problem element" is the one that says "Human-Computer Interaction". It should look like the others, where the "post count" in parentheses "sticks" closely to the topic label.
Here is my code:
{{#foreach tags}}
<a class="flex flex-row gap-1" href="{{url}}">
<span class="text-neutral-200 line-clamp-1"> {{name}}</span>
<span class="text-neutral-500"> ({{count.posts}})</span>
</a>
{{/foreach}}
How does one reduce the width of the clamped text element to fit the clamped text inside?
P.S. I have tried replacing <span>s with <p> elements, and using other CSS approaches that don't involve the line-clamp plugin, and have not found a solution so far.

There is no need to use an extra package because you only one have line and for achieve you can use text-overflow property with white-space and overflow to get the same result.
You can use it as inline or create you own class with #layer.
<script src="https://cdn.tailwindcss.com"></script>
<style type="text/tailwindcss">
#layer utilities { .ellip { #apply overflow-hidden text-ellipsis whitespace-nowrap; } }
</style>
<div class="grid grid-cols-4 gap-6 bg-black">
<div class="flex flex-col">
<a class="flex flex-row gap-1" href="/#">
<span class="overflow-hidden text-ellipsis whitespace-nowrap text-neutral-200"> Music</span>
<span class="text-neutral-500"> (7)</span>
</a>
<a class="flex flex-row gap-1" href="/#">
<span class="overflow-hidden text-ellipsis whitespace-nowrap text-neutral-200"> Architecture</span>
<span class="text-neutral-500"> (2)</span>
</a>
<a class="flex flex-row gap-1" href="/#">
<span class="overflow-hidden text-ellipsis whitespace-nowrap text-neutral-200"> Graphic Design</span>
<span class="text-neutral-500"> (10)</span>
</a>
<a class="flex flex-row gap-1" href="/#">
<span class="overflow-hidden text-ellipsis whitespace-nowrap text-neutral-200"> Human-Computer Interaction </span>
<span class="text-neutral-500"> (5)</span>
</a>
</div>
<div class="flex flex-col">
<a class="flex flex-row gap-1" href="/#">
<span class="text-neutral-200 ellip"> Human-Computer Interaction</span>
<span class="text-neutral-500"> (7)</span>
</a>
<a class="flex flex-row gap-1" href="/#">
<span class="text-neutral-200"> Art</span>
<span class="text-neutral-500"> (4)</span>
</a>
<a class="flex flex-row gap-1" href="/#">
<span class="text-neutral-200 ellip"> Education</span>
<span class="text-neutral-500"> (5)</span>
</a>
<a class="flex flex-row gap-1" href="/#">
<span class="text-neutral-200 ellip"> Graphic Design</span>
<span class="text-neutral-500"> (10)</span>
</a>
</div>
</div>

Related

Aligning bar chart columns and text with CSS

I have a component where the generated HTML is for a simplistic bar chart. The height and background colour are computed in the component. This works fine but I want to solve the issue of long text causing displacement of the bar above it.
There is also the issue of the width of the bars wrongly depending on the width of the text too, but that's probably another post.
Chart when viewport is wide enough:
Chart when viewport is smaller (this is the problem I wish to solve):
I think the rest of the bars and their labels need offsetting?
<ul class="flex gap-3 items-end">
<li class="flex flex-col flex-grow gap-1 content-center">
<span style="height:42.666666666666664px;background-color:#d73027" title="Apple - 10">
</span>
<div class="text-sm text-center">Apple</div>
</li>
<li class="flex flex-col flex-grow gap-1 content-center">
<span style="height:128px;background-color:#f46d43" title="Very Long Banana - 30">
</span>
<div class="text-sm text-center">Very Long Banana</div>
</li>
<li class="flex flex-col flex-grow gap-1 content-center">
<span style="height:64px;background-color:#fdae61" title="Orange - 15">
</span>
<div class="text-sm text-center">Orange</div>
</li>
<li class="flex flex-col flex-grow gap-1 content-center">
<span style="height:106.66666666666667px;background-color:#fee08b" title="Grape - 25">
</span>
<div class="text-sm text-center">Grape</div>
</li>
</ul>
</div>
As someone mentioned in the comments, there are various ways to solve the issues, this is just one way.
Edit: See #MagnusEffect's answer for a much simpler option.
If you want to keep your layout as it is, i.e., using an unordered list as a container for both the bars and the labels, you can wrap all bars with a fixed size div for the vertical alignment. Otherwise you could divide the bars and the labels in two different rows with equally sized items. I positioned the items within the wrapper divs using absolute positioning of the children, you can use flex box here as well.
You can use flex-basis together with word-wrap for equal widths across the flex items. Some kind of overflow for the text can be an alternative to word-wrap.
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body>
<ul class="flex gap-3 items-start" style="width: 270px; resize: both; overflow: auto; border: 1px solid black">
<li class="flex flex-col basis-0 flex-grow gap-1">
<div class="relative" style="height: 128px;">
<span class="absolute w-full bottom-0" style="height:42.666666666666664px;background-color:#d73027" title="Apple - 10"></span>
</div>
<div class="text-sm text-center" style="word-wrap: anywhere;">Apple</div>
</li>
<li class="flex flex-col basis-0 flex-grow gap-1">
<div class="relative" style="height: 128px">
<span class="absolute w-full bottom-0" style="height:128px;background-color:#f46d43" title="Very Long Banana - 30"></span>
</div>
<div class="text-sm text-center" style="word-wrap: anywhere;">Very Long Banana</div>
</li>
<li class="flex flex-col basis-0 flex-grow gap-1">
<div class="relative" style="height: 128px">
<span class="absolute w-full bottom-0" style="height:64px;background-color:#fdae61" title="Orange - 15"></span>
</div>
<div class="text-sm text-center" style="word-wrap: anywhere;">Orange</div>
</li>
<li class="flex flex-col basis-0 flex-grow gap-1">
<div class="relative" style="height: 128px">
<span class="absolute w-full bottom-0" style="height:106.66666666666667px;background-color:#fee08b" title="Grape - 25"></span>
</div>
<div class="text-sm text-center" style="word-wrap: anywhere;">Grape</div>
</li>
</ul>
</body>
</html>
As mentioned , since you are using items-end , it is using the end (text) to align the object.
Replace it with items-baseline class and also add flex-row to the <ul>.
So the code looks like this
<ul class="flex gap-3 flex-row items-baseline">
<li class="flex flex-col flex-grow gap-1 content-center">
<span style="height:42.666666666666664px;background-color:#d73027" title="Apple - 10">
</span>
<div class="text-sm text-center">Apple</div>
</li>
<li class="flex flex-col flex-grow gap-1 content-center">
<span style="height:128px;background-color:#f46d43" title="Very Long Banana - 30">
</span>
<div class="text-sm text-center">Very Long Banana</div>
</li>
<li class="flex flex-col flex-grow gap-1 content-center">
<span style="height:64px;background-color:#fdae61" title="Orange - 15">
</span>
<div class="text-sm text-center">Orange</div>
</li>
<li class="flex flex-col flex-grow gap-1 content-center">
<span style="height:106.66666666666667px;background-color:#fee08b" title="Grape - 25">
</span>
<div class="text-sm text-center">Grape</div>
</li>
</ul>
</div>
You can check the demonstration here on tailwind play
Please try to add the CSS for the text using VW method.
Example: font-size: 16vw;
Please check below reference link:
https://css-tricks.com/viewport-sized-typography/

Different items height inside of div when using flexbox(TailwindCSS)

I am using Flex in tailwind in one my main div container to align the items inside of it horizontal
but somehow the items are of different sizes in the row the image link is below any fixes for it?
i have tried using height utility class but it just messes up the entire page.
[1]: https://i.stack.imgur.com/Yjs51.jpg
HOME
ORDERS
MENU CARD
FAQs
ABOUT
Butter Chicken
If you haven't tried butter chicken, you don't know what you'r missing.
</div>
</div>
</a>
<a href="butterchicken.html">
<div class="max-w-sm rounded overflow-hidden shadow-lg justify-center">
<img class= "w-full" src="images/download (1).jpg" alt="malai-chicken">
<div class="px-6 py-8">
<div class="font-extrabold text-xl pb-3">Malai Chicken</div>
<div>
<p class=" font-serif text-base mb-3">Clean as white and appetizing.</p>
</div>
</div>
</div>
</a>
</a>
<a href="butterchicken.html">
<div class="max-w-sm rounded overflow-hidden shadow-lg justify-center">
<img class= "w-full" src="images/download (2).jpg" alt="Shahi Paneer">
<div class="px-6 py-8">
<div class="font-extrabold text-xl pb-3">Shahi Paneer</div>
<div>
<p class=" font-serif text-base mb-3">First Pick of Royales.</p>
</div>
</div>
</div>
</a>
</div>

tailwind - position icon left within a tag where text is centered

I am trying to position icon to the left side of a Link and have the text centered at the same time.
<div className="max-w-screen-2xl mx-auto sm:px-6 lg:px-8">
<Link
href="#"
className="px-6 py-3 mt-2 flex justify-center text-center"
>
<DocumentTextIcon
className="ml-1 mt-1 -mr-1 h-10 w-10"
aria-hidden="true"
/>
<p>
Some random text </p>
</Link>
</div>
With this the icon is in the middle with the text. I can push to the right with margin left but then it is not dynamic. Any idea how I can push the icon to the left and it remains dynamic?
Try this way:
<div class="my-10 flex items-center justify-center bg-gray-100 w-40">
<div class="flex-1">
<span class="mr-auto">icon</span>
</div>
<p>text</p>
<div class="flex-1"></div>
</div>
<div class="my-10 flex items-center justify-center bg-gray-100 w-80">
<div class="flex-1">
<span class="mr-auto">icon</span>
</div>
<p>with long text</p>
<div class="flex-1"></div>
</div>
Demo

Link using id tag hides Title content of a div

So i have been working on a project. But Clicking on Footer link hides the title portion of the id like the 2nd image . is there any way to show it like the 3rd pic . Tried adding padding top to the id element still not working. Showing this
Want to show like this
My Footer Code
<!-- Tailwind -->
<link href="https://unpkg.com/tailwindcss#^2/dist/tailwind.min.css" rel="stylesheet">
<!-- Body -->
<div class="w-full px-4 md:w-1/3">
<h2 class="mb-3 text-2xl tracking-widest title-font text-textC font-futuraB">
TOP SERVICES</h2>
<ul class="mb-10 list-none font-futuraL">
<li class="py-0.5">
Brand strategy
</li>
<li class="py-0.5">
Identity Design
</li>
<li class="py-0.5">
Marketing & Development
</li>
<li class="py-0.5">
<a rel="noopener noreferrer" href="http://ignition.brandheft.com/" class="text-textAltC hover:text-accentC">Printing Services</a>
</li>
</ul>
</div>
Div Element having the issue
<!-- Tailwind -->
<link href="https://unpkg.com/tailwindcss#^2/dist/tailwind.min.css" rel="stylesheet">
<!-- Body -->
<div class="flex flex-wrap justify-center mx-auto lg:w-4/5 service_container_1" id="strategy">
<div class="order-first object-cover object-center rounded lg:w-1/2">
<img class="w-full h-72 lg:h-auto service_img_1" src="https://via.placeholder.com/300.jpg">
</div>
<div class="w-full my-auto mb-6 text-center lg:w-1/2 lg:pr-10 lg:py-6 lg:mb-0 font-futuraM lg:text-left">
<h1 class="pt-12 mb-4 text-5xl font-medium text-textC">Brand Strategy</h1>
<p class="mb-4 text-base leading-relaxed lg:text-lg text-textAltC first-letter:text-accentC first-letter:text-xl lg:first-letter:text-2xl font-futuraL">Whether you want to be remembered by your customers, connect with your audience, or increase the prices of your products by showing them the value, you need to differentiate yourself from your competitors. Differentiating doesn't always mean providing
a totally different product or service. Differentiating means adding a little something extra that'll make a huge impact. That naturally comes from your vision but you need to mine it using a proper brand strategy. A brand strategy encompasses your
company's mission, promises to your customers, and a plan to communicate the same to your audience. Here's how we can help you draft a successful brand strategy.</p>
<div class="space-y-2">
<div class="flex flex-col justify-between space-y-2 lg:space-y-0 lg:flex-row">
<span class="text-accentC">Brand purpose</span>
<span class="text-accentC">Target audience</span>
</div>
<div class="flex flex-col justify-between space-y-2 lg:space-y-0 lg:flex-row">
<span class="text-accentC">Brand attributes</span>
<span class="text-accentC">Brand book</span>
</div>
<div class="flex flex-col justify-between space-y-2 lg:space-y-0 lg:flex-row">
<span class="text-accentC">Brand mission statement</span>
<span class="text-accentC">Brand voice</span>
</div>
<div class="flex flex-col justify-between space-y-2 lg:space-y-0 lg:flex-row">
<span class="text-accentC">Brand personality</span>
<span class="text-accentC">Brand kit</span>
</div>
</div>
<div class="flex mt-10">
Get a Quote
</div>
</div>
</div>
LIVE WEBSITE

Can't make space in between hamburger - Tailwind CSS

I tried using space-y-2 and leading but I still can't put gaps between them.
<a href="" class="bg-blue-dark lg:hidden">
<span class="block w-7 h-1 mb-1"></span>
<span class="block w-7 h-1 mb-1"></span>
<span class="block w-7 h-1"></span>
</a>
According to your current code, there is space between your hamburger bars because you have used the margin-bottom class i.e mb-1.
Another approach would be to make the bars flex items, then arrange them column-wise and justify the content. Remember to add a certain height to your flex box container.
<a href="" class="bg-blue-dark lg:hidden h-5 flex flex-col justify-between">
<span class="block w-7 h-1"></span>
<span class="block w-7 h-1"></span>
<span class="block w-7 h-1"></span>
</a>
*If bg-blue-dark is your custom class to add colour to the bars then add it to the <span> tags instead of the <a> tag.

Categories