How to create this complex layout in tailwind? - html

I want to create a layout like below with tailwind. I don't know how to make the blue area have full width but the purple area has a limit at 9/12 grid.
12 column is max 1200px.
Here is my code:
<link href="https://unpkg.com/tailwindcss#^2/dist/tailwind.min.css" rel="stylesheet"/>
<div class="container lg:w-1200px bg-red-500 mx-auto flex">
<div class="w-3/12 bg-blue-500 grid place-items-center h-screen">3/12</div>
<div class="w-9/12 h-80 relative">
<div class="bg-yellow-500 h-20"></div>
<div class="bg-green-500 h-screen grid place-items-center">9/12</div>
</div>
</div>
Maybe it's just complex with me, not you. So sorry about that. Thanks!

To create the target layout
absolutely position the blue box relative to screen, using w-screen class so that it takes the entire screen width
use a standard grid layout for other boxes, relying on col-span classes to size them according to requirements
finally, use w-[1200px] class to set the width of the grid layout, and add a left-padding pl-[300px] to the blue box so that its content is away from the red box. As using these "pixel-perfet" arbitrary classes does not work in the code snippet, I replaced them respectively with w-96 and pl-24
See below an implementation example
<link href="https://unpkg.com/tailwindcss#^2/dist/tailwind.min.css" rel="stylesheet">
<div class="w-96 h-screen bg-red-100 grid grid-cols-12">
<div class="bg-red-500 col-span-3 z-20 relative">Something in red</div>
<div class="bg-blue-500 w-full absolute pl-24 h-12 z-0">Something in blue</div>
<div class="bg-purple-700 col-span-9 z-20 transform translate-y-7">Something in purple</div>
<div></div>
</div>

Related

How can I achieve this two-column layout with Tailwind?

I need to create three divs positioned like below:
Green div should be 75% width and red divs should have 25% width and 50% of height, placed in column. And everything should be responsive.
Right now I have something like here:
<div className="w-full">
<div className="w-3/4 float-left">
</div>
<div className="w-1/4 float-right">
<div id="red-one"></div>
<div id="red-two"></div>
</div>
</div>
but it not this same as i expected :/
can someone tell me how to do this?
thanks for any help!
Oldish option (see nowdays below that one) :you can use and mix the table-layout display and regular block display via tailwind class
Possible example
/* your scrennshot's borders */
div div {border:solid red;}
div.table-cell{border-color:green}
<link href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet"/>
<div class="table w-full p-2">
<div class="table-cell w-3/4 p-2">hello</div>
<div class="p-2 ml-2"> the</div>
<div class="p-2 mt-2 ml-2">world</div>
</div>
any draw back ?
yes, if both content of the rights side div are shorter than the content of the left one, it wont fill the column
nowdays option: grid
Advised example:
div div {border:solid red;}
div div:first-child{border-color:green}
<link href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet"/>
<div class="grid grid-cols-4 p-2 grid-cols-2 gap-2">
<div class="col-1 col-span-3 row-span-2 p-2">hello</div>
<div class="col-2 p-2"> the</div>
<div class="col-2 p-2">world</div>
</div>
drawbacks ? none, but you will have to create your own class to set the grid-template-colums property to match your columns's widths as commented by #bqardi
Container: grid grid-cols-4 and green div: col-span-3 row-span-2? No need to create own class

Using flexbox grow but allow the content to overflow

I'm a bit new to using flexbox and I've ran into one problem I can't seem to fix.
What I want:
I want to have a container taking the available height, but whenever the content inside it takes up more space than the containers height, apply overflow:scroll
Context:
Ref image:
container image
As you see on the image, everything inside of the red brackets are covered inside of a div with flex-grow:1, I want this because the images might be different sizes so therefore I need the div to take the reamining space.
As for the white container, that is also using flex-grow:1 so that the button can be on the bottom of the div.
Now, what I would like is for the content inside of the blue brackets to be taking the available height, but if there is more content than the available height, then I want it to be scrollable.
The thing that happens now if I add a lot more content to the container inside of the blue brackets, it pushes everything below it further down, meaning the overflow isn't working.
E.g Like so
As you see in the image, everything is just pushed further down and the div is being stretched.
Here is the code I have so far:
<div class="flex flex-col grow overflow-y-auto w-3/4 my-2 mx-auto bg-white max-h-full">
<!-- img -->
<div>
<img [src]="currentUser.photoURL" class="w-full mx-auto">
</div>
<!-- information -->
<div class="flex flex-col text-black grow">
<!-- Info -->
<div class="flex flex-col p-2 divide-y grow overflow-y-auto">
<div class="flex flex-col">
<p class="font-bold">{{currentUser.displayName}}</p>
<p class="font-thin">{{currentUser.email}}</p>
</div>
<div class="p-2 overflow-y-auto max-h-[90%]">
<div class="h-full grow-0 overflow-y-auto">
<p>
some information about {{currentUser.displayName}}
</p>
<ul>
<li>
Some values are
</li>
<li>
Some experience are...
</li>
<li>
Why im helping people...
</li>
</ul>
</div>
</div>
</div>
<!-- Message -->
<div class="shrink-0 p-2 text-center w-full bg-blue-500">
<button>Send melding</button>
</div>
</div>
</div>
I'm using tailwindCSS for this project, but will happily take suggestions in normal css as well.
I think the simplest solution for this would be to set the div you want to be a scrollable as "display: block" (or at least some version of block) with a fixed height. Once you apply that fixed height, your overflow content ought to be scrollable.

Center vertically while ignoring other elements

I'm trying to center this burger. I used "grid place-items-center" so it gets centered and "h-screen" in order to let it be centered in the full height.
The problem is that it's not in the center, obviously because of the logo at the top.
how do i ignore this logo and center it anyways?
The navbar i'm coding
Greetings, PixelPage
You are almost there. The only thing you need to do is add a w-full to the parent div of logo (the one with the absolute class).
<div class="fixed left-0 h-screen bg-gradient-to-t from-[#07C8F9] to-[#6D8AE4] w-24">
<div class="w-full absolute grid place-items-center mt-8">
<img src="/assets/branding/logo-white.png" class="w-12 h-12"></img>
</div>
<div class="grid place-items-center h-full">
<img src="/assets/common/Burger.png" class="w-16 h-16"></img>
</div>
</div>
Hope this helps.
Read through this guide, it is invaluable, and I reference it all the time. It should help you figure out how to use grid to place your items: https://css-tricks.com/snippets/css/complete-guide-grid/

How to get rid of extra cells generated by grid?

In order to make my site responsive using Tailwind CSS, I set my classes to change from two columns to two rows when it passes some defined breakpoints
<section id="hero" class="pt-12 pb-12 bg-yellow-400">
<div class="container grid items-center max-w-6xl px-2 py-2 mx-auto bg-yellow-100 lg:grid-cols-2 md:grid-cols-2 sm:grid-rows-2 xs:grid-rows-2">
<div class="">
<img src="./img/port-vector.png"
class="scale-50"
alt="logo">
</div>
<div class="text-center xs:pt-24 xs:pb-24 sm:pt-24 sm:pb-24 auto-cols-fr">
<h1 class="text-4xl">GABRIEL STEVEN</h1>
<h3 class="text-2xl">Front-End Web Dev, Designer</h3>
</div>
</div>
</section>
This works fine when it is in mobile, but once it is expanded to larger sizes, it leaves behind extra grid cells, which results in unwanted empty space. How can I get rid of these unwanted cells?
As #Saddy mentioned, you need to reduce the number of rows to 1 in addition to setting the columns to 2.
<div class="container grid items-center max-w-6xl px-2 py-2 mx-auto bg-yellow-100 md:grid-cols-2 md:grid-rows-1 xs:grid-rows-2">
As a side note, you can also omit sm:grid-rows-2 and lg:grid-cols-2 as the changes get applied from the given breakpoint onwards (e.g., using md: will also apply to lg: and xl: breakpoints).

Getting buttons to stretch full screen with Tailwind

I'm trying to get buttons to stretch across the screen with tailwind, but either they align left and don't stretch out (most cases), or - as in the current state of the code, they seem to stretch off the right hand side of the screen!
I'm sure I'm missing something obvious but can't see what it is. My header and footer stretch appropriately, and originally I just duplicated them, but as buttons, not divs.
Code (stretching off screen version) currently looks like this:
<body>
...
<div class="">
<div class="block">
<ul class="">
<li><button class="w-full bg-orange-200 hover:bg-orange-400 rounded-lg mx-6 my-4">
<div class="text-black text-lg content-center">
<h2 class="font-bold">Mike's big adventure</h2><br>
<div class="text-black text-base">Aargh, zombies!</div>
<div class="text-gray-600 text-xs">
<div>Created: 2020-03-24T12:57:01.753Z</div>
<div>Updated: 2020-03-24T13:00:06.411Z</div>
</div>
</div>
</button></li>
... more list items
</ul>
</div>
</div>
...
(Note, don't think it makes a difference, but the html is actually being generated by an Elm SPA)
How do I need to nest the various container, w-full, w-screen, button etc. and what combo do I need to get what I want?
Edit: This snippet isn't the only thing that isn't stretching. For example neither does the page header. The page footer, which is attached to the bottom of the screen, stretches all the way though ...
Header:
<div class="container flex-auto w-screen m-2">
<div class="w-full content-center bg-orange-500 rounded-lg">
<h1 class="font-bold text-5xl text-center">Header</h1>
</div>
</div>
Footer:
<div class="container flex-auto w-screen mx-2">
<div class="absolute inset-x-0 bottom-0 bg-orange-500 rounded-lg m-2">
<div class="m-4">Footer</div>
</div>
</div>
You should make the <li> full width since the button is nested in it and take the width of its parent which is the li. Add a w-full class.
Maybe also try adding a block class to the button as well
Add