CSS alignment: flexbox/ tailwind alignment issues - css

Currently I'm using tailwind to align data in react, I've tried adding flexbox but it appears im off with a few things
This is my expected outcome:
I would love if someone can explain what im doing wrong as well.
Current outcome:
My last attempt was this:
import React from "react";
import ReactDOM from "react-dom";
const SummaryPerPlatform = () => {
return (
<div>
<div className="max-w-md overflow-hidden bg-white m-4">
<div className="flex flex-col min-h-full">
<div className="flex flex-col flex-grow">
<div className="px-6 py-3 border-b">
<div className="text-xl font-bold"> Twitter </div>
</div>
<div className="px-6 py-3 border-b">
<span className="">Avg. sentigment(0.0 -1.0)</span>
<span className="">0.31</span>
</div>
<div className="px-6 py-3 border-b">
<div className="text-xl font-bold"> Instagram </div>
<span className="">Post analyzed</span>
<span className="">5,670</span>
</div>
<div className="px-6 py-3 border-b">
<div className="text-xl font-bold"> LinkedIn </div>
<span className="">Positive posts (>0.66)</span>
<span className="">1,849</span>
</div>
<div className="px-6 py-3 border-b">
<span className="">Negative posts (0.33)</span>
<span className="">1,981</span>
</div>
</div>
</div>
</div>
</div>
);
};
export default SummaryPerPlatform;
const rootElement = document.getElementById("root");
ReactDOM.render(<SummaryPerPlatform />, rootElement);
Any help is very much appreciated.

You should use flex-row instead of flex-col for whole container. Otherwise I would suggest for using an extra div for differentiating these sections and using Grid to arrange these div in a similar width.
You can try like this:
// ...
return (
<div>
<div className="max-w-md overflow-hidden bg-white m-4">
<div className="grid grid-cols-4 gap-1">
<div>
<div className="px-6 py-3 border-b">
<div className="text-xl font-bold"> Twitter </div>
</div>
<div className="px-6 py-3 border-b">
<span className="">Avg. sentigment(0.0 -1.0)</span>
<span className="">0.31</span>
</div>
</div>
<div>
<div className="px-6 py-3 border-b">
<div className="text-xl font-bold"> Instagram </div>
<span className="">Post analyzed</span>
<span className="">5,670</span>
</div>
</div>
<div>
<div className="px-6 py-3 border-b">
<div className="text-xl font-bold"> LinkedIn </div>
<span className="">Positive posts (>0.66)</span>
<span className="">1,849</span>
</div>
<div className="px-6 py-3 border-b">
<span className="">Negative posts (0.33)</span>
<span className="">1,981</span>
</div>
</div>
</div>
</div>
</div>
)
// ...

Related

Vue 3 Carousel unexpected behavior

I have a Vue3 carousel inside a Single file component
package.json
"vue3-carousel": "^0.1.40"
SFC
import { Carousel, Slide, Navigation } from 'vue3-carousel';
import 'vue3-carousel/dist/carousel.css';
import '#/assets/scss/Carousel.scss';
<Carousel :wrap-around="true" class="box-carousel" :autoplay="2000" :transition="500">
<Slide v-for="slide in slides" :key="slide.id">
<div class="mx-auto w-[85%] md:w-[90%] rounded-lg p-5 bg-blue-secondary-5 h-full dark:bg-blue-secondary-5 dark:text-black-dark-100">
<!-- Box Description -->
<div class="grid grid-cols-5 gap-5 mb-5">
<div class="col-span-1">
<div class="rounded-full h-11 w-11 bg-black-20 flex items-center justify-center">
<p class="uppercase font-bold text-sm">{{slide.title}}</p>
</div>
</div>
<div class="col-span-4 text-left">
<div class="ml-3 md:ml-0">
<p class="font-bold">{{slide.name}}</p>
<p class="text-black-40 text-xs">{{slide.date}}</p>
</div>
</div>
</div>
<!-- End Box Description -->
<!-- Box Comment -->
<div class="text-left mb-8">
<p class="text-sm ">
{{slide.comment.substring(0,130)}}
</p>
</div>
<!-- End Box Comment -->
<!-- Box Actions -->
<div class="grid grid-cols-6 gap-5 absolute bottom-5">
<div class="col-span-2">
<a href="javascript:void(0)" class="flex items-center text-xs md:text-sm relative top-1 text-blue-secondary-100">
<UndoIcon width="10" class="fill-blue-secondary-100 mr-2 hidden md:block" />
Responder
</a>
</div>
<div class="col-span-2">
<a href="javascript:void(0)" class="flex items-center text-xs md:text-sm relative top-1 text-black-40 underline">
Ver contexto
</a>
</div>
<div class="col-span-2">
<p class="text-xs md:text-sm flex items-center justify-end md:justify-start relative top-1">
<span class="h-2 w-2 rounded-full bg-green-primary-100 inline-block mr-5 md:mr-1 relative top-[-1px]"></span>
<span class="hidden md:block">aprovado</span>
</p>
</div>
</div>
<!-- End Box Actions -->
</div>
</Slide>
<template #addons>
<Navigation />
</template>
</Carousel>
But the transition behavior of the slides is not as expected. It is just changing withouth the transition/translate position effect
This is how it is:
Expected effect: (by the way, the carousel sometimes spontaneously display the expected behavior like when after some hot module replacement refresh happens after saving some edit in VSCode and there is a refresh in the vue app like this):
Thanks in advance for any advice!! Happy new year !! 🙂

Not able to position Div using tailwindCSS

This is my react code:
<div>
<div>
<div className=" grid gap-4 grid-row-4 grid-flow-col">
<div className="row-span-4 h-2/5 w-auto p-2 bg-white">
<p className="m-4 font-bold">
8 task completed out of 10
<br></br>
<h4 className="font-bold">23 December, Sunday</h4>
</p>
<div className="m-4"> Calender </div>
<div className="m-4 p-4 shadow-md">
<p>
<h4 className="font-bold">Send benefit review by Sunday</h4>
<span className="text-gray-600">
Due date: December 23, 2018
</span>
<br></br>
Image: George Fields
</p>
</div>
<div className="m-4 p-4 shadow-md">
<p>
<h4 className="font-bold">Invite to office meet-up</h4>
<span className="text-gray-600">
Due date: December 23, 2018
</span>
<br></br>
Image: Rebecca Moore
</p>
</div>
<div className="m-4 p-4 shadow-md">
<p>
<h4 className="font-bold">Office meet-up</h4>
<span className="text-gray-600">
Due date: December 23, 2018
</span>
<br></br>
Image: Lindsey Stroud
<h2 className="text-blue-1000 font-bold pt-4"> Show More </h2>
</p>
</div>
</div>
<div className="h-80 w-1/2 p-2 bg-white">
<h4 className="font-bold"> Deals </h4>
<AreaChart />
</div>
<div className="h-80 w-1/2 p-2 bg-white">
<h4 className="font-bold"> Tasks</h4>
<ul className="absolute inset-10">
<li className="text-green-600 font-bold">Active</li>
<li className="text-yellow-600 font-bold">Completed</li>
<li className="text-red-600 font-bold">Ended</li>
</ul>
<PieChart />
</div>
</div>
</div>
</div>
I am not able to position these grids, I don't know where to put the class on and also which classes exactly, please bear in mind this is my day 2 of learning tailwind, any help would be appreciated.
I am also attaching the picture of my UI and will point to the area I want to position this grid layout to. Thanks
I tried to use your code as much as possible, here is the result:
The code:
<div className="flex flex-row ">
<div className="flex flex-col w-96">
<div className="px-2">Placeholder</div>
<div className="px-2">Placeholder</div>
<div className="px-2">Placeholder</div>
<div className="px-2">Placeholder</div>
<div className="px-2">Placeholder</div>
<div className="px-2">Placeholder</div>
</div>
<div className="grid sm:grid-cols-2 bg-gray-200 w-full">
<p className="m-4 font-bold bg-white">
8 task completed out of 10
<br></br>
<h4 className="font-bold">23 December, Sunday</h4>
</p>
<div className="m-4 h-80 w-1/2 p-2 bg-white">
<h4 className="font-bold"> Deals </h4>
AreaChart
</div>
</div>
</div>

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.

Align text under an image in tailwind css?

I want to align the text under the image here is the screenshot of what I am doing.
Help me out here I want the code to be in tailwind css.
Do you mean like this?
<script src="https://cdn.tailwindcss.com"></script>
<div class=" p-8 bg-gray-100">
<div class="w-96 flex justify-start space-x-3 bg-gray-200 h-48 rounded-md p-8">
<div class="space-y-4 text-center">
<div class="w-16 h-16 bg-teal-700 rounded-full"></div>
<h1 class=" px-2 py-0.5 bg-gray-50 border-2 border-gray-300 ">First Name</h1>
</div>
<div class="space-y-4 text-center">
<div class="w-16 h-16 bg-teal-700 rounded-full"></div>
<h1 class=" px-2 py-0.5 bg-gray-50 border-2 border-gray-300 ">SecondName</h1>
</div>
</div>
</div>
You just need to do this. It works for me.
<div class="flex p-10 ">
<div class="mx-5">
<div class="w-20 h-20 ">
<img src="https://comps.gograph.com/penguin-emotional-head-vector-illustration-of-cute-arctic-bird-in-sunglasses-shows-emotion-cool-emoji-smiley-icon-print-chat-communication-penguin-in-flat-cartoon-style-on-blue-background_gg103004116.jpg" className="rounded-full"/>
</div>
<p class="mt-3 p-1 border-2 border-teal-200 ">Zain UI Adideen</p>
</div>
<div class="mx-5">
<div class="w-20 h-20">
<img src="https://comps.gograph.com/penguin-emotional-head-vector-illustration-of-cute-arctic-bird-in-sunglasses-shows-emotion-cool-emoji-smiley-icon-print-chat-communication-penguin-in-flat-cartoon-style-on-blue-background_gg103004116.jpg" className="rounded-full"/>
</div>
<p class="mt-3 p-1 border-2 border-teal-200 ">Akira Ito</p>
</div>
</div>

Resources