Text is doesn't fill the whole div, only a portion in the middle - html

In short, my problem is this:
I'm using TailWind on Laravel, I can't get the text inside the border to fit the whole div he's in, and it's weirdly centered this way where the amount of characters per line is limited
I tried many approaches like changing and trying different values of padding and margin but I was unsuccessful, it only makes the div bigger but the text is still awfully centered and limited.
the code portion is as follows:
<div class="mx-4">
<x-card class="p-10">
<div
class="flex flex-col items-center justify-center text-center"
>
<img
class="w-48 mr-6 mb-6"
src="{{$album->logo? asset('storage/'.$album->logo) : asset('/images/noalbum.png')}}"
alt=""
/>
<h3 class="text-2xl mb-2">{{$album->title}}</h3>
<div class="text-xl font-bold mb-4">{{$album->artist}}</div>
<x-insidetags :tagscsv="$album->tags"/>
<div class=" w-full mb-6 mt-5">
<h3 class="text-3xl font-bold">
About the album
</h3>
</div>
<div>
<div class="flex">
<div class="px-20 text-lg border border-black text-left">
<h3 class="font-bold">Track List :</h3>
#foreach($tracks as $track)
<p>- {{$track}}</p>
#endforeach
</div>
<div class="text-lg space-y-6 ml-10">
<div class="text-left py-10">
{{$album->description}}
</div>
<a
href="{{$album->website}}"
target="_blank"
class=" bg-black text-laravel mt-16 py-2 px-10 rounded-xl hover:opacity-80"
><i class="fa-solid fa-globe"></i> Visit RateYourMusic page</a
>
</div>
</div>
</div>
</div>
For refrence I'm trying to create something like this, but only with the name of the tracks for the moment

I figured it out, added flex 1 1 0% and flex 4 1 0% to the two divs
<div class=" text-lg shadow-xl text-left flex-1 h-fit p-5">
<h3 class="font-bold">Track List :</h3>
#foreach($tracks as $track)
<p>- {{$track}}</p>
#endforeach
</div>
<div class="text-lg ml-10 flex-[4_1_0%]">
<div class="text-left py-10">
{{$album->description}}
</div>
<a
href="{{$album->website}}"
target="_blank"
class=" bg-black text-laravel mt-16 py-2 px-10 rounded-xl hover:opacity-80"
><i class="fa-solid fa-globe"></i> Visit RateYourMusic page</a
>
</div>

Related

Reduce tailwind image to the smallest

I have added images on my page using tailwinds but on mobile, the image still appears to be bigger than I want.
My code below:
<script src="https://cdn.tailwindcss.com"></script>
<div class="max-w-md mx-auto bg-white hover:bg-gray-200 py-3 px-6 border-b border-gray-300 overflow-hidden md:max-w-2xl">
<div class="flex">
<div class="md:shrink-0">
<img class="h-40 w-full scale-75 object-cover md:h-full md:w-48" src="https://images.unsplash.com/photo-1488998427799-e3362cec87c3?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=870&q=80" alt="Man looking at item at a store">
</div>
<div class="p-4">
<div class="uppercase tracking-wide text-sm text-indigo-500 font-light">Course</div>
How to Organize Your Time and Your Life
<p class="mt-2 ">By: Pete Mockaitis | How to Be Awesome at Your Job</p>
<span class="text-sm text-slate-500">134,768 Viewers. Released Jun 19, 2022</span>
</div>
</div>
</div>
What I get
What I want
I think the best way to make a website responsive is by using display: grid;>. I think this solves your problem:
<script src="https://cdn.tailwindcss.com"></script>
<div class="max-w-md mx-auto bg-white hover:bg-gray-200 py-3 px-6 border-b border-gray-300 overflow-hidden md:max-w-2xl grid grid-cols-3 gap-4">
<img class="h-30 w-full col-span-1 object-cover md:h-full md:w-48" src="https://images.unsplash.com/photo-1488998427799-e3362cec87c3?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=870&q=80" alt="Man looking at item at a store">
<div class="col-span-2">
<div class="uppercase tracking-wide text-sm text-indigo-500 font-light">Course</div>
How to Organize Your Time and Your Life
<p class="mt-2 ">By: Pete Mockaitis | How to Be Awesome at Your Job</p>
<span class="text-sm text-slate-500">134,768 Viewers. Released Jun 19, 2022</span>
</div>
</div>

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

How to break the line when I am viewing this website in mobile format. I have used Tailwindcss, jinja and flask to generate this website

instead of the "..." in the end of the title in mobile view how do I get to break the line so that the entire title is visible.
i have tried applying span but it doesn't work either. please help.
<div class="bg-indigo-700 px-4 py-5 border-b rounded-t sm:px-6">
<h3 class="text-lg leading-6 font-medium text-white">
Choose the clip you want and download.
</h3>
</div>
<div class="bg-white shadow overflow-hidden sm:rounded-md">
<ul class="divide-y divide-gray-200">
{%for links in url_dict:%}
<li>
<a class="block hover:bg-gray-50">
<div class="px-4 py-4 sm:px-6">
<div class="flex items-center justify-between">
<!-------------------------------------------TITLE OF THE VIDEO--------------------------->
<h3 class="text-sm font-thin text-gray-700 truncate">
<a href='{{links}}'>{{url_dict[links][0]}}</a>
</h3>
<!----------------------------------------DOWNLOAD BUTTON---------------------------------->
<div class="ml-2 flex-shrink-0 flex">
<p class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 hover:bg-green-200 text-green-800 hover:text-green-700">
Download
</p>
</div>
</div>
<div class="mt-2 sm:flex sm:justify-between">
<div class="sm:flex">
<p class="flex items-center text-sm font-light text-gray-500">
length: {{url_dict[links][1]}}
</p>
</div>
</div>
</div>
</a>
</li>
{% endfor %}
</ul>
<button type="button" class="inline-flex items-center m-4 px-4 py-1.5 border border-transparent text-xs font-medium rounded shadow-sm text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
View more
</button>
</div>
You need to remove the truncate class from the <h3> element in the mobile view.
Use md: to indicate that truncate class is applicable only on medium and large screens
<!-------------------------------------------TITLE OF THE VIDEO--------------------------->
<h3 class="text-sm font-thin text-gray-700 md:truncate">
<a href='{{links}}'>{{url_dict[links][0]}}</a>
</h3>

How to implement Tailwind grids with horizontal spacing without wrapping to the next line?

I have a section with the following contents:
<section class="flex flex-wrap -mx-2">
<Card
v-for="(course, index) in courses"
:key="index"
:title="course.title"
:professor="course.professor"
:price="course.price"
:excerpt="course.excerpt"
:image="course.image"
:category="course.category"
/>
</section>
A Card looks like this:
<article class="bg-red mt-5 px-2 w-full md:w-1/2 lg:w-1/3 xl:w-1/3 shadow-md rounded bg-white">
<nuxt-link to="/courses/example-course">
<img :src="`/images/${image}`" :alt="title" class="rounded-t w-full">
</nuxt-link>
<div class="p-4">
<header class="flex justify-between">
<section>
<h3 class="text-gray-700">
<nuxt-link to="/courses/example-course" class="hover:text-gray-600" v-text="title"></nuxt-link>
</h3>
<p class="text-gray-600 mt-1" v-text="professor"></p>
</section>
<div v-if="price">
<span class="px-2 py-1 bg-green-200 text-green-500 font-bold rounded">${{ price }}</span>
</div>
</header>
<article class="text-gray-700 mt-2" v-text="excerpt"></article>
</div>
<footer class="border-t border-gray-300 uppercase p-5 flex justify-between">
<span class="text-gray-600 text-xs font-bold self-center" v-text="category"></span>
<a href="#" class="text-gray-600 hover:text-blue-600">
<i v-if="price" class="fa fa-user"></i>
</a>
</footer>
</article>
And the outcome of all this looks like this:
As you can see, the cards are touching each other, despite me following what the Tailwind's docs say on grid spacing. I have tried adding ml-2 on the <article> tags, but that just results in wrapping the element prematurely and leaving out too much space.
What am I doing wrong here and how to add a gap between the cards? Thanks!
The "problem" with margin is that it lives on the outside of the box(model) of your element, e.g. it affects the total width of your card. For example on large screens you want them to be 33.33% wide, but if you add margin on the left/right, the card will have a width of 33.33% + margin which makes the flexbox container wrap after two items because otherwise the total width would be more than 100%. You can solve this by a) setting things to box-sizing: border-box (doesn't help with margin tough!) and b) use padding instead of margin to create the gaps, this usually requires some kind of wrapper around your content that does nothing else than dealing with spacing and sizing, something like this:
<article class="mt-5 px-2 w-full md:w-1/2 lg:w-1/3 xl:w-1/3">
<div class="card bg-red shadow-md rounded bg-white">
<nuxt-link to="/courses/example-course">
<img :src="`/images/${image}`" :alt="title" class="rounded-t w-full">
</nuxt-link>
<div class="p-4">
<header class="flex justify-between">
<section>
<h3 class="text-gray-700">
<nuxt-link to="/courses/example-course" class="hover:text-gray-600" v-text="title"></nuxt-link>
</h3>
<p class="text-gray-600 mt-1" v-text="professor"></p>
</section>
<div v-if="price">
<span class="px-2 py-1 bg-green-200 text-green-500 font-bold rounded">${{ price }}</span>
</div>
</header>
<article class="text-gray-700 mt-2" v-text="excerpt"></article>
</div>
<footer class="border-t border-gray-300 uppercase p-5 flex justify-between">
<span class="text-gray-600 text-xs font-bold self-center" v-text="category"></span>
<a href="#" class="text-gray-600 hover:text-blue-600">
<i v-if="price" class="fa fa-user"></i>
</a>
</footer>
</div>
</article>
I know it is kind of annoying to clutter up the markup like that, but its usually worth it =).
EDIT: It is actually as the docs say
Add a negative horizontal margin like -mx-2 to your column container and an equal horizontal padding like px-2 to each column to add gutters.
your issue is with the box-shadow that then doesn't let you create a visual gap, so technically you need the wrapper because of your box-shadow!