float right button without going outside parent div tailwindcss - css

I am trying to float a button to the right of a card. I want it to appear in the bottom righthand corner.
When I use a float right. It appears outside the parent div, is there a way to position it correctly?
<div class="m-10">
<div>
<div class="bg-white shadow-lg border-grey w-1/3 ">
<div class="p-4 flex">
<div class="pt-3 text-center font-bold text-2xl w-16 h-16 bg-grey-lightest">
D
</div>
<div class="ml-4">
Team Name
</div>
</div>
<div class="float-right">
<a :href="'/company/' + team.id">
<button class="ml-2 bg-blue hover:bg-blue-dark text-white text-sm font-bold rounded p-2">
View
</button>
</a>
</div>
</div>
</div>
</div>
I have a running sandbox here with the code
https://codesandbox.io/s/tailwind-css-nl0ph

Instead of using the float-right class use text-right

You just need to apply float-right to the button element instead of the parent div
<div class="m-10">
<div>
<div class="bg-white shadow-lg border-gray-400 w-1/3">
<div class="p-4 flex">
<div class="pt-3 text-center font-bold text-2xl w-16 h-16 bg-gray-200">
D
</div>
<div class="ml-4">Team Name</div>
</div>
<div class="h-fit min-h-full flex justify-end">
<a href="'/company/' + team.id">
<button class="float-right ml-2 bg-blue-400 hover:bg-blue-600 text-white text-sm font-bold rounded px-2 py-1">
View
</button>
</a>
</div>
</div>
</div>
</div>

Add this new class to clear floating element
.clearfix::after {
content: "";
clear: both;
display: table;
}
and then apply that class to the containing div (parent div of the button)
source: https://www.w3schools.com/howto/howto_css_clearfix.asp

Related

I want hover card to animation for images use css tailwind but it don't work

<html>
<body>
<div class="group card my-14 mx-3 w-80 h-100 bg-gray-800 rounded-xl text-white p-5 cursor-pointer">
<div class=" flex justify-between items-center text-2xl ">
<i class='bx bx-heart'></i>
<i class='bx bx-cart-alt'></i>
</div>
<div class="w-11/12 ml-2.5 group-hover:text-white group-hover:-rotate-20">
<img class="object-cover w-full h-full" src="./Images/Jordan.png" id="bannerImage" alt="">
</div>
<div class="text-center uppercase text-xl text-green-600">
Jordan 1 <br>
$299
</div>
</div>
</body>
</html>
Explain why Styling based on parent state doesn't work.
...................................
Tailwind doesn't have -rotate-20 utility class. Change it to one of known or use arbitrary value like group-hover:-rotate-[20deg]

How to place c2 children to the top and to the bottom of the parent in css?

I need to add 2 children of a parent element one on the top and another on the bottom. something like this.
and this is the code I have.
<div class=" w-full flex justify-betwen bg-white items-center">
<div class="ml-auto">
<img class="object-cover mr-2 md:mr-4 ml-2 md:ml-4 float-left h-40 lg:w-32 w-14 xs:w-16"
src="../img/Bless.png" alt="" />
</div>
<div class="w-full mx-8">
<div class="text-redfull text-ms xs:text-lg md:text-xl lg:text-2xl xl:text-3xl">
Some text here to top as a title.
</div>
<div
class=" text-gray70 flex justify-between items-center text-xs xs:text-base md:text-base lg:text-lg mb-0">
and this is the date to the bottom Uploaded Auguts 4, 2020
</div>
</div>
</div>
Title should stay at the top.
Date to the bottom.
If anyone knows:)
You can add two divs for Title and Date and add vertical margin to them.
I am not sure whether you want with the text or not so I had implemented for both the cases.
Case 1: With text
<script src="https://cdn.tailwindcss.com"></script>
<div class="justify-betwen flex w-full items-center bg-white">
<div class="ml-auto">
<img class="xs:w-16 float-left mr-2 ml-2 h-40 w-14 object-cover md:mr-4 md:ml-4 lg:w-32" src="http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/nebula_blue.s2014.png" alt="" />
</div>
<div class="mx-8 w-full">
<div class="text-3xl font-semibold text-red-900">Your Title here</div>
<div class="my-3">
<div class="text-ms xs:text-lg text-red-500 md:text-xl lg:text-2xl xl:text-3xl">Some text here to top as a title.</div>
<div class="xs:text-base mb-0 flex items-center justify-between text-xs text-gray-500 md:text-base lg:text-lg">and this is the date to the bottom Uploaded Auguts 4, 2020</div>
</div>
<div class="text-base font-extralight">25 June 2022</div>
</div>
</div>
Case 2: Without Text
<script src="https://cdn.tailwindcss.com"></script>
<div class="justify-betwen flex w-full items-center bg-white">
<div class="ml-auto">
<img class="xs:w-16 float-left mr-2 ml-2 h-40 w-14 object-cover md:mr-4 md:ml-4 lg:w-32" src="http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/nebula_blue.s2014.png" alt="" />
</div>
<div class="mx-8 w-full">
<div class="text-3xl font-semibold text-red-900">Your Title here</div>
<div class="my-12">
</div>
<div class="text-lg font-extralight">25 June 2022</div>
</div>
</div>
I had use an online image, so you can replace it with your image.
If You want more gap, then simply increase the my-12 to more.

Using flexbox (tailwindcss: flex-1) how do I add background colour to WHOLE element not just the text?

Looking for some help with my tabs design. I use a flexbox which has two parts. The top part for the main content, and the bottom for 'tab' buttons that would change the main content data based on the tab selected.
I want to be able to hover over the button and I want the WHOLE div housing this element to be highlighted (Different background colour) and when selected to be permanently highlighted with a different colour.
Currently when I hover ONLY the text inside the div gets highlighted + margin specified. How do I make the whole div change the background colour?
CodeSandbox
<template>
<!-- CONTAINER -->
<div
class="flex-col bg-gray-200 w-11/12 rounded-xl border-2 m-auto pt-2 mt-2"
>
<!-- MAIN CONTENT -->
<div class="flex pb-2 bg-green-500 py-10">MAIN CONTENT</div>
<!-- Tabs -->
<div class="flex w-full text-sm text-center items-center bg-blue-500">
<div class="flex-1 px-1">
<div class="flex justify-center hover:bg-red-500 cursor-pointer">
<span class="my-4">Tab 1</span>
</div>
</div>
<div class="flex-1 px-1">
<div class="flex justify-center hover:bg-red-500 cursor-pointer">
<span class="my-4">short tab 2</span>
</div>
</div>
<div class="flex-1 px-1">
<div class="flex justify-center hover:bg-red-500 cursor-pointer">
<span class="my-4">Long Tab name 3</span>
</div>
</div>
<div class="flex-1 px-1">
<div class="flex justify-center hover:bg-red-500 cursor-pointer">
<span class="my-4">This is super Long Tab name 4</span>
</div>
</div>
<div class="flex-1 px-1">
<div class="flex justify-center hover:bg-red-500 cursor-pointer">
<span class="my-4">This is SUPER extra long tab name 5</span>
</div>
</div>
</div>
</div>
</template>
You need to make some minor adjustments to get this working since you are using a flexbox, where each div (Let's call it div-1) holds a sub-div which further contains the span element, we can convert div-1 to a flexbox with the direction set to be a column and further apply the flex-grow so that it occupies the full height of the parent div, along with flex-1 which already exists, this is because this div resides under the div whose flex-direction is specified to be row .flex-grow grows on y-axis when the flex-direction is column. The sub-div again needs to have the properties, align-items:center, justify-content:center, and flex-grow:1, so that the text within is centered and again, this div to occupy the full height of its parent div(div1 as per our example).
<template>
<!-- CONTAINER -->
<div
class="flex-col bg-gray-200 w-11/12 rounded-xl border-2 m-auto pt-2 mt-2"
>
<!-- MAIN CONTENT -->
<div class="flex pb-2 bg-green-500 py-10">MAIN CONTENT</div>
<!-- Tabs -->
<div class="flex text-sm text-center bg-blue-500">
<div class="flex -1 flex flex-col flex-grow hover:bg-red-500">
<div class="flex justify-center items-center flex-grow">
<span>Tab 1</span>
</div>
</div>
<div class="flex-1 flex flex-col flex-grow hover:bg-red-500">
<div class="flex justify-center items-center flex-grow">
<span class="my-4">short tab 2</span>
</div>
</div>
<div class="flex-1 flex flex-col flex-grow hover:bg-red-500">
<div class="flex justify-center items-center flex-grow">
<span class="my-4">Long Tab name 3</span>
</div>
</div>
<div class="flex-1 flex flex-col flex-grow hover:bg-red-500">
<div class="flex justify-center items-center flex-grow">
<span class="my-4">This is super Long Tab name 4</span>
</div>
</div>
<div class="flex-1 px-1 flex flex-col flex-grow hover:bg-red-500">
<div class="flex justify-center items-center flex-grow">
<span class="my-4">This is SUPER extra long tab name 5</span>
</div>
</div>
</div>
</div>
</template>

How to align a div within a div using flex and flex-col Tailwind CSS

I'm trying to vertically center the div with a white border onto the div with a green background. Colors just for show. I cannot figure out why justify-center and items-center do not work. I know I can use margin to achieve what I want but I know there's a better way. I have tried referencing this SO post but have had no luck:Reference Post
Also, if there is a better solution to implement what I want I'm all ears.
My code:
<div class="flex flex-col min-h-screen bg-coolGray-900">
<div class="w-screen justify-center items-center h-screen bg-green-500 ">
<div class="text-center text-white border-2 ">
<h1 class="mb-10 text-6xl font-bold font-lato">Message Here</h1>
<h2 class="mb-8 text-2xl font-semibold font-lato">More Detailed Message Here</h2>
<button class="mx-auto btn btn-learn">Learn More</button>
</div>
</div>
</div>
You haven't displayed your container class as flex, this is why your justifies aren't working.
Add the class flex to your bg-green-500 class.
<link href="https://unpkg.com/tailwindcss#^2/dist/tailwind.min.css" rel="stylesheet"/>
<section>
<div class="flex flex-col min-h-screen bg-coolGray-900">
<div class="flex w-screen justify-center items-center h-screen bg-green-500 ">
<div class="text-center text-white border-2 w-screen">
<h1 class="mb-10 text-6xl font-bold font-lato">Message Here</h1>
<h2 class="mb-8 text-2xl font-semibold font-lato">More Detailed Message Here</h2>
<button class="mx-auto btn btn-learn">Learn More</button>
</div>
</div>
</div>
</section>

Set Fixed Gap on Flex Tailwind

This is my design with flex. You can see both the div's are having different gap in between. How Can I make it equal?
I just want to set a fixed width for the second column however I am not able to achieve it in Tailwind.
Code:
<div className='bg-gray-1000 rounded shadow border border-opacity-50 text-white flex flex-col lg:flex-row w-7/12 mx-auto justify-between p-2 mb-2 items-center'>
<div className='bg-primary rounded w-14 h-14 flex items-center'>
<img src={props.logo}/>
</div>
<div className='flex flex-col'>
<div>{props.title}</div>
<div className='flex'>
<div><img className='w-6 mt-1' src={props.flag}/></div>
<div><FaInfoCircle className='inline ml-2 text-xl'/></div>
<div><button className={`ml-2 rounded px-4 py-0 text-sm uppercase bg-${props.color}-600`} disabled>{props.mode}</button></div>
</div>
</div>
<div className='flex flex-col'>
<div><FaCalendar className='inline mr-2 text-xl'/> {props.date}</div>
<div className='mt-1'><FaClock className='inline mr-2 text-xl'/> {props.time}</div>
</div>
<div className='flex flex-col'>
<div> <FaUsers className='inline mr-2 text-xl'/> {props.vs}</div>
<div className='mt-1'><FaUsers className='inline mr-2 text-xl'/> {props.slots} Slots</div>
</div>
<div className='flex flex-col'>
<div><AiFillDollarCircle color='green' className='inline mr-2 text-xl'/></div>
<div className='mt-1'><AiFillTrophy className='inline mr-2 text-xl md:text-2xl'/> {props.prize}</div>
</div>
</div>
I would love to get some help on this, cheers.
Add flex-grow class to block with title and set space-x-{value} class for parent so it will add gap between child elements. Demo
P.S. You have bg-${props.color}-600 which will be purged in a production mode

Resources