Chapter 07

tailwindcss form / フォーム

knaka Tech-Blog
knaka Tech-Blog
2021.04.29に更新

概要:

tailwindcss form の設定の例になります


関連

https://v1.tailwindcss.com/components/forms

外観

  • type=text, textarea , select の例です


  • コード

https://github.com/kuc-arc-f/tailwind-sample/blob/main/src/01_form3.html

src/01_form3.html

  • type=textの例です
01_form3.html
      <div class="mb-4">
        <label class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" for="grid-last-name">
          Name
        </label>
        <input class="appearance-none block w-full bg-white text-gray-700 border border-gray-200 rounded py-3 px-4 leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
         id="grid-last-name" type="text" placeholder="Name123">
      </div>
  • type=textarea
01_form3.html
      <div class="mb-6">
        <label class="block text-gray-700 text-sm font-bold mb-2">
          TextArea :
        </label>
        <textarea class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
         name="goodMessage"></textarea>
      </div>
  • type=select
01_form3.html
      <div class="w-full px-3">
        <label class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" for="grid-password">
          Select :
        </label>
        <div class="relative">
          <select class="block appearance-none w-full bg-white border border-gray-200 text-gray-700 py-3 px-4 pr-8 rounded leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
           id="grid-state">
            <option>New Mexico</option>
            <option>Missouri</option>
            <option>Texas</option>
          </select>
          <div class="pointer-events-none absolute inset-y-0 right-0 flex items-center px-2 text-gray-700">
            <svg class="fill-current h-4 w-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><path d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z"/></svg>
          </div>          
        </div>
      </div>

radio など

外観 radio


src/01_form2.html

  • type=radio
01_form2.html
      <div class="mb-4">
        <label class="block text-gray-700 text-sm font-bold mb-2" for="name">
          radio :
        </label>
        <label class="inline-flex items-center">
          <input name="presentationScore" class="form-radio" type="radio" value="4" checked>
          <span class="ml-2">radio_1</span>
        </label>
        <label class="inline-flex items-center">
          <input name="presentationScore" class="form-radio" type="radio" value="3">
          <span class="ml-2">radio_2</span>
        </label>
        <label class="inline-flex items-center">
          <input name="presentationScore" class="form-radio" type="radio" value="2">
          <span class="ml-2">radio_3</span>
        </label>
      </div>
  • type=checkbox
01_form2.html
      <div class="mb-4">
        <label class="block text-gray-700 text-sm font-bold mb-2" for="name">
          CheckBox :
        </label>       
        <label class="inline-flex items-center">
          <input type="checkbox" name="check_1" class="rounded-full mx-1 text-cyan-600 focus:outline-none" />
          <span class="ml-2">check_1</span>
        </label> 
        <label class="inline-flex items-center">
          <input type="checkbox" name="check_2" class="rounded-full mx-1 text-cyan-600 focus:outline-none" />
          <span class="ml-2">check_2</span>
        </label> 
        <label class="inline-flex items-center">
          <input type="checkbox" name="check_3" class="rounded-full mx-1 text-cyan-600 focus:outline-none" />
          <span class="ml-2">check_3</span>
        </label> 
      </div>
  • type=date
01_form2.html
      <div class="mb-4">
        <label class="block text-gray-700 text-sm font-bold mb-2" for="Date">
            date :
        </label>
        <input
          class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
          name="date" type="date" value="" required>
      </div>

参考のデモページ

  • text etc

https://kuc-arc-f.github.io/tailwind-sample/src/01_form3.html

  • radio etc

https://kuc-arc-f.github.io/tailwind-sample/src/01_form2.html

....