简体   繁体   English

使用 Tailwind CSS 的侧边栏中的下拉菜单

[英]Dropdown menu inside sidebar using Tailwind CSS

I'm learning TailwindCSS, as it seems to be more advance than Bootstrap.我正在学习 TailwindCSS,因为它似乎比 Bootstrap 更先进。

I've this html template, that has a Sidebar.我有这个 html 模板,它有一个侧边栏。 I'd like that when users click each Part-{n}, it shows the inner parts of the content.我希望当用户单击每个 Part-{n} 时,它会显示内容的内部部分。

Note: In my html Parts are called Capítulos (Chapters in spanish).注意:在我的 html 中,零件被称为 Capítulos(西班牙语章节)。

In other words, I'd like to replicate this:换句话说,我想复制这个:

在此处输入图像描述

Codepen:代码笔:

https://codepen.io/ogonzales/pen/WNQMyXJ https://codepen.io/ogonzales/pen/WNQMyXJ

<div class="w-full md:w-1/5 bg-gray-900 md:bg-gray-900 px-2 text-center fixed bottom-0 md:pt-8 md:top-0 md:left-0 h-16 md:h-screen md:border-r-4 md:border-gray-600">
    <div class="md:relative mx-auto lg:float-right lg:px-6">
     <ul class="list-reset flex flex-row md:flex-col text-center md:text-left">
        <li class="mr-3 flex-1">
           <a  href="/" class="block py-1 md:py-3 pl-1 align-middle text-gray-800 no-underline border-b-2 border-gray-800 md:border-gray-900">&emsp;&emsp;<img src="{% static 'images/logo.png' %}" width="100%"
                height="100%"></a>
        </li>  
       </ul>
    </div>
 </div>

Bootstrap that You are referring to is CSS framework with extra JavaScript (using jQuery) scripts for modals, dropdowns, and collapses (that You are trying to get right now).您所指的引导程序是 CSS 框架,带有额外的 JavaScript(使用 jQuery)脚本,用于模式、下拉和折叠(您现在正试图获得)。

Tailwind is in other hand "just" CSS framework without any JS.另一方面,Tailwind 是“只是”没有任何 JS 的 CSS 框架。

Also opposite to Bootstrap (or Bulma or any other similiar framework) is does not contain any components like buttons, inputs etc. So there is also no ready to use "collapse" component.同样与 Bootstrap(或 Bulma 或任何其他类似框架)相反的是不包含任何组件,如按钮、输入等。因此也没有准备好使用的“折叠”组件。 Instead it is used just for styling from scratch, just like with plain CSS.相反,它仅用于从头开始造型,就像普通的 CSS 一样。

Unlike many other CSS frameworks, Tailwind doesn't include any component classes like form-input, btn, card, or navbar.与许多其他 CSS 框架不同,Tailwind 不包含任何组件类,如表单输入、btn、卡片或导航栏。

Tailwind is a CSS framework for implementing custom designs, and even a component as simple as a button can look completely different from one site to another, so providing opinionated component styles that you'd end up wanting to override anyways would only make the development experience more frustrating. Tailwind 是一个用于实现自定义设计的 CSS 框架,即使是像按钮这样简单的组件在一个站点之间看起来也可能完全不同,因此提供您最终想要覆盖的固执己见的组件 styles 只会使开发体验更令人沮丧。

Source: https://tailwindcss.com/components来源: https://tailwindcss.com/components

Collapsing menu that You are trying to achieve requires some scripting (JS) to work.您尝试实现的折叠菜单需要一些脚本 (JS) 才能工作。 Because I do not know it You are using jquery or some JS framework, I cannot give you any ready to use example.因为我不知道你正在使用 jquery 或一些 JS 框架,我不能给你任何现成的例子。 But it actually has nothing to do with Tailwind itself.但它实际上与 Tailwind 本身无关。 It is just hiding/displaying some element after clicking in another element.它只是在单击另一个元素后隐藏/显示某个元素。 It is logic that can be achieved with any JS framework or plain JS, depends what You need.它是可以用任何 JS 框架或普通 JS 实现的逻辑,取决于您需要什么。

If you are using for example Vue framework which will work great with Tailwind, then You can use conditional rendering ( https://v2.vuejs.org/v2/guide/conditional.html ) but like I said it has nothing to do with Tailwind itself so there is no point to give Vue examples in this Tailwind related question.例如,如果您使用的 Vue 框架可以很好地与 Tailwind 配合使用,那么您可以使用条件渲染( https://v2.vuejs.org/v2/guide/conditional.html )但就像我说的那样,它与Tailwind 本身,因此没有必要在这个 Tailwind 相关问题中给出 Vue 示例。

If you want to achieve this with tailwind the easiest approach is to use alpine js to toggle.如果你想用顺风实现这一点,最简单的方法是使用 alpine js 来切换。

You can find more information and download that library on: https://github.com/alpinejs/alpine您可以在以下位置找到更多信息并下载该库: https://github.com/alpinejs/alpine

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM