How to open specific collapsible panel inside modal by clicking in link - html

How to open specific collapsible panel inside modal by clicking in link I'm trying to make a layered filter modal, but i can not create links to appropriate panels in this modal.
We use alpine.js and magento 2 for this. Here is our code.
It would be great if you could help us
<section x-cloak x-data="{open: false}"
:class="open ? 'overflow-hidden ' : 'overflow-visible '">
<div class="border-b border-container-lighter flex pb-6">
<?php foreach ($block->getFilters() as $filter): ?>
<?php if ($filter->getItemsCount()): ?>
<button
#click="open = true"
class="flex-initial items-center text-sm py-2.5 px-4 rounded-full bg-gray-100 mr-2">
<?= $escaper->escapeHtml(__($filter->getName())) ?>
</button>
<?php endif; ?>
<?php endforeach; ?>
</div>
<?= $block->getChildHtml('state') ?>
<div role="dialog"
aria-labelledby="modal1_label"
aria-modal="true"
tabindex="0"
x-show="open"
#click.away="open = false"
class="fixed inset-x-0 bottom-0 md:inset-x-auto md:inset-y-0 md:right-0 z-30 flex max-w-full">
<div class="backdrop"
x-show="open"
x-transition:enter="ease-in-out duration-500"
x-transition:enter-start="opacity-0"
x-transition:enter-end="opacity-100"
x-transition:leave="ease-in-out duration-500"
x-transition:leave-start="opacity-100"
x-transition:leave-end="opacity-0"
#click="open = false"
aria-label="Close panel"></div>
<div data-modal-document
#click.stop=""
x-show="open"
x-transition:enter="transform transition ease-in-out duration-500 sm:duration-700"
x-transition:enter-start="translate-y-full sm:-translate-y-0 sm:translate-x-full"
x-transition:enter-end=" sm:translate-x-0"
x-transition:leave="transform transition ease-in-out duration-500 sm:duration-700"
x-transition:leave-start="sm:translate-x-0"
x-transition:leave-end="translate-y-full sm:-translate-y-0 sm:translate-x-full"
class="bg-white relative w-screen max-w-md shadow-2xl">
<div
x-show="open"
x-transition:enter="ease-in-out duration-500"
x-transition:enter-start="opacity-0"
x-transition:enter-end="opacity-100"
x-transition:leave="ease-in-out duration-500"
x-transition:leave-start="opacity-100"
x-transition:leave-end="opacity-0" class="absolute top-0 right-0 flex p-2 mt-2">
<button #click="open = false;" aria-label="Close panel"
class="p-2 text-gray-300 transition duration-150 ease-in-out hover:text-black">
<svg class="w-6 h-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round"
stroke-width="2" d="M6 18L18 6M6 6l12 12">
</path>
</svg>
</button>
</div>
<div class="flex flex-col h-full py-6 space-y-6 bg-white shadow-xl">
<header class="px-4 sm:px-6">
<h2 id="cart-drawer-title" class="text-lg font-medium leading-7 text-gray-900">
<?= $escaper->escapeHtml(__('Filtern und sortieren')) ?>
</h2>
</header>
<div class="relative grid gap-6 px-6 py-6 overflow-y-auto bg-white
sm:gap-8 sm:px-6 border-container">
<div class="w-full">
<div class="container block p-4 md:border-0 md:bg-transparent md:py-0 md:px-0 my-6"
x-data="initLayeredNavigation()"
x-init="checkIsMobileResolution()"
#resize.window.debounce="checkIsMobileResolution()"
#visibilitychange.window.debounce="checkIsMobileResolution()"
>
<div class="block-content filter-content pt-3" >
<?= $block->getChildHtml('state') ?>
<?php foreach ($block->getFilters() as $filter): ?>
<?php if ($filter->getItemsCount()): ?>
<div class="filter-option my-6" id="filter-<?= $escaper->escapeHtml(__($filter->getName())) ?>" x-data="{ open: false }">
<div
class="filter-options-title flex justify-between items-center cursor-pointer hover:text-secondary-darker border-container"
:class="{ 'border-b pb-4': open }"
#click="open = !open"
#open-dropdown.window=" open = true"
#click.away="open = false">
<span class="title text-md md:text-base font-light">
<?= $escaper->escapeHtml(__($filter->getName())) ?>
</span>
<span class="">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none"
xmlns="http://www.w3.org/2000/svg"
class="transition-transform transform duration-300 ease-in-out"
:class="open ? 'rotate-180' : ''">
<path d="M19 9L12 16L5 9" stroke="#4A5568" stroke-width="2" stroke-linecap="round"
stroke-linejoin="round"/>
</svg>
</span>
</div>
<div class="filter-options-content pt-3 hidden"
:class="{ 'hidden': !open , 'block': 'open' }"
>
<?= /* #noEscape */
$block->getChildBlock('renderer')->render($filter) ?>
</div>
</div>
<?php endif; ?>
<?php endforeach; ?>
</div>
How to open specific collapsible panel inside modal by clicking in link I'm trying to make a layered filter modal, but i can not create links to appropriate panels in this modal.

Related

Dropdown list not working as expected Tailwind css

I'm using tailwind with cdn, and just copy pasting one of the dropdown lists on flowbite:
<button id="dropdownDefault" data-dropdown-toggle="dropdown" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-4 py-2.5 text-center inline-flex items-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800" type="button">Dropdown button <svg class="ml-2 w-4 h-4" aria-hidden="true" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path></svg></button>
<!-- Dropdown menu -->
<div id="dropdown" class="z-10 w-44 bg-white rounded divide-y divide-gray-100 shadow dark:bg-gray-700 block" data-popper-reference-hidden="" data-popper-escaped="" data-popper-placement="bottom" style="position: absolute; inset: 0px auto auto 0px; margin: 0px; transform: translate3d(327px, 70px, 0px);">
<ul class="py-1 text-sm text-gray-700 dark:text-gray-200" aria-labelledby="dropdownDefault">
<li>
Dashboard
</li>
<li>
Settings
</li>
<li>
Earnings
</li>
<li>
Sign out
</li>
</ul>
</div>
But this is what I'm getting:
Any idea what could be causing this?
you need to include the FlowBite <script> before the end of the body element
also, require the minified stylesheet inside the <head> tag like this :
<head>
<link rel="stylesheet" href="https://unpkg.com/flowbite#1.5.1/dist/flowbite.min.css" />
</head>
<body>
<button id="dropdownDefault" data-dropdown-toggle="dropdown" class="inline-flex items-center rounded-lg bg-blue-700 px-4 py-2.5 text-center text-sm font-medium text-white hover:bg-blue-800 focus:outline-none focus:ring-4 focus:ring-blue-300 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800" type="button">
Dropdown busdatton <svg class="ml-2 h-4 w-4" aria-hidden="true" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path></svg>
</button>
<!-- Dropdown menu -->
<div id="dropdown" class="z-10 block w-44 divide-y divide-gray-100 rounded bg-white shadow dark:bg-gray-700" data-popper-reference-hidden="" data-popper-escaped="" data-popper-placement="bottom" style="position: absolute; inset: 0px auto auto 0px; margin: 0px; transform: translate3d(327px, 70px, 0px);">
<ul class="py-1 text-sm text-gray-700 dark:text-gray-200" aria-labelledby="dropdownDefault">
<li>
Dashboard
</li>
<li>
Settings
</li>
<li>
Earnings
</li>
<li>
Sign out
</li>
</ul>
</div>
<script src="https://unpkg.com/flowbite#1.5.1/dist/flowbite.js"></script>
</body>
Here an example without library, only react and tailwind.
const Sidebar = () => {
const [isOpen, setOpen] = useState(false);
const handleDropDown = () => {
setOpen(!isOpen);
};
return (
<div className="dropdown">
<button
className="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-4 py-2.5 text-center inline-flex items-center"
onClick={handleDropDown}
>
Steps
<svg
className="ml-2 w-4 h-4"
aria-hidden="true"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="M19 9l-7 7-7-7"
></path>
</svg>
</button>
<div
id="dropdown"
className={`z-10 w-44 bg-white rounded divide-y divide-gray-100 shadow ${
isOpen ? "block" : "hidden"
}`}
>
<ul className=" z-10 w-44 bg-white rounded divide-y divide-gray-100 shadow ">
<li
>
<a href="#" className="block py-2 px-4 hover:bg-gray-100">
blablabla
</a>
</li>
</ul>
</div>
</div>
);
};

How to add text right in the center of a flowbite carousel?

I am trying to add 2 h2 tags with text right in the vertical and horizontal center of a flowbite carousel, I cannot manage to get a good result.
My classes (for tesint):
"absolute top-500 left-500" do not even make a difference to the way the text shows over the image. It is strange.
Here is the carousel:
https://flowbite.com/docs/components/carousel/
This is the entire html:
<div id="default-carousel" class="relative" data-carousel="static">
<!-- Carousel wrapper -->
<div class="overflow-hidden relative h-56 rounded-lg md:h-96">
<!-- Item 1 -->
<div class="duration-700 ease-in-out absolute inset-0 transition-all transform translate-x-0 z-20" data-carousel-item="">
<span class="absolute top-1/2 left-1/2 text-2xl font-semibold text-white -translate-x-1/2 -translate-y-1/2 sm:text-3xl dark:text-gray-800">First Slide</span>
<img src="/docs/images/carousel/carousel-1.svg" class="block absolute top-1/2 left-1/2 w-full -translate-x-1/2 -translate-y-1/2" alt="...">
</div>
<!-- Item 2 -->
<div class="duration-700 ease-in-out absolute inset-0 transition-all transform translate-x-full z-10" data-carousel-item="">
<img src="/docs/images/carousel/carousel-2.svg" class="block absolute top-1/2 left-1/2 w-full -translate-x-1/2 -translate-y-1/2" alt="...">
</div>
<!-- Item 3 -->
<div class="duration-700 ease-in-out absolute inset-0 transition-all transform -translate-x-full z-10" data-carousel-item="">
<img src="/docs/images/carousel/carousel-3.svg" class="block absolute top-1/2 left-1/2 w-full -translate-x-1/2 -translate-y-1/2" alt="...">
</div>
</div>
<!-- Slider indicators -->
<div class="flex absolute bottom-5 left-1/2 z-30 space-x-3 -translate-x-1/2">
<button type="button" class="w-3 h-3 rounded-full bg-white dark:bg-gray-800" aria-current="true" aria-label="Slide 1" data-carousel-slide-to="0"></button>
<button type="button" class="w-3 h-3 rounded-full bg-white/50 dark:bg-gray-800/50 hover:bg-white dark:hover:bg-gray-800" aria-current="false" aria-label="Slide 2" data-carousel-slide-to="1"></button>
<button type="button" class="w-3 h-3 rounded-full bg-white/50 dark:bg-gray-800/50 hover:bg-white dark:hover:bg-gray-800" aria-current="false" aria-label="Slide 3" data-carousel-slide-to="2"></button>
</div>
<!-- Slider controls -->
<button type="button" class="flex absolute top-0 left-0 z-30 justify-center items-center px-4 h-full cursor-pointer group focus:outline-none" data-carousel-prev="">
<span class="inline-flex justify-center items-center w-8 h-8 rounded-full sm:w-10 sm:h-10 bg-white/30 dark:bg-gray-800/30 group-hover:bg-white/50 dark:group-hover:bg-gray-800/60 group-focus:ring-4 group-focus:ring-white dark:group-focus:ring-gray-800/70 group-focus:outline-none">
<svg aria-hidden="true" class="w-5 h-5 text-white sm:w-6 sm:h-6 dark:text-gray-800" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"></path></svg>
<span class="sr-only">Previous</span>
</span>
</button>
<button type="button" class="flex absolute top-0 right-0 z-30 justify-center items-center px-4 h-full cursor-pointer group focus:outline-none" data-carousel-next="">
<span class="inline-flex justify-center items-center w-8 h-8 rounded-full sm:w-10 sm:h-10 bg-white/30 dark:bg-gray-800/30 group-hover:bg-white/50 dark:group-hover:bg-gray-800/60 group-focus:ring-4 group-focus:ring-white dark:group-focus:ring-gray-800/70 group-focus:outline-none">
<svg aria-hidden="true" class="w-5 h-5 text-white sm:w-6 sm:h-6 dark:text-gray-800" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"></path></svg>
<span class="sr-only">Next</span>
</span>
</button>
</div>
I tried this in the first slide vua the text get stuck to the top of the slide:
<div class="duration-700 ease-in-out absolute inset-0 transition-all transform translate-x-0 z-20" data-carousel-item="">
<img src="https://placeimg.com/800/300/rabbit" class="block absolute top-1/2 left-1/2 w-full -translate-x-1/2 -translate-y-1/2" alt="">
<div class="absolute top-500 left-500 px-4 py-2 opacity-100">
<h2 class="text-xl text-white font-bold text-center">Text 1 here</h3>
<h2 class="text-xl text-white font-bold text-center">Text 2 here</h3>
</div>
</div>
Any help would be appreciated please.
Thanks!
You can add the two h2 tags by replacing the absolute with relative for the div containing heading and adding top-1/2 to same div.
This is the code
<script src="https://cdn.tailwindcss.com"></script>
<div class="duration-700 ease-in-out absolute inset-0 transition-all transform translate-x-0 z-20" data-carousel-item="">
<img src="https://placeimg.com/800/300/rabbit" class="block absolute top-1/2 left-1/2 w-full -translate-x-1/2 -translate-y-1/2" alt="">
<div class="relative top-500 top-1/2 px-4 py-2 opacity-100 ">
<h2 class="text-xl text-white font-bold text-center ">Text 1 here</h3>
<h2 class="text-xl text-white font-bold text-center ">Text 2 here</h3>
</div>
</div>
Please see the full page view.
Ok got it, this seems to work perfectly, (it can be left as absolute):
<div class="duration-700 ease-in-out absolute inset-0 transition-all transform translate-x-0 z-20" data-carousel-item="">
<img src="https://placeimg.com/800/300/rabbit" class="block absolute top-1/2 left-1/2 w-full -translate-x-1/2 -translate-y-1/2" alt="...">
<span class="absolute top-1/2 left-1/2 text-2xl font-semibold text-white -translate-x-1/2 -translate-y-1/2 sm:text-3xl dark:text-gray-800">First Slide</span>
</div>

Tailwind CSS center horizontally in navbar

Using the default tailwindcss navbar in Laravel Breeze, I want to center the application logo, whilst having navigation links on the far left and right of it. There will be three navigation links on one side, and just two on the other, so flex-between won't work properly. Any ideas how to do it? Here is the entire default navbar, and how it currently looks.
<nav x-data="{ open: false }" class="bg-white border-b border-gray-100 py-6">
<!-- Primary Navigation Menu -->
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex justify-between h-16">
<div class="flex">
<!-- Logo -->
<div class="flex-shrink-0 flex items-center">
<a href="{{ route('index') }}">
<x-application-logo class="block h-10 w-auto fill-current text-gray-600" />
</a>
</div>
<!-- Navigation Links -->
<div class="hidden space-x-8 sm:-my-px sm:ml-10 sm:flex">
<x-nav-link :href="route('index')" :active="request()->routeIs('index')">
{{ __('Home') }}
</x-nav-link>
<x-nav-link :href="route('dashboard')" :active="request()->routeIs('dashboard')">
{{ __('Occupational Health') }}
</x-nav-link>
<x-nav-link :href="route('bookings')" :active="request()->routeIs('bookings')">
{{ __('Inquiry') }}
</x-nav-link>
</div>
</div>
<!-- Settings Dropdown -->
<div class="hidden sm:flex sm:items-center sm:ml-6">
#guest
#if (Route::has('login'))
#endif
#else
<x-dropdown align="right" width="48">
<x-slot name="trigger">
<button class="flex items-center text-sm font-medium text-gray-500 hover:text-gray-700 hover:border-gray-300 focus:outline-none focus:text-gray-700 focus:border-gray-300 transition duration-150 ease-in-out">
<div>{{ Auth::user()->name }}</div>
<div class="ml-1">
<svg class="fill-current h-4 w-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20">
<path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd" />
</svg>
</div>
</button>
</x-slot>
<x-slot name="content">
<!-- Authentication -->
<form method="POST" action="{{ route('logout') }}">
#csrf
<x-dropdown-link :href="route('logout')"
onclick="event.preventDefault();
this.closest('form').submit();">
{{ __('Log Out') }}
</x-dropdown-link>
</form>
</x-slot>
</x-dropdown>
#endguest
</div>
<!-- Hamburger -->
<div class="-mr-2 flex items-center sm:hidden">
<button #click="open = ! open" class="inline-flex items-center justify-center p-2 rounded-md text-gray-400 hover:text-gray-500 hover:bg-gray-100 focus:outline-none focus:bg-gray-100 focus:text-gray-500 transition duration-150 ease-in-out">
<svg class="h-6 w-6" stroke="currentColor" fill="none" viewBox="0 0 24 24">
<path :class="{'hidden': open, 'inline-flex': ! open }" class="inline-flex" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16" />
<path :class="{'hidden': ! open, 'inline-flex': open }" class="hidden" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>
</div>
</div>
#guest
#if (Route::has('login'))
#endif
#else
<!-- Responsive Navigation Menu -->
<div :class="{'block': open, 'hidden': ! open}" class="hidden sm:hidden">
<div class="pt-2 pb-3 space-y-1">
<x-responsive-nav-link :href="route('index')" :active="request()->routeIs('index')">
{{ __('Home') }}
</x-responsive-nav-link>
<x-responsive-nav-link :href="route('bookings')" :active="request()->routeIs('bookings')">
{{ __('Bookings') }}
</x-responsive-nav-link>
<x-responsive-nav-link :href="route('dashboard')" :active="request()->routeIs('dashboard')">
{{ __('Dashboard') }}
</x-responsive-nav-link>
</div>
<!-- Responsive Settings Options -->
<div class="pt-4 pb-1 border-t border-gray-200">
<div class="px-4">
<div class="font-medium text-base text-gray-800">{{ Auth::user()->name }}</div>
<div class="font-medium text-sm text-gray-500">{{ Auth::user()->email }}</div>
</div>
<div class="mt-3 space-y-1">
<!-- Authentication -->
<form method="POST" action="{{ route('logout') }}">
#csrf
<x-responsive-nav-link :href="route('logout')"
onclick="event.preventDefault();
this.closest('form').submit();">
{{ __('Log Out') }}
</x-responsive-nav-link>
</form>
</div>
</div>
#endguest
</div>
</nav>
Thank you to Martin for helping me solve this!
Each section of the navbar was split into containers of width 1/3, and the logo centered in its container, similar to this:
<div class="flex">
<!-- Navigation Links -->
<div class="hidden space-x-8 sm:-my-px sm:ml-10 sm:flex sm:w-1/3">
<x-nav-link :href="route('index')" active="request()->routeIs('index')">
{{ __('Home') }}
</x-nav-link>
<x-nav-link class="text-center" :href="route('dashboard')" :active="request()->routeIs('dashboard')">
{{ __('Occupational Health') }}
</x-nav-link>
<x-nav-link :href="route('bookings')" :active="request()->routeIs('bookings')">
{{ __('Inquiry') }}
</x-nav-link>
</div>
</div>
<div class="flex w-1/3 justify-center">
<!-- Logo -->
<div class="flex-shrink-0 flex items-center">
<a href="{{ route('index') }}">
<x-application-logo class="block h-10 w-auto fill-current text-gray-600" />
</a>
</div>
</div>
<div class="hidden sm:flex w-1/3 justify-end">
<x-nav-link :href="route('bookings')" :active="request()->routeIs('bookings')">
{{ __('Inquiry') }}
</x-nav-link>
</div>

Always show dropdown directly below button with flexbox

I have created the following responsive navigation bar with Tailwind and have a problem with the dropdown button ("Folgen") which shows the content always somewhere else on the x-axis than the button (depending on the window width).
How could I make sure that the dropdown always stays within the browser window (no overflow outside of the window) and stay close to the button depending on the browser width?
<nav class="bg-blue-800 shadow-lg sticky top-0 z-50 h-[3.75rem]">
<div class="max-w-6xl mx-auto px-4 h-[3.75rem]">
<div class="flex justify-between h-[3.75rem]">
<div class="flex space-x-7">
<div>
<!-- Website Logo -->
<a class="flex items-center py-4 px-2 text-white font-bold text-lg" href="<?= $site->url() ?>"><?= $site->title()->html() ?></a>
</a>
</div>
<!-- Primary Navbar items -->
<div class="hidden md:flex items-center space-x-1">
<?php foreach ($site->children()->listed() as $item): ?>
<a class="py-4 px-2 text-white font-semibold hover:text-white-500 hover:bg-blue-500 transition duration-300" <?php e($item->isOpen(), 'aria-current ') ?> href="<?= $item->url() ?>"><?= $item->title()->html() ?></a>
<?php endforeach ?>
</div>
</div>
<!-- This is a search component -->
<ul class="flex items-center ml-auto space-x-1">
<div class="md:flex hidden items-center ml-auto bg-blue-800 space-x-1 pr-4">
<form method="post" action="<?= page('search')->url() ?>">
<div class="relative text-gray-600 focus-within:text-gray-800">
<span class="absolute inset-y-0 left-0 flex items-center pl-2">
<button type="submit" class="p-1 focus:outline-none focus:shadow-outline">
<svg fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24" class="w-6 h-6"><path d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path></svg>
</button>
</span>
<input type="search" name="q" class="py-2 text-sm text-gray-900 bg-white rounded-md pl-10 focus:outline-none focus:bg-white focus:text-gray-900" placeholder="Suche..." value="<?php echo (!empty($query)) ? esc($query) : '' ?>" autocomplete="off">
</div>
</form>
</div>
<!-- Language selector -->
<?php foreach($kirby->languages()->not($kirby->language()) as $language): ?>
<?php if ($page->translation($language->code())->exists()): ?>
<?= svg('assets/icons/OOjs_UI_icon_language-ltr-invert.svg') ?>
<li <?php e($kirby->language() == $language, ' class="active text-white"') ?>>
<a href="<?= $page->url($language->code()) ?>" hreflang="<?php echo $language->code() ?>" class="text-white">
<?= html($language->name()) ?>
</a>
</li>
<?php endif ?>
<?php endforeach ?>
</ul>
<!-- Social Navbar items -->
<div class="group hidden md:flex">
<button
class="outline-none focus:outline-none px-3 py-1 bg-blue-800 text-white rounded-sm flex items-center min-w-32"
>
<span class="pr-1 font-semibold flex-1">Folgen</span>
<span>
<svg
class="fill-current h-4 w-4 transform group-hover:-rotate-180
transition duration-150 ease-in-out"
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>
</span>
</button>
<ul
class="bg-gray-200 inline-flex transform scale-0 group-hover:scale-100 absolute transition duration-150 ease-in-out origin-top top-full right-0 left-auto"
>
<li class="items-center inline-flex py-2"><?php snippet('social') ?></li>
</ul>
</div>
<!-- Mobile menu button -->
<div class="md:hidden flex ml-4 items-center">
<button class="outline-none mobile-menu-button" aria-label="Navigation icon">
<svg class=" w-7 h-7 text-white hover:text-blue-500 "
x-show="!showMenu"
fill="none"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path d="M4 6h16M4 12h16M4 18h16"></path>
</svg>
</button>
</div>
</div>
</div>
<!-- mobile menu -->
<div class="hidden mobile-menu text-center bg-blue-600">
<ul class="inline-block">
<?php foreach ($site->children()->listed() as $item): ?>
<li><a class="block px-2 py-4 text-white hover:bg-blue-500 transition duration-300" <?php e($item->isOpen(), 'aria-current ') ?> href="<?= $item->url() ?>"><?= $item->title()->html() ?></a></li>
<?php endforeach ?>
<div class="inline-flex px-2 py-4">
<form method="post" action="<?= page('search')->url() ?>">
<div class="relative text-gray-600 focus-within:text-gray-800">
<span class="absolute inset-y-0 left-0 flex items-center pl-2">
<button type="submit" class="p-1 focus:outline-none focus:shadow-outline">
<svg fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24" class="w-6 h-6"><path d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path></svg>
</button>
</span>
<input type="search" name="q" class="py-2 text-sm text-gray-900 bg-white rounded-md pl-10 focus:outline-none focus:bg-white focus:text-gray-900" placeholder="Suche..." value="<?php echo (!empty($query)) ? esc($query) : '' ?>">
</div>
</form>
</div>
<div class="inline-flex px-2 py-4 text-white filter invert"><?php snippet('social') ?></div>
</ul>
</div>
<script>
const btn = document.querySelector("button.mobile-menu-button");
const menu = document.querySelector(".mobile-menu");
btn.addEventListener("click", () => {
menu.classList.toggle("hidden");
});
</script>
</nav>
You can find a working example over here.
You can add relative class on the container which contains the button and the dropdown. Your dropdown, which has the right-0 class, will then be positioned on the right edge of the container instead of the browser window like it is now. Working example here.

Tailwindcss Dropdown item flying off to edge of the screen instead of under the dropdown button

So Im making an app with Rails, Vue and TailwindCss 1.0+
At present I'm attempting to make a dropdown menu for my products, but when I click on the dropdown button my dropdown that contains my items flys off to the edge of the screen, when it should be under my button..
Im not too sure where I'm going wrong.
Pic of the problem:
Here is how the dropdown menu looks:
<!-- Start LG Products Dropdown -->
<div class="hidden lg:inline-block">
<button #click="prodOpen = !prodOpen" role="button" class="relative z-10 inline-block select-none focus:outline-none text-base font-normal text-blue-600 hover:text-green-600 header-font focus:text-green-600">
<i class="fal fa-sitemap"></i><span class="ml-1">Products</span>
</button>
<button v-if="prodOpen" #click="prodOpen = false" class="fixed inset-0 bg-black opacity-25 h-full w-full cursor-default"></button>
</div>
<div v-if="prodOpen" class="absolute left-0 mt-5 bg-white rounded-lg shadow-xl w-40 headerFont text-base font-normal">
<slot name="dropdown-items"></slot>
</div>
<!-- End LG Products Dropdown -->
This is the code of the entire nav component:
<template>
<nav class="flex items-center justify-between flex-wrap bg-white p-6 w-full fixed">
<a href="https://loadze.com">
<h1>
<div class="flex items-center flex-shrink-0 text-blue-600 mr-6 logoFont">
<span class="font-bold text-3xl tracking-tight"><i class="far fa-truck-loading text-2xl"></i>LOADZE</span>
</div>
</h1>
</a>
<div class="block lg:hidden">
<button #click="navOpen = !navOpen" class="flex items-center px-3 py-2 border rounded text-blue-600 border-blue-600 hover:text-green-600 hover:border-green-600 focus:outline-none">
<svg v-if="!navOpen" aria-hidden="true" focusable="false" data-prefix="far" data-icon="bars" class="svg-inline--fa fa-bars fa-w-14" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg>
<svg v-if="navOpen" aria-hidden="true" focusable="false" data-prefix="far" data-icon="times" class="svg-inline--fa fa-times fa-w-10" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><path fill="currentColor" d="M207.6 256l107.72-107.72c6.23-6.23 6.23-16.34 0-22.58l-25.03-25.03c-6.23-6.23-16.34-6.23-22.58 0L160 208.4 52.28 100.68c-6.23-6.23-16.34-6.23-22.58 0L4.68 125.7c-6.23 6.23-6.23 16.34 0 22.58L112.4 256 4.68 363.72c-6.23 6.23-6.23 16.34 0 22.58l25.03 25.03c6.23 6.23 16.34 6.23 22.58 0L160 303.6l107.72 107.72c6.23 6.23 16.34 6.23 22.58 0l25.03-25.03c6.23-6.23 6.23-16.34 0-22.58L207.6 256z"></path></svg>
</button>
</div>
<div :class="navOpen ? 'block' : 'hidden'" class="w-full block flex-grow lg:flex lg:items-center lg:w-auto">
<div class="text-sm lg:flex-grow">
<slot name="nav-left"></slot>
<!-- Start LG Products Dropdown -->
<div class="hidden lg:inline-block">
<button #click="prodOpen = !prodOpen" role="button" class="relative z-10 inline-block select-none focus:outline-none text-base font-normal text-blue-600 hover:text-green-600 header-font focus:text-green-600">
<i class="fal fa-sitemap"></i><span class="ml-1">Products</span>
</button>
<button v-if="prodOpen" #click="prodOpen = false" class="fixed inset-0 bg-black opacity-25 h-full w-full cursor-default"></button>
</div>
<div v-if="prodOpen" class="absolute left-0 mt-5 bg-white rounded-lg shadow-xl w-40 headerFont text-base font-normal">
<slot name="dropdown-items"></slot>
</div>
<!-- End LG Products Dropdown -->
</div>
<div>
<slot name="nav-right"></slot>
</div>
</div>
</nav>
</template>
<script>
export default {
data () {
return {
navOpen: false,
prodOpen: false
}
}
}
</script>
I'm not fully understanding your issue. But if I see the screenshot I guess it's the alignment you are talking about. Based on this conclusion.
If this is the case you have to change the following: left-0 to right-0.
<div v-if="prodOpen" class="absolute left-0 mt-5 bg-white rounded-lg shadow-xl w-40 headerFont text-base font-normal">
<slot name="dropdown-items"></slot>
</div>
To:
<div v-if="prodOpen" class="absolute right-0 mt-5 bg-white rounded-lg shadow-xl w-40 headerFont text-base font-normal">
<slot name="dropdown-items"></slot>
</div>
This will let the div align from right to left, if it's extends/needs more room, it will expand to the middle of the screen.