Tailwind CSS truncate destroys design - css

I am working on a table using Tailwind CSS, I have a long string, which I would like to truncate, but when I apply truncate the layout breaks
<div>
<!-- START TABLE ROW -->
<div
id="tableRow"
class="grid grid-cols-5 gap-4 border-2 border-transparent hover:border-2 hover:border-me-green hover:rounded-lg"
>
<!-- 1. Table column -->
<div class="px-6 py-4">
<div class="flex items-center space-x-3">
<div>
<p class="font-bold text-black my-2">ProtoPrograma</p>
<p class="text-gray-400 text-sm font-roboto truncate w-[950px]">
[Normal text] Suspendisse nec libero id ligula mollis
ullamcorper quis vitae dui. Mauris vel. Neque porro quisquam est
qui dolorem ipsum quia dolor sit...123, blah, blah, blah, blah, blah
</p>
</div>
</div>
</div>
<!-- 2. Table column -->
<div class="px-6 py-4">
<div>
<p class="text-xl font-roboto font-medium text-black">
1.3.2019 - v6
</p>
<p class="text-me-gray text-sm font-roboto"></p>
</div>
</div>
<!-- Draw line -->
<div class="w-full border-t border-me-gray-2"></div>
<!-- Draw line -->
<!-- END TABLE ROW -->
</div>
Here is an example: https://play.tailwindcss.com/pEpWLfzCvl
The layout (when text is truncated) should look like
this
but as soon as I apply truncate property, and assign insame width (there is probably a better way, then asigning large widths, maybe number of words or something,which I don't know)
the table layout gets completly broken
How can apply truncate so it will truncate text and not break the layout along the way?
Thanks for Anwsering and Best Regards

Adding w-full on the parent div and delete the fixed width 950px fix the problem.
If you need to truncate with multiple line you can npm install #tailwindcss/line-clamp and adding line-clamp class.
If you do not want to install extra package, you can just add -webkit-line-clamp property into css stylesheet.
Example:
<div class="w-full">
<p class="my-2 font-bold text-black">ProtoPrograma</p>
<p class="font-roboto text-sm text-gray-400 line-clamp-6">[Normal text] Suspendisse nec libero id ligula mollis ullamcorper quis vitae dui. Mauris vel. Neque porro quisquam est qui dolorem ipsum quia dolor sit...123, blah, blah, blah, blah, blah</p>
</div>

Related

Gap Between Cards in Tailwind

I want to have multiple of this Tailwind card component that I found. I'm trying to get ride of the weird gap between the two cards, I'm not sure whats causing it. I added the gap-0 to the parent div so I don't understand why it's still there. I'm also having trouble understanding why the content is not in the middle of page and starting at the top left.
Here is the Tailwind playground link: https://play.tailwindcss.com/wPqTqYp1jr
The m-4 in each component is causing margin between the two cards. You can remove the gap by adding mr-0 in the first and ml-0 in the second card.
Below is the code
<div class="grid grid-cols-2 gap-0">
<!-- component -->
<div class="m-4 mr-0 my-20 max-w-md rounded-lg bg-pink-100 py-4 px-8 shadow-lg">
<div class="-mt-16 flex justify-center md:justify-end">
<img class="h-14 w-14 rounded-full border-2 border-indigo-500 object-cover" src="https://images.unsplash.com/photo-1499714608240-22fc6ad53fb2?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80" />
</div>
<div>
<p class="mt-2 text-gray-600">Lorem ipsum dolor sit amet consectetur adipisicing elit. Quae dolores deserunt ea doloremque natus error, rerum quas odio quaerat nam ex commodi hic, suscipit in a veritatis pariatur minus consequuntur!</p>
</div>
<div class="mt-4 flex justify-end">
Bob Smith
</div>
</div>
<!-- component -->
<div class="ml-0 my-20 max-w-md rounded-lg bg-blue-100 py-4 px-8 shadow-lg">
<div class="-mt-16 flex justify-center md:justify-end ">
<img class="h-14 w-14 rounded-full border-2 border-indigo-500 object-cover" src="https://images.unsplash.com/photo-1499714608240-22fc6ad53fb2?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80" />
</div>
<div>
<p class="mt-2 text-gray-600">Lorem ipsum dolor sit amet consectetur adipisicing elit. Quae dolores deserunt ea doloremque natus error, rerum quas odio quaerat nam ex commodi hic, suscipit in a veritatis pariatur minus consequuntur!</p>
</div>
<div class="mt-4 flex justify-end">
Virginia Lucas
</div>
</div>
</div>
Use tailwind play and check the above code there . Also added bg-color to differentiate between the two cards.
EDIT -1
Just remove the grid grid-cols-2 gap-0 from the main div and add flex flex-row to that div. Then you will not see any gap even in fullscreen also.
Please preview here
This is my proposition:
Instead of grid i suggest using flexbox. I used additional properties to center the cards items-center justify-center h-screen
Remove all margin and padding from the first divs of the card: m-4 my-20 & py-4 px-8. Later, You can adjust it as desired.
You can now use gap property as much as You want ;-) In parent div.
Good Luck and Best regards !
<!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>
<div class="flex items-center justify-center h-screen gap-0">
<!-- component -->
<div class="max-w-md rounded-lg bg-white shadow-lg">
<div class="-mt-16 flex justify-center">
<img
class="h-14 w-14 rounded-full border-2 border-indigo-500 object-cover"
src="https://images.unsplash.com/photo-1499714608240-22fc6ad53fb2?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80"
/>
</div>
<div>
<p class="mt-2 text-gray-600">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quae
dolores deserunt ea doloremque natus error, rerum quas odio quaerat
nam ex commodi hic, suscipit in a veritatis pariatur minus
consequuntur!
</p>
</div>
<div class="mt-4 flex justify-end">
Bob Smith
</div>
</div>
<!-- component -->
<div class="max-w-md rounded-lg bg-white shadow-lg">
<div class="-mt-16 flex justify-center">
<img
class="h-14 w-14 rounded-full border-2 border-indigo-500 object-cover"
src="https://images.unsplash.com/photo-1499714608240-22fc6ad53fb2?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80"
/>
</div>
<div>
<p class="mt-2 text-gray-600">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quae
dolores deserunt ea doloremque natus error, rerum quas odio quaerat
nam ex commodi hic, suscipit in a veritatis pariatur minus
consequuntur!
</p>
</div>
<div class="mt-4 flex justify-end">
<a href="#" class="text-sm font-medium text-indigo-500"
>Virginia Lucas</a
>
</div>
</div>
</div>
</body>
</html>

Tailwind CSS truncate after filling a space

I am building a card with Tailwind CSS and Vue.js. I want to fill a space on my card with text and truncate any remaining text that doesn't fit with an ellipsis.
I have applied Tailwinds .truncate class however it only allows me to have 1 line of text before the ellipsis. I have also looked into the line-clamp property but I was hoping there would be a nicer way to do this with Tailwind.
<template>
<div class="p-6 w-full bg-white rounded-lg overflow-hidden shadow-lg border">
<div class="flex flex-col sm:flex-row">
<img src="img/card-default.jpg" class="mx-auto" alt="Card">
<div class="mt-4 overflow-hidden sm:ml-4 flex flex-col justify-between">
<div>
<h2 class="text-gray-900 font-semibold text-lg">Title</h2>
<p class="truncate mt-2 text-gray-700 max-h-full">
Lorem ipsum, dolor sit amet consectetur adipisicing elit.
Tempore repellat labore distinctio maxime, debitis autem perferendis dolore,
deleniti doloribus quia vel! Amet nisi, a vel modi officiis sapiente fugiat,
illum delectus, incidunt repellendus suscipit. Delectus iusto eligendi, doloribus amet et fugiat,
atque perspiciatis eveniet, ipsum inventore sed placeat sapiente maiores.
</p>
</div>
<div class="flex justify-around mt-4 mx-2 sm:mx-0">
<button class="mx-2 bg-indigo-600 p-2 rounded-lg text-white hover:bg-indigo-500 sm:mx-0">Button 1</button>
<button class="mx-2 bg-indigo-600 p-2 rounded-lg text-white hover:bg-indigo-500 sm:mx-0">Button 2</button>
</div>
</div>
</div>
</div>
</template>
Short answer: Nope their isn’t a nicer solution for this.
tailwind is meant to be cover the ‘basics’ like padding, margin, grid etc for developers/designers so they can create easily and fast pages/components.
What you are using/asking is totally custom for your situation only.
Possible solution for your problem:
Write a tailwind plug-in that extends the default tailwind css
Extend tailwind.scss with your custom css
Or just css (in-line or just your custom css file)
Use the #tailwind/line-clamp plugin
<p className="line-clamp-n"> where n stands for the number of lines you want before truncating
A solution that worked for me was to put a max-height on the <p> tag

How do I keep aspect ratio with padding for a card image on mobile display?

When I add padding around an image at the top of a card when in dev tools mobile view, the image doesn't keep aspect ratio. When I go back to full size view the aspect ratio is fine.
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="card-deck">
<div class="card bg-primary product-card--style mb-3">
<img src="https://dummyimage.com/500x500/8A8A8A/fff" alt="asdf" class="card-img-top product-card--img p-5">
<div class="card-body product-card--layout">
<h5 class="card-title">Product 1</h5>
<h6 class="card-subtitle">For people who..</h6>
<p class="card-text">Lorem ipsum dolor sit, amet consectetur adipisicing elit. Alias sit illo eaque nulla aliquid tempora sapiente minus consequuntur atque! Iusto.</p>
More info
</div>
</div>
</div>
My code
Image of how it looks in dev tool mobile
The thing is if I go to my code pen in dev tools mobile view it seems to be working as it should, but from my file it isn't. This is the reason I'm so confused about it.
You wanted to maintain aspect ratios, does this work for you ?
.card { display:block !important; }
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="card-deck">
<div class="card bg-primary product-card--style mb-3">
<img src="https://dummyimage.com/500x500/8A8A8A/fff" alt="asdf" class="card-img-top product-card--img p-5">
<div class="card-body product-card--layout">
<h5 class="card-title">Product 1</h5>
<h6 class="card-subtitle">For people who..</h6>
<p class="card-text">Lorem ipsum dolor sit, amet consectetur adipisicing elit. Alias sit illo eaque nulla aliquid tempora sapiente minus consequuntur atque! Iusto.</p>
More info
</div>
</div>
</div>

Why does Scrollspy target the outer div instead of the ul?

So my confusion is that the Scrollspy is targeting the outer div instead of the actual element it is modifying. I'm trying to understand why that is the case?
The code in question is line 12 and 89-90 here:
http://4f7ba83874222b00ae84-8c55136fa379d9b2d1adde446f45d068.r28.cf2.rackcdn.com/scrollspy.html
Tried my best to include relevant part here:
<body data-spy="scroll" data-target="#myScrollspy">
<div class="container">
<div class="row">
<div class="col-xs-10 col-sm-10 col-md-10 col-lg-10">
<h1 id="p_1">Part 1</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut et felis consequat velit sollicitudin fermentum....
</p>
<h1 id="p_2">Part 2</h1>
<p>
Maecenas massa eros, aliquam id nisi ut, venenatis eleifend diam....
</p>
<h1 id="p_3">Part 3</h1>
<p>
Quisque id luctus tortor, a scelerisque nulla....
</p>
<h1 id="p_4">Part 4</h1>
<p>
Nam sed volutpat sapien....
</p>
</div>
<div class="col-xs-2 col-sm-2 col-md-2 col-lg-2" id="myScrollspy">
<ul class="nav nav-pills nav-stacked affix">
<li class="active">Part 1</li>
<li>Part 2</li>
<li>Part 3</li>
<li>Part 4</li>
</ul>
</div>
</div>
</div>
</body>
It actually target parent element of any Bootstrap navigation component.
It'd work too if u put the data-target to the ul nav class..

Horizontally Aligning Bootstrap 3.3.5 Columns inside a row in Wordpress

Re: Bootstrap 3.3.5 in Wordpress
I have not seen this issue before. All I want to do is align 3 x .col-md-4 .wells inside a row, but they just won't align. The first div is always a bit higher; see screenshot.
This is the code:
<div class="row">
<div class="col-xs-12 col-sm-10 col-sm-offset-1 col-md-4 col-md-offset-0 col-lg-4 col-lg-offset-0 text-center">
<a class="page-scroll" href="#how-to"><div class="home-plans well">
<br/>
<h2>1.</h2>
<p class="lead text-left">Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin commodo.p>
</div> <!-- /well --></a>
</div> <!-- /col-md-4 -->
<div class="col-xs-12 col-sm-10 col-sm-offset-1 col-md-4 col-md-offset-0 col-lg-4 col-lg-offset-0 text-center">
<div class="home-plans well">
<br />
<h2>2.</h2>
<p class="lead text-left">Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin commodo.p>
</div> <!-- /well -->
</div> <!-- /col-md-4 -->
<div class="col-xs-12 col-sm-10 col-sm-offset-1 col-md-4 col-md-offset-0 col-lg-4 col-lg-offset-0 text-center">
<div class="home-plans well">
<br />
<h2>3.</h2>
<p class="lead text-left">Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin commodo.</p>
</div> <!-- /well -->
</div> <!-- /col-md-4 -->
</div>
Using f12 tools in explorer, the issue seems to be the below CSS code styling the row:
/*media all*/
.btn-group-vertical > .btn-group::after, .btn-group-vertical > .btn-group::before, .btn-toolbar::after, .btn-toolbar::before, .clearfix::after, .clearfix::before, .container-fluid::after, .container-fluid::before, .container::after, .container::before, .dl-horizontal dd::after, .dl-horizontal dd::before, .form-horizontal .form-group::after, .form-horizontal .form-group::before, .modal-footer::after, .modal-footer::before, .nav::after, .nav::before, .navbar-collapse::after, .navbar-collapse::before, .navbar-header::after, .navbar-header::before, .navbar::after, .navbar::before, .pager::after, .pager::before, .panel-body::after, .panel-body::before, .row::after, .row::before {
display: table;
content: " ";
}
This page is in Wordpress. I have tried the same code in a normal HTML page and the .well .col-md-4s align OK.
To get the cols to align I can just remove the row, but I want to use rows.
This has been killing me for nearly one day now. I have done loads of research and tried using clearfix and clear: both all over without joy. Can anyone shed some light on this please?
Edit: I also note that the two rows in the footer section are causing the page footer to have a scroll bar? So, I have had to remove those rows too. It seems that I can't use rows in Wordpress with Bootstrap anymore for some reason.
Hmm, it's really tricky to say without seeing more of the CSS but have you tried reformatting your first div as follows:
<div class="col-xs-12 col-sm-10 col-sm-offset-1 col-md-4 col-md-offset-0 col-lg-4 col-lg-offset-0 text-center">
<div class="home-plans well">
<a class="page-scroll" href="#how-to">
<br/>
<h2>1.</h2>
<p class="lead text-left">Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin commodo.p>
</a>
</div> <!-- /well -->
</div> <!-- /col-md-4 -->
Then styling the inner anchor element as follows:
CSS:
.well > a {
display: block;
}
I'd guess that it's something to do with the anchor element wrapping around the .well div?

Resources