how to vertically place item center of the screen using tailwind css - next.js

I am making form in next.js and i am unable to place the form vertically in the center of the screen. I am using one way that allows me to center it but it changes my form original size
the code without center of screen
import React from "react";
function SignUp() {
return (
<div className="h-screen bg-gray-50 pt-5 ">
<form className=" grid grid-cols-1 gap-4 p-9 rounded-xl shadow-xl bg-gray-50 max-w-sm mx-auto ">
<h1 className="text-2xl font-bold text-purple-600 ">
SignUp{" "}
<span className="text-sm font-normal text-gray-400">
to Trading Application
</span>
</h1>
<div>
<input className="input" type="text" placeholder="Company Name..." />
</div>
<div>
<input className="input" type="text" placeholder="Username..." />
</div>
<div>
<input className="input" type="text" placeholder="Email..." />
</div>
<div>
<input className="input" type="text" placeholder="Password..." />
</div>
<div>
<input
className="input"
type="text"
placeholder="Confirm Password..."
/>
</div>
<button className="btn btn-purple mt-3 rounded-full">
Create Account
</button>
</form>
</div>
);
}
export default SignUp;
code with center of screen trick but this trick changes the size of my form
<div className="h-screen bg-gray-50 pt-5 grid grid-cols-1">
<form className="place-self-center grid grid-cols-1 gap-4 p-9 rounded-xl shadow-xl bg-gray-50 max-w-sm mx-auto ">
<h1 className="text-2xl font-bold text-purple-600 ">
SignUp{" "}
<span className="text-sm font-normal text-gray-400">
to Trading Application
</span>
</h1>
<div>
<input className="input" type="text" placeholder="Company Name..." />
</div>
<div>
<input className="input" type="text" placeholder="Username..." />
</div>
<div>
<input className="input" type="text" placeholder="Email..." />
</div>
<div>
<input className="input" type="text" placeholder="Password..." />
</div>
<div>
<input
className="input"
type="text"
placeholder="Confirm Password..."
/>
</div>
<button className="btn btn-purple mt-3 rounded-full">
Create Account
</button>
</form>
</div>
tailwind code for btn, btn-purple & input
#layer components {
.input {
#apply border border-transparent focus:outline-none focus:ring-2 focus:ring-purple-600 focus:border-transparent shadow-md rounded-lg px-3 py-2 w-full font-light
transition duration-300;
}
.btn {
#apply rounded-md py-2 px-3 border-transparent focus:outline-none transition duration-500 uppercase font-medium;
}
.btn-purple {
#apply bg-purple-600 text-white hover:bg-purple-700;
}
}
these are the only line of code i used in my project and nothing more.
I want to vertically center the form without effecting any other changes to my form

i have got the solution of the problem
<div className="h-screen bg-gray-100 p-10 grid grid-cols-1 ">
<div className="place-self-center">
<form className=" grid grid-cols-1 gap-4 p-9 rounded-xl shadow-xl bg-gray-50 max-w-sm mx-auto ">
/* ..... some context ....*/
</form>
</div>
</div>
if we wrap our form into two divs and make parent div(div1) a grid and by using place-self-center class on child div(div2) then the size will not be effected and the context will automatically place in the vertical middle of the screen
<div className="h-screen grid grid-cols-1" >
1
<div className="place-self-center" >
2
<form>
context
</form>
</div>
</div>

Related

How to stop two nested divs with absolute positioning from overlapping each other?

I have a responsiveness issue with the project that I am currently developing
I have a sidebar with two nested divs (the sections that appear "separated" from each other - see preview below) with absolute positioning that are overlapping each other whenever the screen height is lower than the space required to fit all of the elements on screen.
Overlapping Elements
I would like to know how to stop the bottom section from overlapping the top section and make the sidebar's content scrollable from that point (once the "SOUND DETECTION DETAILS" container begins to overlap the "STROBE DURATION" container).
Here's the relevant index.html body section code:
<body class="bg-black">
<div id="sidebar">
<div id="sidebar-container" class="py-1.5 bg-gray-300 w-400px h-full absolute z-1 overflow-x-hidden opacity-100">
<div id="sidebar-logo" class="w-[300px] mx-auto">
<img class="" src="assets\img\logo-V2\logo-horizontal-black.png">
</div>
<hr class="w-[375px] border border-solid border-zinc-700 mx-auto">
<h3 class="text-center py-3 text-xl text-gray-600 font-semibold">STROBE SYNC MODE</h3>
<div id="auto-manual-container" class="w-[330px] ml-35px flex justify-between">
<button id="auto" class="w-[150px] h-10 mb-4 bg-white rounded font-bold text-xl text-themeOrange selected" onclick="autoMode()">AUTO</button>
<button id="manual" class="w-[150px] h-10 mb-4 bg-white rounded font-bold text-xl text-gray-700" onclick="manualMode();">MANUAL</button>
</div>
<hr class="w-[375px] border border-solid border-zinc-700 mx-auto">
<div id="auto-mode-container" class=""> <!-- "AM" stands for "Auto Mode" -->
<div id="input-device-container" class="w-[330px] ml-35px">
<h5 class="mt-3 mb-1 font-semibold text-sm text-gray-500">INPUT DEVICE</h5>
<select id="select-input-device" class="w-full h-10 mb-5 flex mx-auto bg-white rounded outline-none font-semibold text-center text-gray-700" required>
<option value="" selected disabled hidden>SELECT DEVICE</option>
<option value="" class="device text-left"> Integrated Player</option>
<option value="" class="device text-left"> Example Device</option>
</select>
</div>
<div id="frequency-range-focus-container" class="w-[330px] ml-35px">
<h5 class="mt-3 mb-1 font-semibold text-sm text-gray-500">FREQUENCY RANGE FOCUS</h5>
<div id="low-mid-high-container" class="w-full flex justify-between">
<button id="low" class="w-[100px] h-6 mb-4 pt-[2px] bg-white rounded font-bold text-base text-themeOrange selected" onclick="low_Btn()">LOW</button>
<button id="mid" class="w-[100px] h-6 mb-4 pt-[2px] bg-white rounded font-bold text-base text-gray-700" onclick="mid_Btn()">MID</button>
<button id="high" class="w-[100px] h-6 mb-4 pt-[2px] bg-white rounded font-bold text-base text-gray-700" onclick="high_Btn()">HIGH</button>
</div>
<button id="master" class="w-full h-12 mb-3 pt-[2px] bg-white rounded font-bold text-base text-gray-700" onclick="master_Btn()">MASTER</button>
</div>
<div id="detection-sensitivity-container" class="w-[330px] ml-35px">
<h5 id="sens-label" class="mt-3 mb-1 font-semibold text-sm text-gray-500"></h5>
<div id="sens-slider-container" class="w-full">
<input type="range" min="0" max="100" value="50" class="sens-slider w-full" id="sens-slider">
<p class="float-left font-regular text-sm text-gray-600">0</p>
<p class="float-right font-regular text-sm text-gray-600">100</p>
</div>
</div>
<br>
<div id="strobe-duration-container" class="w-[330px] ml-35px">
<h5 id="AM-duration-label" class="mt-3 mb-1 font-semibold text-sm text-gray-500"></h5>
<div id="duration-slider-container" class="duration-slider-container">
<input type="range" min="10" max="1000" value="200" class="duration-slider w-full" id="AM-duration-slider">
<p class="float-left font-regular text-sm text-gray-600">10</p>
<p class="float-right font-regular text-sm text-gray-600">1000</p>
</div>
</div>
<br>
<div id="sound-detection-details-container" class="w-[330px] ml-35px absolute bottom-[75px]">
<h5 class="mt-3 mb-1 font-semibold text-sm text-gray-500">SOUND DETECTION DETAILS</h5>
<div id="SDD-container" class="w-full h-40 px-4 bg-white rounded flex flex-col justify-evenly">
<div id="SCT-container" class="w-full">
<h4 class="float-left font-semibold text-base text-gray-600">SOUND COME THROUGH</h4>
<label id="SCT-check-container" class="float-right">
<input type="checkbox" checked disabled> <!-- only check when audio coming trough, change with javascript -->
<span class="SCT-checkmark"></span>
</label>
</div>
<hr>
<div id="tempo-container" class="w-full">
<h4 class="float-left font-semibold text-base text-gray-600">TEMPO:</h4>
<h4 id="bpm" class="float-right font-semibold text-base text-gray-600">150BPM</h4> <!-- change with javascript -->
</div>
<hr>
<div id="audio-meter-container" class="w-full">
<h4 class="float-left font-semibold text-base text-gray-600">AUDIO METER</h4>
<label id="AM-check-container" class="float-right"><!-- in this context "AM" stands for "Audio Meter" -->
<input type="checkbox">
<span class="AM-checkmark"></span>
</label>
</div>
</div>
</div>
<br>
<div id="AM-on-off-container" class="w-[330px] ml-35px flex justify-between absolute bottom-0">
<button id="AM-off" class="w-[150px] h-10 mb-4 bg-white rounded font-bold text-xl text-themeOrange selected" onclick="AM_turnOff()">OFF</button>
<button id="AM-on" class="w-[150px] h-10 mb-4 bg-white rounded font-bold text-xl text-gray-700" onclick="AM_turnOn();">ON</button>
</div>
</div>
</div>
</div>
</body>
I am using Tailwind CSS, however, I do understand pure CSS answers as i am able to convert them to Tailwinds fromatting. Thanks!
I have searched for hours trying to find a solution for a problem similar to mine, but with no avail. I have found tutorials with a context similar to mine but the elements' positioning were not of the same type.
I had tried to remove the absolute position of the divs encapsulating sound detection details and also refactored some of the code . Below is the code shared.
<script src="https://cdn.tailwindcss.com"></script>
<body class="bg-black">
<div id="sidebar">
<div id="sidebar-container" class="py-1.5 bg-gray-300 w-400px h-full absolute z-1 overflow-x-hidden opacity-100 overflow-y-scroll flex-col justify-center items-center">
<div id="sidebar-logo" class="w-[300px] mx-auto">
<img class="" src="assets\img\logo-V2\logo-horizontal-black.png">
</div>
<hr class="w-[375px] border border-solid border-zinc-700 mx-auto">
<h3 class="text-center py-3 text-xl text-gray-600 font-semibold">STROBE SYNC MODE</h3>
<div id="auto-manual-container" class="w-[330px] mx-[35px] flex justify-between">
<button id="auto" class="w-[150px] h-10 mb-4 bg-white rounded font-bold text-xl text-themeOrange selected" onclick="autoMode()">AUTO</button>
<button id="manual" class="w-[150px] h-10 mb-4 bg-white rounded font-bold text-xl text-gray-700" onclick="manualMode();">MANUAL</button>
</div>
<hr class="w-[375px] border border-solid border-zinc-700 mx-auto">
<!-- "AM" stands for "Auto Mode" -->
<div id="input-device-container" class="w-[330px] mx-[35px]">
<h5 class="mt-3 mb-1 font-semibold text-sm text-gray-500">INPUT DEVICE</h5>
<select id="select-input-device" class="w-full h-10 mb-5 flex mx-auto bg-white rounded outline-none font-semibold text-center text-gray-700" required>
<option value="" selected disabled hidden>SELECT DEVICE</option>
<option value="" class="device text-left"> Integrated Player</option>
<option value="" class="device text-left"> Example Device</option>
</select>
</div>
<div id="frequency-range-focus-container" class="w-[330px] mx-[35px]">
<h5 class="mt-3 mb-1 font-semibold text-sm text-gray-500">FREQUENCY RANGE FOCUS</h5>
<div id="low-mid-high-container" class="w-full flex justify-between">
<button id="low" class="w-[100px] h-6 mb-4 pt-[2px] bg-white rounded font-bold text-base text-themeOrange selected" onclick="low_Btn()">LOW</button>
<button id="mid" class="w-[100px] h-6 mb-4 pt-[2px] bg-white rounded font-bold text-base text-gray-700" onclick="mid_Btn()">MID</button>
<button id="high" class="w-[100px] h-6 mb-4 pt-[2px] bg-white rounded font-bold text-base text-gray-700" onclick="high_Btn()">HIGH</button>
</div>
<button id="master" class="w-full h-12 mb-3 pt-[2px] bg-white rounded font-bold text-base text-gray-700" onclick="master_Btn()">MASTER</button>
</div>
<div id="detection-sensitivity-container" class="w-[330px] mx-[35px]">
<h5 id="sens-label" class="mt-3 mb-1 font-semibold text-sm text-gray-500"></h5>
<div id="sens-slider-container" class="w-full">
<input type="range" min="0" max="100" value="50" class="sens-slider w-full" id="sens-slider">
<p class="float-left font-regular text-sm text-gray-600">0</p>
<p class="float-right font-regular text-sm text-gray-600">100</p>
</div>
</div>
<br>
<div id="strobe-duration-container" class="w-[330px] mx-[35px]">
<h5 id="AM-duration-label" class="mt-3 mb-1 font-semibold text-sm text-gray-500"></h5>
<div id="duration-slider-container" class="duration-slider-container">
<input type="range" min="10" max="1000" value="200" class="duration-slider w-full" id="AM-duration-slider">
<p class="float-left font-regular text-sm text-gray-600">10</p>
<p class="float-right font-regular text-sm text-gray-600">1000</p>
</div>
</div>
<br>
<div id="sound-detection-details-container" class=" w-[330px] mt-28 mx-[35px] bottom-[75px]">
<h5 class="mt-3 mb-1 font-semibold text-sm text-gray-500">SOUND DETECTION DETAILS</h5>
<div id="SDD-container" class="w-full h-40 px-4 bg-white rounded flex flex-col justify-evenly">
<div id="SCT-container" class="w-full">
<h4 class="float-left font-semibold text-base text-gray-600">SOUND COME THROUGH</h4>
<label id="SCT-check-container" class="float-right">
<input type="checkbox" checked disabled> <!-- only check when audio coming trough, change with javascript -->
<span class="SCT-checkmark"></span>
</label>
</div>
<hr>
<div id="tempo-container" class="w-full">
<h4 class="float-left font-semibold text-base text-gray-600">TEMPO:</h4>
<h4 id="bpm" class="float-right font-semibold text-base text-gray-600">150BPM</h4> <!-- change with javascript -->
</div>
<hr>
<div id="audio-meter-container" class="w-full">
<h4 class="float-left font-semibold text-base text-gray-600">AUDIO METER</h4>
<label id="AM-check-container" class="float-right"><!-- in this context "AM" stands for "Audio Meter" -->
<input type="checkbox">
<span class="AM-checkmark"></span>
</label>
</div>
</div>
</div>
<br>
<div id="AM-on-off-container" class=" w-[330px] mx-[35px] flex justify-between bottom-0">
<button id="AM-off" class="w-[150px] h-10 mb-4 bg-white rounded font-bold text-xl text-themeOrange selected" onclick="AM_turnOff()">OFF</button>
<button id="AM-on" class="w-[150px] h-10 mb-4 bg-white rounded font-bold text-xl text-gray-700" onclick="AM_turnOn();">ON</button>
</div>
</div>
</div>
</body>
Note: Since I don't have the styles defined with id like sidebar, so the sidebar appears in the left side.
ALso you can view here

How can I add spacing in file upload button

I wanted to add spacing between the Choose Files button and the text on right side. How can I do so by tailwind CSS. I had added the code below .
<script src="https://cdn.tailwindcss.com"></script>
<section class="body-font text-gray-600">
<div class="container mx-auto px-5 py-24">
<div class="mx-auto flex flex-col items-start lg:w-2/3">
<label class="title-font mb-2 text-sm font-medium text-gray-900" for="multiple_files">Upload multiple files</label>
<input class="w-full cursor-pointer rounded-lg border border-gray-300 bg-gray-100 px-4 py-2 text-lg text-gray-600 file:rounded-lg file:border-none file:bg-indigo-600 file:p-2 file:text-white hover:file:cursor-pointer hover:file:bg-indigo-500" id="multiple_files" type="file" multiple="" />
</div>
</div>
</section>
you can add margin-right to file, use this selector file:mr-4
<input class="file:mr-4" id="multiple_files" type="file" multiple="" />
have a look here :
https://play.tailwindcss.com/scMYVnSVjY

Problem to integrate a tailwindcss / laravel8 form, does not retrieve data and found an error SQLSTATE [23000] Integrity violation: 1048

I have two forms :
One works with the same data and the other don't.
I'm new to laravel and tailwindcss and i need to understand what is happening.
I must have made a mistake that I don't see or understand...
My form 1 : Data passes
<div class="max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8">
#foreach ($errors->all() as $error)
<span class="block text-red-500">{{ $error }}</span>
#endforeach
<form action="{{ route('categories.posts.store', $category) }}" method="post" enctype="multipart/form-data">
#csrf
<x-label for="title" value="Titre du post" />
<x-input id="title" name="title" />
<x-label for="content" value="Contenu du post" />
<textarea id="content" name="content"></textarea>
<x-label for="image" value="Image du post" />
<x-input type="file" id="image" name="image"/>
<x-button style="display: block !important" class="mt-10">Créer mon post</x-button>
</form>
</div>
My form 2 : Data don't passes
<div class="max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8">
<div class="bg-white shadow rounded-lg p-6">
<div class="grid lg:grid gap-6">
<div class="border focus-within:border-blue-500 focus-within:text-blue-500 transition-all duration-500 relative rounded p-1">
<div class="-mt-4 absolute tracking-wider px-1 uppercase text-xs">
#foreach ($errors->all() as $error)
<span class="block text-red-500">{{ $error }}</span>
#endforeach
<form action="{{ route('categories.posts.store', $category) }}" method="post" enctype="multipart/form-data">
#csrf
<p>
<label for="title" class="bg-white text-gray-600 px-1">Titre du Post</label>
</p>
</div>
<p>
<input id="title" autocomplete="false" tabindex="0" type="text" class="py-1 px-1 text-gray-900 outline-none block h-full w-full">
</p>
</div>
<div class="border focus-within:border-blue-500 focus-within:text-blue-500 transition-all duration-500 relative rounded p-1">
<div class="-mt-4 absolute tracking-wider px-1 uppercase text-xs">
<p>
<label for="image" value="Image du post" class="bg-white text-gray-600 px-1">Contenu du post</label>
</p>
</div>
<p>
<input type="file" id="image" name="image" autocomplete="false" tabindex="0" type="text" class="py-1 px-1 outline-none block h-full w-full">
</p>
</div>
<div class="border focus-within:border-blue-500 focus-within:text-blue-500 transition-all duration-500 relative rounded p-1">
<div class="-mt-4 absolute tracking-wider px-1 uppercase text-xs">
<p>
<label for="Content" class="bg-white text-gray-600 px-1">Contenu du post</label>
</p>
</div>
<p>
<textarea id="content" name="content"
rows="4"
class="ring-1 ring-gray-300 w-full rounded-md px-4 py-2 mt-2 outline-none focus:ring-2 focus:ring-teal-300"
></textarea>
</p>
</div>
<div class="border-t mt-6 pt-3">
<button class="rounded text-white px-3 py-1 bg-green-500 hover:shadow-inner hover:bg-green-700 transition-all duration-300">
Créer mon post
</button>
</div>
</div>
</form>
</div>
</div>
I get a nice error : SQLSTATE[23000]: Integrity constraint violation: 1048
Please add the name attribute to your title input.
<input id="title" name="title" autocomplete="false" tabindex="0" type="text" class="py-1 px-1 text-gray-900 outline-none block h-full w-full">

Align items with tailwind

I'm new using Tailwind and I have a simple text with input that consists of two rows
fiddle
Code:
<div>
<div
class="text-center p-4 flex flex-col space-x-5 space-y-4 md:flex-row md:space-y-0 md:space-x-4 md:justify-center"
>
<p class="text-center">Value:</p>
<div class="w-40">
<input
v-model="model.currentValue"
class="p-2 border-2 border-black-500 outline-none focus:bg-gray-100 w-10"
/>
</div>
</div>
<div
class="text-center p-4 flex flex-col space-x-5 space-y-4 md:flex-row md:space-y-0 md:space-x-4 md:justify-center"
>
<p class="text-center">Daily Value to upload:</p>
<div class="w-40">
<input
v-model="model.incrementBy"
class="p-2 border-2 border-black-500 outline-none focus:bg-gray-100 w-10"
/>
</div>
<button #click="update">Upload</button>
</div>
</div>
As you can see the two text are not vertically aligned, the same for inputs
issue
How can I align text to left and center it to input? Regards
Use CSS grid for this:
<link href="https://unpkg.com/tailwindcss#^2/dist/tailwind.min.css" rel="stylesheet">
<div class="p-4 grid grid-cols-2 gap-x-2">
<p class="text-right my-2">Value:</p>
<div class="text-left">
<input v-model="model.currentValue" class="p-2 border-2 border-black-500 outline-none focus:bg-gray-100 w-10" />
</div>
<p class="text-right my-2">Daily Value to upload:</p>
<div class="text-left">
<input v-model="model.incrementBy" class="p-2 border-2 border-black-500 outline-none focus:bg-gray-100 w-10" /><button #click="update">Upload</button>
</div>
</div>

How to create an equal width columns grid with gap in Tailwind?

First time i'm using css grid and i have problems with getting an equal content of my 3 columns when adding gap between them.
I'm not sure it's a tailwind problem (with the predefined classes) or with the grip or where the solution can come from (what i'm missing).
Here is an illustrative example:
https://codepen.io/erkage/pen/VwmxeRG
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.0.3/tailwind.min.css">
<div class="grid grid-cols-3 space-x-3 items-stretch mt-10 m-auto border border-gray-900" style="width:800px">
<div class="bg-blue-200 py-2">
<label class="block">Label 1</label>
<input type="text" class="rounded-lg border border-gray-400 py-2 w-full" placeholder="266px">
</div>
<div class="bg-blue-200 py-2">
<label class="block">Label 2</label>
<input type="text" class="rounded-lg border border-gray-400 py-2 w-full" placeholder="254px">
</div>
<div class="bg-blue-200 py-2">
<label class="block">Label 3</label>
<input type="text" class="rounded-lg border border-gray-400 py-2 w-full" placeholder="254px">
</div>
</div>
The HTML:
<div class="parent">
<div class="child">this is larger than 2-3</div>
<div class="child2">this is equal with 3rd</div>
<div class="child2">this is equal with 2nd</div>
</div>
The used css are (which comes from tailwind):
.parent {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
}
.child2 {
margin-right: calc(0.75rem * 0);
margin-left: calc(0.75rem * calc(1 - 0));
}
And i know that the main problem comes from that child 2 and 3 has a margin and 1 not but looking for a builtin solution (with css grid) if it exist.
Also child 1 can't have margin-left because of design circumstences.
replace space-x-3 by gap-x-3
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.0.3/tailwind.min.css">
<div class="grid grid-cols-3 gap-x-3 items-stretch mt-10 m-auto border border-gray-900" style="width:800px">
<div class="bg-blue-200 py-2">
<label class="block">Label 1</label>
<input type="text" class="rounded-lg border border-gray-400 py-2 w-full" placeholder="266px">
</div>
<div class="bg-blue-200 py-2">
<label class="block">Label 2</label>
<input type="text" class="rounded-lg border border-gray-400 py-2 w-full" placeholder="254px">
</div>
<div class="bg-blue-200 py-2">
<label class="block">Label 3</label>
<input type="text" class="rounded-lg border border-gray-400 py-2 w-full" placeholder="254px">
</div>
</div>

Resources