I am trying to create a form using Tailwind for a project. For this project I need to create a certain type of input field. When this field is being focused the placeholder of that field should change position on top of the border of the input. Is this possible using Tailwind?
This is my code for the input I am using:
<input
type="text"
name="email"
id="email"
v-model="email"
placeholder="Email address"
class="my-2 px-4 py-2 border rounded-lg text-gray-700 focus:outline-none text-sm"
/>
This is an example of how to input should be displayed when it is being focused:
You can use :
<div class="relative z-0 px-2 w-full group">
<label for="first_name" class="font-mono uppercase font-bold text-[11px] text-gray-900 dark:text-gray-300
bg-white relative px-1 top-2 left-3 w-auto group-focus-within:text-red-600 ">
Email Address
</label>
<input type="email" name="first_name" id="first_name" class="h-8 text-10 bg-gray-50 border py-55-rem border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
required="" placeholder="contact#gmail.com" />
Or
<div class="relative z-0 px-2 w-full group">
<label for="first_name" class="font-mono uppercase font-bold text-11 text-gray-900 dark:text-gray-300
bg-white relative px-1 group-focus-within:top-2 top-7 left-3 w-auto group-focus-within:text-red-600 ">
Email Address
</label>
<input type="email" name="first_name" id="first_name" class="h-8 text-[11px]text-10 bg-gray-50 border py-55-rem border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
required="" placeholder="contact#gmail.com" />
#tailwind base;
#tailwind components;
#tailwind utilities;
<link href="https://unpkg.com/tailwindcss#^1.0/dist/tailwind.min.css" rel="stylesheet">
<script src="https://cdn.tailwindcss.com/3.0.23"></script>
<div class="relative z-0 px-2 w-full group">
<label for="first_name" class="font-mono uppercase font-bold text-11 text-gray-900 dark:text-gray-300 bg-white relative px-1 group-focus-within:top-2 top-7 left-3 w-auto group-focus-within:text-red-600"> Email Address </label>
<input type="email" name="first_name" id="first_name" class="h-8 text-[11px]text-10 bg-gray-50 border py-55-rem border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
required="" placeholder="contact#gmail.com" />
</div>
<div class="relative z-0 px-2 w-full group">
<label for="first_name" class="font-mono uppercase font-bold text-[11px] text-gray-900 dark:text-gray-300 bg-white relative px-1 top-2 left-3 w-auto group-focus-within:text-red-600"> Email Address </label>
<input type="email" name="first_name" id="first_name" class="h-8 text-10 bg-gray-50 border py-55-rem border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
required="" placeholder="contact#gmail.com" />
</div>
Related
Whenever I use Google Chrome's responsive view to see my login form component at different screen sizes, I notice some strange behaviour. Once the viewport shrinks to a certain width, specifically 1024px, it stops shrinking horizontally and instead starts shrinking on both axis at the same fixed rate. This is despite there being ample space in the form still.
I tried setting fixed (non-percentile) values for the top-level to hopefully constrain the height to a specific scale, but this hasn't fixed the issue unfortunately. If anyone could help me to troubleshoot this behaviour I would be very appreciative!
The code is written using the React library and makes use of TailwindCSS classes for styling.
<div className='
w-3/4 xl:w-1/3 h-[26rem]
absolute
top-1/2 left-1/2 xl:left-3/4
-translate-y-1/2 -translate-x-1/2 xl:-translate-x-3/4'>
<div className='
w-full h-full
relative
bg-navWhite
py-12 px-4 sm:px-8
shadow-lg
flex flex-col'>
<h1 className='
font-navigation font-medium text-3xl tracking-tight
text-navGrey
text-center'>
Sign In
</h1>
<p className='
mt-2
font-navigation
text-navGrey text-center
font-light text-base'>
Enter your credentials below, to access your dashboard.
</p>
<form className='
flex flex-col gap-y-4 mt-4'>
<div className='
w-full flex flex-row-reverse
border-b border-b-navGrey/20
focus-within:border-b-dashboardBlue
transition-colors duration-200'>
<input
type="text"
placeholder="Email Address"
value={username}
name='Email signup'
onChange={usernameInput}
className='
p-2 w-full peer
bg-transparent
outline-none focus:ring-0
sm:text-sm'
/>
<span className='
material-symbols-outlined
text-2xl
text-navGrey/50
peer-focus:text-dashboardBlue
transition-colors duration-200
h-full
p-2
select-none'>
mail
</span>
</div>
<div className='
w-full flex flex-row-reverse
border-b border-b-navGrey/20
focus-within:border-b-dashboardBlue
transition-colors duration-200'>
<span
onClick={passwordVisibility}>
<span className='
cursor-pointer select-none
material-symbols-outlined
text-2xl
h-full
p-2'
style={showPassword === true ? styles.active : styles.inactive}>
{showPassword === true ? 'visibility' : 'visibility_off'}
</span>
</span>
<input
type='password'
id='passwordField'
placeholder="Password"
value={password}
name='Email signup'
onChange={passwordInput}
className='
p-2 w-full peer
bg-transparent
outline-none focus:ring-0
sm:text-sm'
/>
<span className='
material-symbols-outlined
text-2xl
text-navGrey/50
peer-focus:text-dashboardBlue
transition-colors duration-200
h-full
p-2
select-none'>
lock
</span>
</div>
<div className="flex justify-between p-2 -mb-2">
<label className='self-end'>
<input type="checkbox" checked={rememberPassword} onChange={() => toggleRemember(!rememberPassword)} className='relative align-middle w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600'/>
<span className="
sm:text-sm
text-navGrey/50
ml-1">
Remember me
</span>
</label>
<span className="
cursor-pointer
sm:text-sm
text-dashboardBlue
no-underline
hover:underline
transition-all duration-200">
Forgot password?
</span>
</div>
<button
className='
w-full p-6 mt-2
relative
bg-dashboardBlue
focus:outline-none focus:ring-2 focus:ring-dashboardBlue focus:ring-offset-2'
onClick={loginAction}>
<div className='relative' style={loading === true ? styles.notLoading : styles.loading}>
<span className='
absolute
top-1/2 -translate-y-1/2 left-1/2 -translate-x-1/2
text-white
font-semibold
text-lg
transition-all duration-300'>
Login
</span>
</div>
<Loader visibility={loading === true ? styles.loading : styles.notLoading} />
</button>
</form>
</div>
</div>
So my problem is i can't style the same way as other form rows/attributes with tailwindcss on symfony
enter image description here
<section class="bg-gray-50 grey:bg-gray-900">
<div class="flex flex-col items-center justify-center px-6 py-8 mx-auto md:h-screen lg:py-0">
<a href="#" class="flex items-center mb-6 text-2xl font-semibold text-gray-900 dark:text-white">
<img class="w-8 h-8 mr-2" src="https://flowbite.s3.amazonaws.com/blocks/marketing-ui/logo.svg" alt="logo">
Flowbite
</a>
{{ form_start(registrationForm, {
attr: {'class': 'w-full bg-white rounded-lg shadow grey:border md:mt-0 sm:max-w-md xl:p-0 grey:bg-gray-900 grey:border-gray-700'}
}) }}
<div class="p-6 space-y-4 md:space-y-6 sm:p-8">
<h1 class="text-xl font-bold leading-tight tracking-tight text-gray-900 md:text-2xl dark:text-black">
Create and account
</h1>
<form class="space-y-4 md:space-y-6" action="#">
<div>
{{ form_row(registrationForm.email, {
label: 'Email',
attr: {'class': 'bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="name#company.com" required=""'}
}) }}
</div>
<div>
{{ form_row(registrationForm.plainPassword, {
label: 'Passwords',
attr: {'class': 'bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="name#company.com" required=""'}
}) }}
</div>
<div>
{{ form_row(registrationForm.telegram, {
label: 'telegram',
attr: {'class': 'bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="name#company.com" required=""'}
}) }}
</div>
<div>
{{ form_row(registrationForm.username, {
label: 'Gebruikersnaam',
attr: {'class': 'bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="name#company.com" required=""'}
}) }}
</div>
<div class="flex items-start">
<div class="flex items-center h-5">
<input id="terms" aria-describedby="terms" type="checkbox" class="w-4 h-4 border border-gray-300 rounded bg-gray-50 focus:ring-3 focus:ring-primary-300 dark:bg-gray-700 dark:border-gray-600 dark:focus:ring-primary-600 dark:ring-offset-gray-800" required="">
</div>
<div class="ml-3 text-sm">
<label for="terms" class="font-bold text-gray-900 dark:text-gray-900">I accept the <a class="font-medium text-primary-600 hover:underline dark:text-primary-900" href="{{ path('app_faq') }}">Terms and Conditions</a></label>
</div>
</div>
<button type="submit" class="group relative flex w-full justify-center rounded-md border border-transparent bg-indigo-600 py-2 px-4 text-sm font-medium text-white hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2">
Create an account</button>
<p class="text-sm font-light text-gray-500 dark:text-black-400">
Already have an account? Login here
</p>
</form>
</div>
</div>
</div>
</section>
I've tried to every way i could to get it right but it's shows not the way i want i've tried to find information on symfony website too.
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">
I'm using Tailwindcss to style my forms but when I try to submit and catch errors for required fields, the size on input fields increases.
Form code
<Formik
initialValues={userData.signup}
onSubmit={submitData}
validationSchema={signupSchema}
>
{({ values, errors, touched, handleChange, handleSubmit }) => {
return (
<>
<Form className="grid grid-cols-2 gap-3" onSubmit={handleSubmit} id="form">
<div className="relative flex w-full flex-wrap items-stretch mb-3">
<span className="z-10 leading-snug font-normal absolute text-center text-gray-400 bg-transparent rounded text-base items-center justify-center w-8 pl-3 py-3">
<i className="fas fa-user-circle"></i>
</span>
<input
className={
`${touched.name && errors.name ?
"form-input border py-3 border-red-400 placeholder-gray-400 text-gray-700 relative rounded text-sm w-full pl-10" :
"form-input border py-3 border-gray-400 placeholder-gray-400 text-gray-700 relative rounded text-sm focus:border-green-200 w-full pl-10"}`
}
type="text"
name="name"
placeholder="Name"
value={values.name}
onChange={handleChange}
/>
<span className="text-red-400 self-center">{touched.name && errors.name}</span>
</div>
<div className="relative flex w-full flex-wrap items-stretch mb-3">
<span className="z-10 leading-snug font-normal absolute text-center text-gray-400 bg-transparent rounded text-base items-center justify-center w-8 pl-3 py-3">
<i className="fas fa-envelope"></i>
</span>
<input
className={
`${touched.email && errors.email ?
"form-input border py-3 border-red-400 placeholder-gray-400 text-gray-700 relative rounded text-sm w-full pl-10" :
"form-input border py-3 border-gray-400 placeholder-gray-400 text-gray-700 relative rounded text-sm focus:border-green-200 w-full pl-10"}`
}
type="email"
name="email"
placeholder="Email"
value={values.email}
onChange={handleChange}
/>
<span className="text-red-400 self-center">{touched.email && errors.email}</span>
</div>
<div className="relative flex w-full flex-wrap items-stretch mb-3">
<span className="z-10 leading-snug font-normal absolute text-center text-gray-400 bg-transparent rounded text-base items-center justify-center w-8 pl-3 py-3">
<i className="fas fa-phone"></i>
</span>
<input
className={
`${touched.phoneNumber && errors.phoneNumber ?
"form-input border py-3 border-red-400 placeholder-gray-400 text-gray-700 relative rounded text-sm w-full pl-10" :
"form-input border py-3 border-gray-400 placeholder-gray-400 text-gray-700 relative rounded text-sm focus:border-green-200 w-full pl-10"}`
}
type="text"
name="phoneNumber"
placeholder="Phone number"
value={values.phoneNumber}
onChange={handleChange}
/>
<span className="text-red-400 self-center">{touched.phoneNumber && errors.phoneNumber}</span>
</div>
<div className="relative flex w-full flex-wrap items-stretch mb-3">
<span className="z-10 leading-snug font-normal absolute text-center text-gray-400 bg-transparent rounded text-base items-center justify-center w-8 pl-3 py-3">
<i className="fas fa-lock"></i>
</span>
<input
className={
`${touched.password && errors.password ?
"form-input border py-3 border-red-400 placeholder-gray-400 text-gray-700 relative rounded text-sm w-full pl-10" :
"form-input border py-3 border-gray-400 placeholder-gray-400 text-gray-700 relative rounded text-sm focus:border-green-200 w-full pl-10"}`
}
type="password"
name="password"
placeholder="Password"
value={values.password}
onChange={handleChange}
/>
<span className="text-red-400 self-center">{touched.password && errors.password}</span>
</div>
{/* <div className="relative flex w-full flex-wrap items-stretch mb-3">
<span className="z-10 leading-snug font-normal absolute text-center text-gray-400 bg-transparent rounded text-base items-center justify-center w-8 pl-3 py-3">
<i className="fas fa-lock"></i>
</span>
<input
className={
`${touched.confirmPassword && errors.confirmPassword ?
"form-input border py-3 border-red-400 placeholder-gray-400 text-gray-700 relative rounded text-sm w-full pl-10" :
"form-input border py-3 border-gray-400 placeholder-gray-400 text-gray-700 relative rounded text-sm focus:border-green-200 w-full pl-10"}`
}
type="password"
name="confirmPassword"
placeholder="Confirm Password"
value={values.confirmPassword}
onChange={handleChange}
/>
<span className="text-red-400 self-center">{touched.confirmPassword && errors.confirmPassword}</span>
</div> */}
</Form>
<SignupBtn type="submit" form="form"> Sign Up </SignupBtn>
<SocialBtns />
</>
)
}}
</Formik>
Form before error highlighting using Formik
Form after error highlighting using Formik
This is the code I used to style the forms.
Am I missing anything here? Thanks
Remove flex from the button container...
<div class="relative w-full flex-wrap mb-3">
<button class="py-2 px-4 bg-green-500 text-white font-semibold rounded-lg hover:bg-green-700 w-full">
Sign Up
</button>
</div>
Codeply
Not sure how to debug this, but inspecting some items that are supposedly inside a flex, they are still off by a few fractions of a pixel.
On the screenshot below, notice the slight variation between the Id / Due Date and the Project input fields. https://imgur.com/a/je3Sgiu
What could be the issue here? I tried it in Firefox, Safari, and Chrome, all facing the issue.
Edit:
Added the html snippet below
<div class="lg:w-4/5 mr-auto ml-auto mt-16 sm:px-6 lg:px-8">
<div class="">
<form method="GET" autocomplete="off">
<div class="md:flex">
<div class="mx-2">
<label class="block uppercase tracking-wide text-gray-700 text-xs font-bold my-5" for="grid-state">
Id
</label>
{% render_field invoice_filter.form.id class="w-full lg:w-40 block appearance-none bg-white border border-gray-500 text-gray-700 py-3 px-4 pr-8 rounded leading-tight focus:outline-none focus:bg-white focus:border-gray-500" %}
</div>
<div class="mx-2">
<label class="block uppercase tracking-wide text-gray-700 text-xs font-bold my-5" for="grid-state">
Project
</label>
{% render_field invoice_filter.form.project class="w-full lg:w-40 block appearance-none bg-white border border-gray-500 text-gray-700 py-3 px-4 pr-8 rounded leading-tight focus:outline-none focus:bg-white focus:border-gray-500" %}
</div>
<div class="mx-2">
<label class="block uppercase tracking-wide text-gray-700 text-xs font-bold my-5" for="grid-state">
Due Date
</label>
{% render_field invoice_filter.form.due_date class="w-full lg:w-40 block appearance-none bg-white border border-gray-500 text-gray-700 py-3 px-4 pr-8 rounded leading-tight focus:outline-none focus:bg-white focus:border-gray-500" %}
</div>
</div>
<button class="whitespace-no-wrap mr-5 bg-green-600 hover:bg-green-700 text-white py-2 my-2 mx-2 px-6 rounded-lg" type="submit">Apply filter</button>
</form>
</div>
</div>
The {% render_field ... %} tags are just a Django specific way of adding classes to the form fields,
It essentially says
`<input class="...." />`