I am using Tailwind CSS and am trying to build a grid that certain cell contents span multiple cells while other items stay in the single cell. In the code below, I try to show what I am trying to accomplish. I know my col-span-2 class is not doing anything, but I put it there to indicate what I wish I could do. I want all cells to be the same width (I just want some cell content to span over the dividers). Do I need some sort of overlay logic?
Any help is appreciated.
Thanks!
<div id=container class="m-auto p-2">
<div id=theGrid class="grid grid-cols-3 divide-x divide-gray-600">
<div id=cell1 class="px-4 h-24">
Cell 1<br />
<div id=thingThatSpansTwoCells class="h-4 bg-green-700 text-white col-span-2">Spans 2 Cells</div>
</div>
<div id=cell2 class="px-4 h-24">Cell 2</div>
<div id=cell3 class="px-4 h-24">Cell 3</div>
</div>
</div>
You will need to write your own CSS for this. To span 2 column, use width:200% and don't forget to account for the padding you are using:
.w-200 {
width:calc(200% + 3rem);
}
<link href="https://unpkg.com/tailwindcss#^2/dist/tailwind.min.css" rel="stylesheet">
<div id=container class="m-auto p-2">
<div id=theGrid class="grid grid-cols-3 divide-x divide-gray-600">
<div id=cell1 class="px-4 h-24">
Cell 1<br />
<div id=thingThatSpansTwoCells class="bg-green-700 text-white w-200">Spans 2 Cells</div>
</div>
<div id=cell2 class="px-4 h-24">Cell 2</div>
<div id=cell3 class="px-4 h-24">Cell 3</div>
</div>
</div>
Related
I am working on an angular project where I am getting the data in image and title and location. I tried to make a responsive div but unable to make them in one size.
<div *ngFor="let company of companies" class="col-xl-2 col-lg-3 col-md-4 col-sm-6 col-12">
<div class="card">
<div class="card-content">
<div class="card-body py-0 text-center">
<input [checked]="true" type="radio" formControlName="scope" (click)="nextFormPostion(nextFormPostionName)" (change)="nextFormPostion(nextFormPostionName)" id="img{{company.scope}}" class="d-none imgbgchk" value="{{company.scope}}">
<label for="img{{company.scope}}">
<div class="row justify-content-center">
<div class="col-12" style="height: 6rem ; display:table-cell; vertical-align: middle;">
<img src="{{company.logo}}" class="mt-1 img-fluid mh-100" alt="Image 1">
</div>
<div class="col-12 mt-2" style="min-height: 3rem;font-size: 12px;text-transform: none;">
<span>{{company.company}}</span>
</div>
<div class="col-12 mt-1" style="min-height: 2.5rem;font-size: 12px;text-transform: none;">
<span>{{company.country}}</span>
</div>
</div>
<div class="tick_container">
<div class="tick"><i class="fa fa-check"></i></div>
</div>
</label>
</div>
</div>
</div>
</div>
company.logo is the image path and company.company is the name of the company. I want to make image in vertical and horizontal align center and if company name length is new line it change the size of all divs.
You don't need bootstrap exactly to do that you can use JavaScript to get the div side you want and apply as width + height.
Also you can use CSS with, for example:
width: 100%
The first thing you need to check if you have any border, margin, padding that is affecting your code. I don't know, I don't have enough information. But I believe it could be because Bootstrap puts automatic padding on .row
For this you can put
<div class="row g-0">
</div>
Bootstrap 5 - No gutters
Or if it is in another element, simply add the px-0 class that removes the padding from the widths.
I am trying to achieve a grid layout using Tailwind, but I have troubles of implementing it.
I thought at first to use flex but I think that would be difficult to achieve.
So far I am using grid grid-cols-3 gap-4 and it looks like the picture below, but I want the chart status to be below the X-as and Lijen, bottom to be databak, algemeen and data/filters.
<div className="h-full grid grid-flow-col-dense col-span-3 gap-4">
<div className="row-span-3">
1
</div>
<div className="col-span-2">
2
</div>
<div className="row-span-2 h-full col-span-2">
3
</div>
</div>
I cannot make the 3 element get the remaining height..
Take a look at this: https://tailwindcss.com/docs/grid-column
Basically, you want to span your cols.
<div class="grid grid-cols-3 gap-4">
<div class="...">01</div>
<div class="...">02</div>
<div class="...">03</div>
<div class="col-span-2 ...">04</div>
<div class="...">05</div>
<div class="...">06</div>
<div class="col-span-2 ...">07</div>
</div>
And you can do the same for the rows, so you can get Chart status in the same col under leien.
<div class="grid grid-rows-3 grid-flow-col gap-4">
<div class="row-span-3 ...">01</div>
<div class="col-span-2 ...">02</div>
<div class="row-span-2 col-span-2 ...">03</div>
</div>
Have you tried to just change the order of the items in the HTML?
If you're using for example a 12x12 grid you could also specify for each items the exact row/column you want it to span:
.grid-item-1 {
grid-column:2/4;
}
You could also try flex - it does have the "order" property:
.flex-item-1 {
order: 1;
}
It's not such a complex layout so you could try flex too.
I would like to create a grid with tailwind css where the first column is very narrow and the second one is very wide. Normally I find the tailwind docs very intuitive but I'm not understanding this one. Using grid-cols-{n} I can create equally sized columns but I don't understand how to make differently sized columns. How can I go about this?
If you want create columns with different widths then it will be an implicitly-created grid.
<div class="p-5 bg-slate-200">
<div class="grid grid-flow-col auto-cols-max gap-x-5">
<div class="bg-white w-20">Hello 1</div>
<div class="bg-white w-40">Hello 2</div>
<div class="bg-white">Hello 3</div>
</div>
</div>
https://play.tailwindcss.com/7XjBZDzwml
This is the relevant documentation here:
https://tailwindcss.com/docs/grid-auto-columns
And it explains how you can customize your theme if needed too.
Here's an example of a 2 column grid where the first column is narrow, and the second one is not:
<div class="grid grid-cols-[max-content_1fr] gap-x-4">
<div class="bg-red-200 p-4">Column 1</div>
<div class="bg-green-200 p-4">Column 2</div>
</div>
Tailwind play: https://play.tailwindcss.com/FTLi83L5zI
I'll assume that's not what you want as it's not 100% clear from your question. So here's a different example using a 12 column grid, you can span multiple columns to achieve something along the lines of what you are asking for:
<div class="grid grid-cols-12 gap-x-4 text-center">
<div class="bg-slate-400 p-4">Col</div>
<div class="bg-slate-400 p-4 col-span-2">Col</div>
<div class="bg-slate-400 p-4">Col</div>
<div class="bg-slate-400 p-4">Col</div>
<div class="bg-slate-400 p-4">Col</div>
<div class="bg-slate-400 p-4 col-span-4">Col</div>
<div class="bg-slate-400 p-4">Col</div>
<div class="bg-slate-400 p-4">Col</div>
</div>
Tailwind play: https://play.tailwindcss.com/XtUOu2cDD9
Finally, you could also do this:
<div class="grid grid-cols-12 gap-x-4 text-center">
<div class="bg-slate-400 p-4 col-span-4">Col</div>
<div class="bg-slate-400 p-4 col-span-8">Col</div>
</div>
Tailwind play: https://play.tailwindcss.com/bAnPhCdNfc
In the end the way I did it was:
grid grid-cols-[2rem,8fr]
Which creates a grid with 2 columns one, the first one 2rems wide the second one being 8fr wide
I'm just getting started with tailwind and I would like to grid essentially a row of images that fit the container.
Currently I am just stubbing in 2 photos for testing/getting to know tailwind purposes.
<main class="mt-12 lg:mt-32">
<section class="container mx-auto px-6">
<div class="w-full lg:flex items-center">
<div *ngFor="let item of photos">
<p class="text-md lg:text-xl font-light text-gray-800 mb-8">
{{item.description}}
</p>
<div class="grid grid-col-2 gap-2">
<img [src]="image" *ngFor="let image of item.images"
class="object-contain shadow rounded border-none">
</div>
</div>
</div>
</section>
</main>
This code is causing the 2 images to essentially appear underneath each other as seen here
https://i.imgur.com/vhSBkc7.png
Thank you for any help.
Your class should me grid-cols-2 and the img tag should have col-span-1. Checkout Grid Columns
<div class="grid grid-cols-2 gap-2"> // grid-cols-2
<img [src]="image" *ngFor="let image of item.images" class="col-span-1 object-contain shadow rounded border-none"> // col-span-1
</div>
I've created this layout in Angular 9 using Bootstrap 4's row and column classes. The charts are created by the Chart.js library.
For some reason I can't get the columns in each row to be of the same height, so I've come here for help.
Layout Markup
<div class="container mb-2">
<div class="row" *ngFor="let row of rows">
<div [ngClass]="{'col': component.cols == 4, 'col-9': component.cols == 3, 'col-6': component.cols == 2, 'col-3': component.cols == 1}" *ngFor="let component of row">
<app-chart></app-chart>
</div>
</div>
</div>
Component Markup
<div class="container-fluid my-1 component-shadow rounded-lg">
<div class="row border">
<div class="col pt-1">
<div class="h5 text-center">Some Chart</div>
</div>
</div>
<div class="row border-left border-right border-bottom">
<div class="col py-2">
<canvas
baseChart
width="400"
height="200"
[datasets]="chartData"
[labels]="chartLabels"
[options]="chartOptions"
[chartType]="chartType"
>
</canvas>
</div>
</div>
</div>
The column classes are determined by the conditions in *ngClass
Can you please check with below css, hope it will work for you.
.row { display : flex; flex-wrap :wrap; }
Nevermind. All I had to do is to set the maintainAspectRatio of the chart in ChartOptions to false.