VueJS, Display form fields in separate rows - css

In my vue component I have a form, there I'm trying to add two fields with labels
<div class="bg-certstyle-background-light " slot="modal_content">
<div class="flex justify-between">
<div class="container mx-auto flex bg-white px-6 py-4 border-b space-x-2">
<!-- Team member -->
<dashboard-input-label class="col-sm-2 mb-2 w-full" identifier="first_name">
{{ 'Team member' }}
</dashboard-input-label>
<div class="col-sm-10 mb-6 w-full">
<input
name="first_name"
type="text"
class="form-input w-full relative z-10"
placeholder="Search user"
>
</div>
<!-- Team member -->
</div>
<div class="container mx-auto flex bg-white px-6 py-4 border-b space-x-2">
<!-- Schedule name -->
<dashboard-input-label class="col-sm-2 mb-2 w-full" identifier="schedule_name">
{{ 'Schedule name' }}
</dashboard-input-label>
<div class="col-sm-10 mb-6 w-full">
<input
name="schedule_name"
type="text"
class="form-input w-full relative z-10"
placeholder="Schedule name"
>
</div>
<!-- Schedule namer -->
</div>
</div>
</div>
This is what I've tried so far, But the problem is, this gives me following output,
Instead of this way, I want to add the second label and field in a new row...
How can I do it?

You could have a outer div-container with a flex-direction: row with two div-container with flex-direction: column inside, which represent your label and field.
Or this bootstrap example could fit: "Two Columns With Two Nested Columns"
Example:
<div class="col">
<div class="row">
<div class="col-sm-6" style="background-color:green;">One</div>
<div class="col-sm-6" style="background-color:red;">Two</div>
</div>
<div class="row">
<div class="col-sm-6" style="background-color:yellow;">Three</div>
<div class="col-sm-6" style="background-color:blue;">Four</div>
</div>
<div class="col">
Another alternativ could be a css-grid.
Some nice tips for flex and grid

Related

Vue 3 Carousel unexpected behavior

I have a Vue3 carousel inside a Single file component
package.json
"vue3-carousel": "^0.1.40"
SFC
import { Carousel, Slide, Navigation } from 'vue3-carousel';
import 'vue3-carousel/dist/carousel.css';
import '#/assets/scss/Carousel.scss';
<Carousel :wrap-around="true" class="box-carousel" :autoplay="2000" :transition="500">
<Slide v-for="slide in slides" :key="slide.id">
<div class="mx-auto w-[85%] md:w-[90%] rounded-lg p-5 bg-blue-secondary-5 h-full dark:bg-blue-secondary-5 dark:text-black-dark-100">
<!-- Box Description -->
<div class="grid grid-cols-5 gap-5 mb-5">
<div class="col-span-1">
<div class="rounded-full h-11 w-11 bg-black-20 flex items-center justify-center">
<p class="uppercase font-bold text-sm">{{slide.title}}</p>
</div>
</div>
<div class="col-span-4 text-left">
<div class="ml-3 md:ml-0">
<p class="font-bold">{{slide.name}}</p>
<p class="text-black-40 text-xs">{{slide.date}}</p>
</div>
</div>
</div>
<!-- End Box Description -->
<!-- Box Comment -->
<div class="text-left mb-8">
<p class="text-sm ">
{{slide.comment.substring(0,130)}}
</p>
</div>
<!-- End Box Comment -->
<!-- Box Actions -->
<div class="grid grid-cols-6 gap-5 absolute bottom-5">
<div class="col-span-2">
<a href="javascript:void(0)" class="flex items-center text-xs md:text-sm relative top-1 text-blue-secondary-100">
<UndoIcon width="10" class="fill-blue-secondary-100 mr-2 hidden md:block" />
Responder
</a>
</div>
<div class="col-span-2">
<a href="javascript:void(0)" class="flex items-center text-xs md:text-sm relative top-1 text-black-40 underline">
Ver contexto
</a>
</div>
<div class="col-span-2">
<p class="text-xs md:text-sm flex items-center justify-end md:justify-start relative top-1">
<span class="h-2 w-2 rounded-full bg-green-primary-100 inline-block mr-5 md:mr-1 relative top-[-1px]"></span>
<span class="hidden md:block">aprovado</span>
</p>
</div>
</div>
<!-- End Box Actions -->
</div>
</Slide>
<template #addons>
<Navigation />
</template>
</Carousel>
But the transition behavior of the slides is not as expected. It is just changing withouth the transition/translate position effect
This is how it is:
Expected effect: (by the way, the carousel sometimes spontaneously display the expected behavior like when after some hot module replacement refresh happens after saving some edit in VSCode and there is a refresh in the vue app like this):
Thanks in advance for any advice!! Happy new year !! 🙂

How to place c2 children to the top and to the bottom of the parent in css?

I need to add 2 children of a parent element one on the top and another on the bottom. something like this.
and this is the code I have.
<div class=" w-full flex justify-betwen bg-white items-center">
<div class="ml-auto">
<img class="object-cover mr-2 md:mr-4 ml-2 md:ml-4 float-left h-40 lg:w-32 w-14 xs:w-16"
src="../img/Bless.png" alt="" />
</div>
<div class="w-full mx-8">
<div class="text-redfull text-ms xs:text-lg md:text-xl lg:text-2xl xl:text-3xl">
Some text here to top as a title.
</div>
<div
class=" text-gray70 flex justify-between items-center text-xs xs:text-base md:text-base lg:text-lg mb-0">
and this is the date to the bottom Uploaded Auguts 4, 2020
</div>
</div>
</div>
Title should stay at the top.
Date to the bottom.
If anyone knows:)
You can add two divs for Title and Date and add vertical margin to them.
I am not sure whether you want with the text or not so I had implemented for both the cases.
Case 1: With text
<script src="https://cdn.tailwindcss.com"></script>
<div class="justify-betwen flex w-full items-center bg-white">
<div class="ml-auto">
<img class="xs:w-16 float-left mr-2 ml-2 h-40 w-14 object-cover md:mr-4 md:ml-4 lg:w-32" src="http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/nebula_blue.s2014.png" alt="" />
</div>
<div class="mx-8 w-full">
<div class="text-3xl font-semibold text-red-900">Your Title here</div>
<div class="my-3">
<div class="text-ms xs:text-lg text-red-500 md:text-xl lg:text-2xl xl:text-3xl">Some text here to top as a title.</div>
<div class="xs:text-base mb-0 flex items-center justify-between text-xs text-gray-500 md:text-base lg:text-lg">and this is the date to the bottom Uploaded Auguts 4, 2020</div>
</div>
<div class="text-base font-extralight">25 June 2022</div>
</div>
</div>
Case 2: Without Text
<script src="https://cdn.tailwindcss.com"></script>
<div class="justify-betwen flex w-full items-center bg-white">
<div class="ml-auto">
<img class="xs:w-16 float-left mr-2 ml-2 h-40 w-14 object-cover md:mr-4 md:ml-4 lg:w-32" src="http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/nebula_blue.s2014.png" alt="" />
</div>
<div class="mx-8 w-full">
<div class="text-3xl font-semibold text-red-900">Your Title here</div>
<div class="my-12">
</div>
<div class="text-lg font-extralight">25 June 2022</div>
</div>
</div>
I had use an online image, so you can replace it with your image.
If You want more gap, then simply increase the my-12 to more.

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 show items till 3 elements in 1 rows and next 4th element must be on next line with tailwindcss?

With tailwindcss 2 / Alpinejs 2.8 I try to show items till 3 elements in 1 rows and
next 4th element must be on next line, something like I did wuth php/bootstrap :
<div class="row m-2">
#foreach($hostelFacilities as $nextFacility)
<div class="facility_item col-12 col-sm-4">
{!! $viewFuncs->showAppIcon('check') !!} {{ $nextFacility->name }}
</div>
#endforeach
</div>
I tried to make like :
<div class="flex w-full" >
<template x-for="nextCategory in categories" :key="nextCategory.id">
<div class="border px-2 cursor-pointer w-4/12 flex flex-nowrap" >
<input type="checkbox"
x-model="searchSelectedCategoryIds"
:value="nextCategory.id"
class="editor_checkbox_field"
>
<label :for="'cbx_' + nextCategory.id"
class="whitespace-nowrap md:flex-shrink-0"
x-text="nextCategory.name">
</label>
</div>
</template>
But failed, as all items are in 1 row...
How correct?
Thanks!
In such case, I highly recommend to use grid system.
Here's an exmaple of 3 in one row.
<div class="grid grid-cols-3 gap-1">
<div class="col-span-1 h-20 bg-gray-100">1</div>
<div class="col-span-1 h-20 bg-gray-100">2</div>
<div class="col-span-1 h-20 bg-gray-100">3</div>
<div class="col-span-1 h-20 bg-gray-100">4</div>
<div class="col-span-1 h-20 bg-gray-100">5</div>
<div class="col-span-1 h-20 bg-gray-100">6</div>
<div class="col-span-1 h-20 bg-gray-100">7</div>
<div class="col-span-1 h-20 bg-gray-100">8</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