I am trying to group table rows using tailwind and custom CSS like the below screenshot:
I have done something similar like the screenshot but the issue is I want the total and Grade data in the middle, here is my code:
<div className="container mx-auto overflow-x-auto border-x border-t my-10">
<table className="table-auto w-full">
<thead className="border-b">
<tr
style={{ backgroundColor: "#5CB25A" }}
className="text-white font-bold h-10"
>
<th className="text-center md:p-4 p-0 md:w-32 w-10 border-r border-gray-300">
Subject Code
</th>
<th className="text-center md:p-4 p-0 md:w-96 w-none ">
Subject Name
</th>
<th
colSpan={3}
className="text-center p-4 border border-t-0 border-gray-300"
>
Marks
</th>
<th className="text-center md:p-4 p-0 md:w-32 w-10 border-r border-gray-300">
Grade
</th>
</tr>
<tr
style={{ backgroundColor: "#5CB25A" }}
className="border-b border-gray-400 font-bold h-10 text-white"
>
<th className="text-center p-4 border-r text-base"></th>
<th className="text-center p-4"></th>
<th className="text-center p-4 border ">Theory</th>
<th className="text-center p-4 border ">MCQ</th>
<th className="text-center p-4 border ">Total</th>
<th className="text-center p-4"></th>
</tr>
</thead>
<tbody>
<tr className="hover:bg-gray-50 text-center border-b-0 border-b-none h-10">
<td className="p-0 border-l border-r">001</td>
<td className="p-0 border-l border-r">English 1</td>
<td className="p-0 border-l border-r">40</td>
<td className="p-0 border-l border-r">40</td>
<td className="p-0 border-l border-r"></td>
<td className="p-0 border-l border-r"></td>
</tr>
<tr className="border -b border-t-0 hover:bg-gray-50 text-center h-10">
<td className="p-0 border-l border-r">001</td>
<td className="p-0 border-l border-r">English 1</td>
<td className="p-0 border-l border-r">40</td>
<td className="p-0 border-l border-r">40</td>
<td className="p-0 border-l border-r">80</td>
<td className="p-0 border-l border-r">A+</td>
</tr>
<tr className="border-b hover:bg-gray-50 text-center h-10">
<td className="p-4 border">001</td>
<td className="p-4 border">English 1</td>
<td className="p-4 border">40</td>
<td className="p-4 border">40</td>
<td className="p-4 border"></td>
<td className="p-4 border">A+</td>
</tr>
</tbody>
</table>
</div>
Above code UI:
As you can see the total and grade are not in the middle because I have used table rows for the group row.
First I would like you to suggest to remove style={{ backgroundColor: "#5CB25A" }} and add bg-[#5CB25A] in <thead> tag.
<thead class="border-b bg-[#5CB25A]">
Secondly to center, you can use class flex items-center justify-center to center the Grade vertically.
You can also make use of grid class properties to create this table like below
<script src="https://cdn.tailwindcss.com"></script>
<div class="m-2 grid grid-cols-6 bg-gray-50 outline outline-1">
<!-- table head starts -->
<div class="row-span-2 flex items-center justify-center border-[1px] bg-[#5CB25a] py-12 text-white">Subject Code</div>
<div class="row-span-2 flex items-center justify-center border-[1px] bg-[#5CB25a] py-12 text-white">Subject Name</div>
<div class="col-span-3 flex items-center justify-center border-[1px] bg-[#5CB25a] text-white">Marks</div>
<div class="row-span-2 flex items-center justify-center border-[1px] bg-[#5CB25a] text-white">Grade</div>
<div class="flex items-center justify-center border-[1px] bg-[#5CB25a] text-white">Theory</div>
<div class="flex items-center justify-center border-[1px] bg-[#5CB25a] text-white">MCQ</div>
<div class="flex items-center justify-center border-[1px] bg-[#5CB25a] text-white">Total</div>
<!-- table head ends -->
<!-- table body starts -->
<div class="flex items-center justify-center border-[1px] border-b-0 py-4">
001<br />
001
</div>
<div class="flex items-center justify-center border-[1px] border-b-0">English 1<br />English 1</div>
<div class="flex items-center justify-center border-[1px] border-b-0">40<br />40</div>
<div class="flex items-center justify-center border-[1px] border-b-0">40<br />40</div>
<div class="flex items-center justify-center border-[1px] border-b-0">80</div>
<div class="flex items-center justify-center border-[1px] py-2">A+</div>
<div class="flex items-center justify-center border-[1px] py-2">001</div>
<div class="flex items-center justify-center border-[1px] py-2">English 1</div>
<div class="flex items-center justify-center border-[1px] py-2">40</div>
<div class="flex items-center justify-center border-[1px] py-2">40</div>
<div class="flex items-center justify-center border-[1px] py-2">80</div>
<div class="flex items-center justify-center border-[1px] py-2">A+</div>
<!-- table body ends -->
</div>
Don't forgot to replace class with className as you are working with className
Related
<div className="flex overflow-x-auto shadow-md sm:rounded-lg bg-white dark:bg-gray-800 dark:border-gray-700 w-11/12 justify-center">
<table className="w-full text-sm text-left text-gray-500 dark:text-gray-400">
<thead className="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
<tr>
<th scope="col" className="px-6 py-3">
Date
</th>
<th scope="col" className="px-6 py-3">
Job Description
</th>
<th scope="col" className="px-6 py-3">
Location
</th>
<th scope="col" className="px-6 py-3">
Job Type / $ Rate (hourly)
</th>
<th scope="col" className="px-6 py-3">
Details
</th>
</tr>
</thead>
<tbody>
<tr className="bg-white dark:bg-gray-800 dark:border-gray-700">
<th
scope="row"
className="px-6 py-4 font-medium text-gray-900 whitespace-pre-wrap text-xs dark:text-white"
>
WHY NOOOO CENTERRRRRRRRRR
</th>
<td className="px-6 py-4">Sliver</td>
<td className="px-6 py-4">Laptop</td>
<td className="px-6 py-4">$2999</td>
<td className="px-6 py-4">
<a
href="#"
className="font-medium text-blue-600 dark:text-blue-500 hover:underline"
>
Edit
</a>
</td>
</tr>
<tr className="bg-white dark:bg-gray-800">
<th
scope="row"
className="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white"
>
Magic Mouse 2
</th>
<td className="px-6 py-4">Black</td>
<td className="px-6 py-4">Accessories</td>
<td className="px-6 py-4">$99</td>
<td className="px-6 py-4">
<a
href="#"
className="font-medium text-blue-600 dark:text-blue-500 hover:underline"
>
Edit
</a>
</td>
</tr>
</tbody>
</table>
</div>
I've used flex, flex item-center, and anything that says it will center the table. But, it never moves to the center position no matter what I do.
It is because there is no parent element which is containing the div spanning accross the entire width of screen.
Possible solutions
Try using mx-auto, that will center your table
Code:
<div className="flex mx-auto ...">
<table className="...">
If you want to use flex anyways, try wrapping it with a div and give it width of w-screen
Code:
<div class="flex w-screen justify-center">
<div className="flex ....>
<table> ...
</div>
</div>
I'm getting this error when I attempt to run my Next app:
Server Error
Error: Failed prop type: The prop href expects a string or object in <Link>, but got undefined instead.
I have all the tags pointing to id's within the SPA. I'm not seeing where it's getting the 'undefined' from. Could someone point this out and maybe provide some insight on how to find the initial point it messed up?
This is the Layout.js:
import Link from "next/link";
export default function Layout({children}){
return (<>
<div className="container mx-auto w-screen md:container md:mx-auto top-0 b" id="topNavBar">
<div className=" flex justify-between" id="topNavarInner">
<a className="button p-4 b" href="#">LOGO</a>
<div className="flex " id="topNavBarMenuGroup">
<Link href="#web-development" id="topNavBarMenu-webDevSection" className="">
<a className="button p-2 h-full flex items-center b">Web Development</a>
</Link>
<Link href="#email-development" id="topNavBarMenu-emailDevSection" className="">
<a className="button p-2 h-full flex items-center b">Email Development</a>
</Link>
</div>
</div>
</div>
{children}
<div id="footer">
<div className="container mx-auto w-screen md:container md:mx-auto sticky bottom-0 b">
<div className=" flex justify-center " id="footerInner">
<p className="p-4 b">FOOTER</p>
</div>
</div>
</div>
</>)
}
This is the pages/index.js:
import {useState,useEffect} from "react";
import Head from "next/head";
import Link from "next/link";
import Image from 'next/image';
import {microblog_entries} from "../data/microblog-entries";
import projectPieces from "../data/projectInfo";
import emailDevProjectPieces from "../data/emailDevProjectInfo";
import graphicArtPieces from "../data/graphicArtInfo";
import {personalText,professionalText,picture,techUsed} from "../data/aboutMeInfo";
export default function Home() {
const microblogPhrase = "Tiny gods with tiny computers."
const [projects,setProjects] = useState(projectPieces);
const [emailDevProjects,setemailDevProjects] = useState(emailDevProjectPieces);
const [graphicArt,setGraphicArt] = useState(graphicArtPieces);
return (<>
<Head>
<title>JZ-Portfolio</title>
</Head>
<section className="container px-6 mx-auto h-screen flex flex-col justify-center items-center" id="landingPage">
<table className="table table-auto border">
<tbody>
<tr id="title-row">
<td className="pb-5 text-center">
<div className="text-4xl font-bold">Jason Zamora's <span className="text-4xl">portfolio</span></div>
</td>
</tr>
<tr id="subTitle-row">
<td className="pb-5 text-center text-white">
<p className="text-white">web | email developer </p>
</td>
</tr>
<tr id="microBlog-row">
<td className="py-2 text-center border border-3">
<p>{microblogPhrase}</p>
</td>
</tr>
</tbody>
</table>
</section>
<WebDevSection projects={projects}/>
<EmailDevSection emailDevProjects={emailDevProjects}/>
<GraphicArtSection graphicArt={graphicArt}/>
<AboutMeSection/>
</>)
}
const WebDevSection = ({projects})=>{
return(<>
<section className="container mx-auto h-fit flex flex-col " id="web-development">
<table className=" table table-auto b">
<tbody>
<tr id="webDev-title-row" className="">
<td className="pt-4 text-2xl text-white/75 " >
<span className="pl-6">web development</span><br/>
<span className="pl-10 relative top-[-1rem] text-6xl ">Projects</span>
<ul id="webDevNavMenu" className="p-2 -top-11 flex flex-col relative float-right sm:top-1 sm:justify-around sm:justify-self-center sm:flex-row sm:float-none">
<Link href="#email-development">
<a><li className="text-base p-2 text-right button">Email Development</li></a>
</Link>
<Link href="#graphic-art">
<a><li className="text-base p-2 text-right button">Graphic Art</li></a>
</Link>
<Link href="#about-me">
<a><li className="text-base p-2 text-right button">About me</li></a>
</Link>
</ul>
</td>
</tr>
<tr id="webDev-links-row" className="border-t-2 col-span-2 flex flex-wrap justify-evenly">
{projects.map((project,index)=>{
return (
<td className="shrink-0 p-2 button" key={project.id}>
<Link href={`#${project.id}`} key={`${project.name}-link`}>
<a className=" h-full" id={`${project.id}-link`} key={`${project.name}-anchor`}>
{project.name}
</a>
</Link>
</td>
)
})}
</tr>
<tr id="webDev-items-row" className="flex flex-col pt-4 lg:flex-row lg:gap-2 lg:flex-wrap lg:space-around ">
{projects.map((project,index)=>{
return (
<td id={`${project.id}`} className="w-11/12 mx-auto my-1 lg:w-5/12 lg:shrink-0 b" key={project.id}>
<div id={`${project.id}-grid`} className="grid grid-cols-[50%_50%] grid-rows-[70%_18%_12%] h-[250px] lg:h-[450px] lg:grid-rows-[50%_150px_auto] ">
<div id={`${project.id}-screenshot`} className="col-span-1 row-span-2 m-auto lg:col-span-2 lg:row-span-1 ">
<Image src={project.screenShot} width={375} height={235} />
</div>
<div id={`${project.id}-info`} className="p-4 pt-1 lg:col-span-2 ">
<h1 id={`${project.id}-title`} className="text-center py-1 font-bold lg:pt-5">{project.name}</h1>
<p id={`${project.id}-description`} className="text-sm leading-4 lg:text-[1rem] lg:leading-5 lg:p-4 lg:border-b-4 border-white" >{project.description}</p>
</div>
<div id={`${project.id}-techStack`} className="text-xs flex items-center justify-center p-2 text-center lg:text-sm ">
{project.techStack}
</div>
<div id={`${project.id}-external-links-group`} className="col-span-2 row-start-3 flex items-center justify-evenly lg:col-span-1 ">
<Link href={project.url} className="">
<a id={`${project.id}-url`} className="font-bold button px-4" target="_blank">live site</a>
</Link>
<div className="spacer"> </div>
<Link href={project.git}>
<a id={`${project.id}-github`} className="font-bold" target="_blank">github</a>
</Link>
</div>
</div>
</td>
)
})}
</tr>
</tbody>
</table>
</section>
</>)
}
const EmailDevSection = ({emailDevProjects})=>{
return (<>
<section className="container mx-auto h-fit flex flex-col " id="email-development">
<table className="table table-auto">
<tbody>
<tr id="emailDev-title-row" className="">
<td className=" pt-6 text-2xl text-white/75">
<span className="pl-6">Email Development</span><br/>
<span className="pl-10 relative top-[-1rem] text-6xl ">Projects</span>
<ul id="emailDevNavMenu" className="p-2 -top-11 flex flex-col relative float-right sm:top-1 sm:justify-around sm:justify-self-center sm:flex-row sm:float-none">
<Link href="#web-development">
<a><li className="text-base p-2 text-right button">Web Development</li></a>
</Link>
<Link href="#graphic-art">
<a><li className="text-base p-2 text-right button">Graphic Art</li></a>
</Link>
<Link href="#about-me">
<a><li className="text-base p-2 text-right button">About me</li></a>
</Link>
</ul>
</td>
</tr>
<tr id="emailDev-links-row" className="border-t-2 flex flex-wrap justify-evenly">
{emailDevProjects.map((emailDevProject)=>{
return (
<td className="shrink-0 p-2 button" key={`${emailDevProject.id}-container`}>
<Link href={`#${emailDevProject.id}`} key={`${emailDevProject.name}-link`}>
<a className=" h-full" id={`${emailDevProject.id}-link`} key={`${emailDevProject.name}-anchor`}>
{emailDevProject.name}
</a>
</Link>
</td>
)
})}
</tr>
<tr id="emailDev-items-row" className=" flex flex-col pt-4 b">
{emailDevProjects.map((emailDevProject)=>{
return (
<td id={`${emailDevProject.id}`} className="w-11/12 mx-auto my-1 b" key={`${emailDevProject.id}-container`}>
<div id={`${emailDevProject.id}-grid`} className="grid grid-cols-[30%_auto] grid-rows-[70%_18%_auto] h-[250px] b">
<div id={`${emailDevProject.id}-screenshot`} className="col-span-1 row-span-2 m-auto b">insert image</div>
<div id={`${emailDevProject.id}-info`} className="p-4 pt-1 b">
<h1 id={`${emailDevProject.id}-title`} className="text-center py-1 font-bold ">{emailDevProject.name}</h1>
<p id={`${emailDevProject.id}-description`} className="text-sm leading-4">{emailDevProject.description}</p>
</div>
<div id={`${emailDevProject.id}-techStack`} className="text-xs flex items-center justify-center p-2 text-center b">
{emailDevProject.techStack}
</div>
<div id={`${emailDevProject.id}-external-links-group`} className="col-span-2 row-start-3 flex items-center justify-evenly b">
<Link href={emailDevProject.url} className="">
<a id={`${emailDevProject.id}-url`} className="font-bold button px-4" target="_blank">live site</a>
</Link>
<div className="spacer"> </div>
<Link href={emailDevProject.git}>
<a id={`${emailDevProject.id}-github`} className="font-bold" target="_blank">github</a>
</Link>
</div>
</div>
</td>
)
})}
</tr>
</tbody>
</table>
</section>
</>)
}
const GraphicArtSection = ({graphicArt})=>{
return (<>
<section className="container mx-auto h-fit flex flex-col " id="graphic-art">
<table className=" table table-auto b">
<tbody>
<tr id="graphicArt-title-row" className="">
<td className="pt-4 text-2xl text-white/75 " >
<span className="pl-6">Graphic</span><br/>
<span className="pl-10 relative top-[-1rem] text-6xl ">Art</span>
<ul id="graphicArtNavMenu" className="p-2 -top-11 flex flex-col relative float-right sm:top-1 sm:justify-around sm:justify-self-center sm:flex-row sm:float-none">
<Link href="#web-development">
<a><li className="text-base p-2 text-right button">Web Development</li></a>
</Link>
<Link href="#email-development">
<a><li className="text-base p-2 text-right button">Email Development</li></a>
</Link>
<Link href="#about-me">
<a><li className="text-base p-2 text-right button">About me</li></a>
</Link>
</ul>
</td>
</tr>
<tr id="graphicArt-links-row" className="border-t-2 col-span-2 flex flex-wrap justify-evenly">
{graphicArt.map((artPiece,index)=>{
return (
<td className="shrink-0 p-2 button" key={artPiece.id}>
<Link href={`#${artPiece.id}`} key={`${artPiece.name}-link`}>
<a className=" h-full" id={`${artPiece.id}-link`} key={`${artPiece.name}-anchor`}>
{artPiece.name}
</a>
</Link>
</td>
)
})}
</tr>
<tr id="graphicArt-items-row" className="flex flex-col pt-4 b">
{graphicArt.map((artPiece,index)=>{
return (
<td id={`${artPiece.id}`} className="w-11/12 mx-auto my-1 b" key={artPiece.id}>
<div id={`${artPiece.id}-grid`} className="grid grid-rows-[90%_auto] h-96 b">
<div id={`${artPiece.image}`} className="p-1 bg-black bg-contain "></div>
<div id={`${artPiece.description}`} className="flex items-center justify-center">{artPiece.description}</div>
</div>
</td>
)
})}
</tr>
</tbody>
</table>
</section>
</>)
}
const AboutMeSection = ({aboutInfo})=>{
return (<>
<section className="container mx-auto h-screen flex flex-col " id="about-me">
<table className=" table table-auto ">
<tbody>
<tr id="aboutMe-title-row" className="">
<td className=" pt-6 text-2xl text-white/75">
<span className="pl-6">About</span><br/>
<span className="pl-10 relative top-[-1rem] text-6xl ">Me</span>
<ul id="aboutMeNavMenu" className="p-2 -top-11 flex flex-col relative float-right border-b-2 sm:top-1 sm:justify-around sm:justify-self-center sm:flex-row sm:float-none">
<Link href="#web-development">
<a><li className="text-base p-2 text-right button">Web Development</li></a>
</Link>
<Link href="#email-development">
<a><li className="text-base p-2 text-right button">Email Development</li></a>
</Link>
<Link href="#graphic-art">
<a><li className="text-base p-2 text-right button">Graphic Art</li></a>
</Link>
</ul>
</td>
</tr>
<tr className="">
<div id="aboutme-grid" className=" mt-6 p-6 grid grid-cols-6 gap-4 ">
<div id="personal-info" className="col-span-4 text-right break-words">{personalText}</div>
<div id="personal-heading" className="col-span-2 col-start-5 flex justify-center items-center bg-gradient-to-r from-[#334] to-transparent ">
<h1 className="text-2xl ">Personal</h1>
</div>
<div id="professional-heading" className="col-span-2 col-start-1 flex justify-center items-center bg-gradient-to-l from-[#334] to-transparent">
<h1 className="text-2xl">Professional</h1>
</div>
<div id="professional-info" className="col-start-3 col-span-4 ">{professionalText}</div>
</div>
</tr>
<tr id="techUsed-title" className="flex justify-center text-2xl bg-[#334] py-4">Technologies used:</tr>
<tr id="techUsed-row" className="flex flex-wrap items-center justify-evenly bg-white ">
{techUsed.map((icon)=>{
return (
<div id={`${icon.name}-icon`} className="p-1" key={`${icon.name}`}>
<Image src={`/${icon.logo}`} width="40" height="40" />
</div>
)
})}
</tr>
</tbody>
</table>
</section>
</>)}
I'm trying to make a word wrapper inside a table row, using Tailwind CSS, and it doesn't seem to be working. What am I doing wrong?
I am:
Making the table a: "w-full"
Making the td and the p a "break-all"
Giving a max width to the tr
This is the code:
<div className="py-5 ">
<div className="overflow-x-auto">
<table className="w-full max-w-4xl mx-auto overflow-hidden bg-white divide-y divide-gray-300 rounded-lg whitespace-nowrap">
<thead className="bg-gray-900">
<tr className="text-left text-white">
<th className="px-6 py-4 text-lg font-semibold "> n ° </th>
<th className="px-3 py-4 text-lg font-semibold "> Song </th>
<th className="px-3 py-4 text-lg font-semibold text-center "> Best Singers </th>
<th className="px-6 py-4 text-lg font-semibold text-center"> </th>
</tr>
</thead>
<tbody className="divide-y divide-gray-200">
<tr className="max-w-xs break-words">
<td className="px-6 py-4">
<div className="flex items-center space-x-3">
<p>
1
</p>
</div>
</td>
<td
style={{ maxWidth: '100px' }}
className="px-3 py-4 break-all"
>
<p
className="break-all"
>
Vivin la vida loca dsadasdasdasd dasdddddddd saddasdasdad
</p>
</td>
<td className="px-3 py-4 text-center">
<p className="text-blue-600 visited:text-purple-600 hover:text-blue-800 hover:underline">
Donkey
</p>
</td>
<td className="px-3 py-4 text-center">
<p className="text-blue-600 visited:text-purple-600 hover:text-blue-800 hover:underline">
Ricky Martin
</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
This is how it looks:
You just need to remove the whitespace-nowrap from the table, then it should work.
Uploaded the example here: https://stackblitz.com/edit/react-ewzbi6?file=src/App.js
Might be another part of your styling affecting things here. This works for me:
Don't mean this as an answer, just can't attach pics to comments.
I've been trying for hours to center the image in this table, but I cannot make it work. The image is in the middle of this code. I hope this is a workable example.
<table class="container mx-auto mt-2">
<thead>
#foreach($posts as $post)
<tr>
<th class="p-3 font-bold uppercase bg-gray-200 text-gray-600 border border-gray-300 hidden lg:table-cell">Title</th>
<th class="p-3 font-bold uppercase bg-gray-200 text-gray-600 border border-gray-300 hidden lg:table-cell">Image</th>
<th class="p-3 font-bold uppercase bg-gray-200 text-gray-600 border border-gray-300 hidden lg:table-cell">Status</th>
<th class="p-3 font-bold uppercase bg-gray-200 text-gray-600 border border-gray-300 hidden lg:table-cell">Action</th>
</tr>
</thead>
<tbody>
<tr class="bg-white lg:hover:bg-gray-100 flex lg:table-row flex-row lg:flex-row flex-wrap lg:flex-no-wrap mb-10 lg:mb-0">
<td class="w-full lg:w-auto p-3 text-gray-800 text-center border border-b block lg:table-cell relative lg:static">
<span class="lg:hidden absolute top-0 left-0 bg-blue-200 px-2 py-1 text-xs font-bold uppercase">title</span>
{{ $post->title }}
</td>
<td class="w-full lg:w-auto p-3 text-gray-800 border border-b text-center block lg:table-cell relative lg:static">
<span class="lg:hidden absolute top-0 left-0 bg-blue-200 px-2 py-1 text-xs font-bold uppercase">Image</span>
<img class=" text-center block w-8 h-8 rounded-full " src="{{ asset('storage/photos/'. $post->image ) }}" />
</td>
<td class="w-full lg:w-auto p-3 text-gray-800 text-center border border-b text-center block lg:table-cell relative lg:static">
<span class="lg:hidden absolute top-0 left-0 bg-blue-200 px-2 py-1 text-xs font-bold uppercase">Status</span>
#if($post->active )
active
#else
Not active
#endif
</td>
<td class="w-full lg:w-auto p-3 text-gray-800 text-center border border-b text-center block lg:table-cell relative lg:static">
<span class="lg:hidden absolute top-0 left-0 bg-blue-200 px-2 py-1 text-xs font-bold uppercase">Actions</span>
<x-jet-button wire:click="showEditPostModal({{ $post->id }})" class="bg-green-500">Edit</x-jet-button>
<x-jet-button wire:click="deletePost({{ $post->id}})" class="bg-red-700">Delete</x-jet-button>
</td>
</tr>
#endforeach
</tbody>
</table>
Images in Tailwind are set to block-level by default so they can be centered with CSS properties like margin: 0 auto or with the mx-auto class. Basically element require to be block (has its width) to be centered this way.
In general this guide is very useful to know every possible way of centering elements
you can add the "flex-auto" class.
if you want any things show
I have a dropdown menu inside one of the columns in a table. When it is exposed, it is either cut off (overflow-hidden) or created a scroll bar (overflow-visible).
How would I get this to just appear over top of the table (or "extend" a parent div so it's all visible) so that the only scroll bar is the usual one in the browser, not this table-specific scroll bar. Code provided below.
<div class="flex flex-col">
<div class="-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
<div class="py-2 align-middle inline-block min-w-full sm:px-6 lg:px-8">
<div class="shadow border-b border-gray-200 sm:rounded-lg overflow-auto">
<div class="flex flex-wrap m-4 justify-between">
<div class="flex items-center">
<div class="beep-label">
#lang('livewire.per_page'):
</div>
<select wire:model="perPage" class="beep-input align-middle w-auto inline-block">
<option>10</option>
<option>15</option>
<option>25</option>
</select>
</div>
<div class="flex">
<div class="beep-label pr-2 flex justify-center items-center h-full text-center">
#lang('one-word.filter'):
</div>
<input wire:model="search" class="beep-input" type="text" placeholder="#lang('livewire.search_users')...">
</div>
</div>
<table class="divide-y divide-gray-200 w-full">
<thead>
<tr>
<th class="beep-table-header h-full align-middle flex">
<div class="align-middle justify-items-auto">
<a wire:click.prevent="sortBy('name')" role="button" href="#" class="">
#include('livewire.includes._sort-icon', ['field' => 'name'])
<div class="inline-block">#lang('one-word.name')</div>
</a>
</div>
</th>
<th class="beep-table-header">
<a wire:click.prevent="sortBy('users.email')" role="button" href="#" class="">
#include('livewire.includes._sort-icon', ['field' => 'users.email'])
#lang('users.beep_email')
</a>
</th>
<th class="beep-table-header">
<a wire:click.prevent="sortBy('beep_extension')" role="button" href="#" class="">
#include('livewire.includes._sort-icon', ['field' => 'beep_extension'])
#lang('livewire.beep_ext')
</a>
</th>
<th class="beep-table-header text-center">
#lang('one-word.action')
</th>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200">
#foreach ($contacts as $contact)
<tr #if ($contact->is_active !== true) class="table-danger" #endif>
<td class="px-6 py-4 whitespace-no-wrap">
<div class="flex items-center">
<div class="flex-shrink-0 h-10 w-10">
#if ($contact->contactable->thumbnail)
<img class="h-10 w-10 rounded-full"
src="{{ $contact->contactable->thumbnail }}"
alt="">
#else
<x-nav.svg-icons icon="user-circle" class="w-3 h-3" />
#endif
</div>
<div class="ml-4">
<div class="text-sm leading-5 font-medium text-gray-900">
{{ $contact->name }}
</div>
<div class="text-sm leading-5 text-gray-500">{{ $contact->contactable->email }}</div>
</div>
</div>
</td>
<td class="px-6 py-4 whitespace-no-wrap">
<div class="text-sm leading-5 text-gray-900">{{ $contact->beep_mail }}</div>
</td>
<td class="px-6 py-4 whitespace-no-wrap">
<div class="text-sm leading-5 text-gray-900">{{ $contact->beep_extension }}</div>
</td>
<td class="px-6 py-4 whitespace-no-wrap text-center text-sm leading-5 font-medium">
<div x-data="{ open: false }" #keydown.window.escape="open = false" #click.away="open = false" class="relative inline-block text-left">
<div>
<span class="rounded-md shadow-sm">
<button #click="open = !open" type="button" class="inline-flex justify-center w-full rounded-md border border-gray-300 px-4 py-2 bg-white text-sm leading-5 font-medium text-gray-700 hover:text-gray-500 focus:outline-none focus:border-blue-300 focus:shadow-outline-blue active:bg-gray-50 active:text-gray-800 transition ease-in-out duration-150" id="options-menu" aria-haspopup="true" aria-expanded="true">
#lang('one-word.action')
<!-- Heroicon name: chevron-down -->
<svg class="-mr-1 ml-2 h-5 w-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd" />
</svg>
</button>
</span>
</div>
<div x-show="open" x-description="Dropdown panel, show/hide based on dropdown state." x-transition:enter="transition ease-out duration-100" x-transition:enter-start="transform opacity-0 scale-95" x-transition:enter-end="transform opacity-100 scale-100" x-transition:leave="transition ease-in duration-75" x-transition:leave-start="transform opacity-100 scale-100" x-transition:leave-end="transform opacity-0 scale-95" class="origin-top-right absolute right-0 mt-2 w-56 rounded-md shadow-lg z-10">
<div class="rounded-md bg-white shadow-xs">
<div class="py-1" role="menu" aria-orientation="vertical" aria-labelledby="options-menu">
#can ('view', $contact->contactable)
#lang('users.view_profile')
#endcan
#can ('update', $contact->contactable)
#lang('one-word.edit')
#lang('livewire.edit_contact_methods')
{{ $contact->is_active ? __('one-word.deactivate') : __('one-word.activate') }}
#endcan
</div>
</div>
</div>
</div>
</td>
</tr>
#endforeach
</tbody>
</table>
<div class="p-2 uppercase text-sm bg-gray-200">
{{ $contacts->links() }}
</div>
</div>
</div>
</div>
</div>
And the extracted css components in case they are helpful:
.beep-label {
#apply block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2;
}
.beep-input {
#apply appearance-none block w-full text-gray-700 border border-gray-500 rounded py-1 px-2 mb-3;
}
.beep-table-header {
#apply px-6 py-3 bg-gray-100 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider;
}