Grid in Tailwind CSS + React not working as intended

Viewed 167

I am making a signup form with react and tailwind CSS and I seem to have hit a roadblock when I am trying to get this one label and text-field aligned. The screenshot of what it looks like is below: Screenshot of the form

As you can probably make out I intend to have the postcode label and text field next to the county label and text-field. To achieve this I am using the grid layout and my code looks like this (The part in question is under the address section):

const SignupPage = () => {
  return(
    <div className="container rounded-lg shadow-lg mx-auto">
        <h1 className="font-hk text-slate-800 text-left font-bold text-2xl p-5 ">Your Info</h1>
          <form className="grid grid-cols-1 items-start gap-1 sm:grid-cols-2">

            {/*Title Selector*/}
            <label className="font-hk px-5 text-lg text-left text-slate-800 row-start-1 sm:row-start-1">Title</label>
            <select className="font-hk font-light rounded-lg border border-gray-300 focus:outline-none focus:border-green-500 mx-5 row-start-2 sm:col-span-2" >
              <option>Select one ...</option> 
              <option>Mr</option> 
              <option>Mrs</option> 
              <option>Miss</option> 
              <option>Ms</option> 
            </select>

            {/*Name fields*/}
            <label className="font-hk px-5 pt-2 text-lg text-left text-slate-800 row-start-3">First name</label>
            <input type="text" className="mx-5 font-hk font-light rounded-lg border border-gray-300 row-start-4 sm:col-start-1" required="true"/>
            <label className="font-hk px-5 pt-2 text-lg text-left text-slate-800 row-start-5 sm:row-start-3 sm:col-start-2">Last name</label>
            <input type="text" className="mx-5 font-hk font-light rounded-lg border border-gray-300 row-start-6 sm:row-start-4 sm:col-start-2" required="true"/>

            {/*Gender Selector and Date-Picker*/}
            <lable className="font-hk pt-2 px-5 text-lg text-left text-slate-800 row-start-7 sm:row-start-5">Gender</lable>
            <select className="font-hk font-light rounded-lg border border-gray-300 focus:outline-none focus:border-green-500 mx-5 row-start-8 sm:row-start-6 sm:col-span-1" >
              <option>Select one..</option> 
              <option>Male</option> 
              <option>Female</option> 
            </select>
            <label className="font-hk pt-2 px-5 text-lg text-left text-slate-800 row-start-8 sm:row-start-5 sm:col-start-2">Date of Birth</label>
            <input type="date" className="font-hk mx-5 pt-2 px-5 text-left text-slate-800 rounded-lg border border-gray-300 row-start-9 sm:row-start-6 sm:col-start-2" />
    
            {/*Address*/}
            <label className="font-hk px-5 pt-2 text-lg text-left text-slate-800 row-start-10 sm:row-start-7">Street</label>
            <input type="text" className="mx-5 font-hk font-light rounded-lg border border-gray-300 row-start-11 sm:row-start-8 sm:col-start-1" required="true"/>
            <label className="font-hk px-5 pt-2 text-lg text-left text-slate-800 row-start-12 sm:row-start-7 sm:col-start-2">City</label>
            <input type="text" className="mx-5 font-hk font-light rounded-lg border border-gray-300 row-start-13 sm:row-start-8 sm:col-start-2" required="true"/>
            <label className="font-hk px-5 pt-2 text-lg text-left text-slate-800 row-start-14 sm:row-start-9">County</label>
            <input type="text" className="mx-5 font-hk font-light rounded-lg border border-gray-300 row-start-15 sm:row-start-10 sm:col-start-1" required="true"/>
            <label className="font-hk px-5 pt-2 text-lg text-left text-slate-800 row-start-16 sm:row-start-9 sm:col-start-2">Postcode</label>
            <input type="text" className="mx-5 font-hk font-light rounded-lg border border-gray-300 row-start-17 sm:row-start-10 sm:col-start-2" required="true" />

          </form>       
    </div> 
  );
}

export default SignupPage;

I have checked my code to see if I have used the correct row-start-{n} and col-start-{n} values. I even tried explicitly setting the row-span-{n} value and it is still not giving me the intended results. Can someone explain to me what is going on here?

These are the versions of the frameworks I am using for your reference:

  • tailwindcss: 3.0.24
  • @tailwindcss/forms: 0.5.2
  • react: 18.1.0

PS: This is my first question on StackOverflow any pointers on how I could ask questions better in future are appreciated as well :)

1 Answers

Out of the box, Tailwind does not support row-start values greater than row-start-7. See: https://tailwindcss.com/docs/grid-row

You can add a custom value inline by using the "arbitrary values" utility class format: row-start-[8].

Alternatively, you can add the values 8-10 to your tailwind.config.js file to extend this utility class.

module.exports = {
  theme: {
    extend: {
      gridRowStart: {
        '8': '8',
        '9': '9',
        '10': '10'
      }
    }
  }
}
Related