- Published on
6 Tips To Make A Select add and remove With Tailwind CSS

- What is Tailwind CSS?
- The description of Select add and remove ui component
- Why use Tailwind CSS to create a Select add and remove ui component?
- The preview of Select add and remove ui component
- The source code of Select add and remove ui component
- How to create a Select add and remove with Tailwind CSS?
- Install tailwind css of verion 2.2.19
- All the unility class needed to create a Select add and remove component
- 23 steps to create a Select add and remove component with Tailwind CSS
- Conclusion
What is Tailwind CSS?
Tailwind CSS is a utility-first CSS framework that focuses on creating personalized user interfaces quickly. It can gives you all the building blocks you are able to create personalized designs without having to fight to override irritating opinionated styles. Also, Tailwind CSS is a highly configurable, low-level CSS framework.
The description of Select add and remove ui component
Diseño para añadir y remover permisos de un usuario en laravel
Why use Tailwind CSS to create a Select add and remove ui component?
- It can make the building process of Select add and remove ui component faster and more easily.
- Enables building complex responsive layouts and components freely.
- Minimum lines of CSS code in Select add and remove component file.
The preview of Select add and remove ui component
Free download of the Select add and remove's source code
The source code of Select add and remove ui component
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<div class=" mx-auto h-full flex flex-col max-w-3xl items-center justify-center bg-white rounded-xl p-4">
<h1 class="font-bold uppercase text-xl py-4">Permisos de Juan Cárdenas</h1>
<form action="nombre/ruta" class="flex flex-row justify-between space-x-4 items-center mx-auto" method="post"
id="frmadd">
<!-- Select con los permisos que no tiene el usuario -->
<select name="perm" id="poragregar" class="p-3 h-96 border-2 border-one w-56 capitalize min-w-full min-w-max" multiple>
<option value="1">Uno</option>
<option value="2">Dos</option>
<option value="3">Tres</option>
<option value="4">Cuatro</option>
<option value="5">Cinco</option>
</select>
<div class="flex flex-col">
<!-- Mueve los seleccionados del primer select al segundo -->
<button type="button" class="h-8" id="add">Añadir-></button>
<!-- Mueve los seccionados del segundo select al primero -->
<button type="button" class="h-8" id="remove">
<- Quitar </button>
<!-- Para enviar el formulario -->
<button form="frmadd"
data-label="¿Actualizar permisos de usuario?" class="h-8 confirm mt-4 bg-black text-white px-3 py-1 rounded-lg" id="save">Guardar</button>
</div>
<!-- Select con los permisos que sí tiene el usuario -->
<!-- Este es el que se envía a la ruta post en forma de array -->
<select name="permissions[]" id="agregados" class="p-3 h-96 border-2 border-one w-56 capitalize" multiple>
<option value="6">Seis</option>
<option value="7">Siete</option>
<option value="8">Ocho</option>
<option value="9">Nueve</option>
<option value="10">Diez</option>
</select>
</form>
</div>
<script>
$(document).ready(function() {
$('#add').on('click', function() {
$('#poragregar').find('option:selected').each(function() {
$('#agregados').append($('<option>', {
value: $(this).val(),
text: $(this).text()
}));
$(this).remove();
});
})
$('#remove').on('click', function() {
$('#agregados').find('option:selected').each(function() {
$('#poragregar').append($('<option>', {
value: $(this).val(),
text: $(this).text()
}));
$(this).remove();
});
})
$('#save').on('click', function() {
/* Selecciona todos los permisos del segundo select antes de enviar el formulario */
$('#agregados option').prop('selected', true);
/* En el back, uso $user->synPermissionsTo($request->permissions)
De esa forma borra todos los permisos del usuario y le asigna sólo los que haya enviado
por el form.
*/
})
})
</script>
How to create a Select add and remove with Tailwind CSS?
Install tailwind css of verion 2.2.19
Use the script
html tag to import the script of Tailwind CSS of the version 2.2.19
<script src="https://cdn.tailwindcss.com"></script>
All the unility class needed to create a Select add and remove component
mx-auto
h-full
flex
flex-col
max-w-3xl
bg-white
p-4
text-xl
py-4
flex-row
p-3
h-96
border-2
border-one
w-56
min-w-full
min-w-max
h-8
mt-4
bg-black
text-white
px-3
py-1
23 steps to create a Select add and remove component with Tailwind CSS
Control the horizontal margin of an element to auto using the
mx-auto
utilities.Use
h-full
to set an element’s height to 100% of its parent, as long as the parent has a defined height.Use
flex
to create a block-level flex container.Use
flex
to create a block-level flex container.Set the maximum width/height of an element using the
max-w-3xl
utilities.Control the background color of an element to white using the
bg-white
utilities.Control the padding on all sides of an element to 1rem using the
p-4
utilities.Control the text color of an element to xl using the
text-xl
utilities.Control the vertical padding of an element to 1rem using the
py-4
utilities.Use
flex
to create a block-level flex container.Control the padding on all sides of an element to 0.75rem using the
p-3
utilities.Use
h-96
to set an element to a fixed height(24rem).Control the border color of an element to 0.5rem using the
border-2
utilities.Control the border color of an element to one using the
border-one
utilities.Use
w-56
to set an element to a fixed width(14rem).Set the minimum width/height of an element using the
min-w-full
utilities.Set the minimum width/height of an element using the
min-w-max
utilities.Use
h-8
to set an element to a fixed height(2rem).Control the margin on top side of an element to 1rem using the
mt-4
utilities.Control the background color of an element to black using the
bg-black
utilities.Control the text color of an element to white using the
text-white
utilities.Control the horizontal padding of an element to 0.75rem using the
px-3
utilities.Control the vertical padding of an element to 0.25rem using the
py-1
utilities.
Conclusion
The above is a step-by-step tutorial on how to use Tailwind CSS to create a Select add and remove components, learn and follow along to implement your own components.