我试图更改选定型式杆的选项的各个样式,并使角落四舍五入,但可以吗?

发布于 2025-02-11 00:51:29 字数 777 浏览 0 评论 0原文

我正在使用tailwind进行风格,但不确定如何在CSS中更改它,要么选择选择,

<select class="h-8 w-24 bg-neutral-900 cursor-pointer inline-flex align-middle p-1 m-4 font-bold text-neutral-400 hover:text-red-800 active:text-red-900 focus:text-red-800 transition ease-in-out duration-300 carret-black">
 <option>red</option>
  <option>green</option>
  <option>blue</option>          
</select>

我无法通过将类添加到选项并以这种方式进行更改,并且无法找到如何找到要更改选项背景,文字颜色和圆形菜单的边缘。

因此看起来像 image 1 ,我希望它看起来更像 image 2

我也尝试通过CSS进行此操作以无济于事,这对任何帮助都将非常感谢。

I'm using tailwind to style but am not sure how to change it in CSS either heres the code for the select

<select class="h-8 w-24 bg-neutral-900 cursor-pointer inline-flex align-middle p-1 m-4 font-bold text-neutral-400 hover:text-red-800 active:text-red-900 focus:text-red-800 transition ease-in-out duration-300 carret-black">
 <option>red</option>
  <option>green</option>
  <option>blue</option>          
</select>

I can't change it by adding class to the options and doing it that way and haven't been able to find how to change the options background, text colour and rounding the edges of the dropdown menu.

So it looks like image 1 and i want it to look more like image 2

I've also tryed doing it through CSS to no avail either any help would be greatly appreciated thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

箜明 2025-02-18 00:51:29

确实,您无法使用CSS为选择选项设计。您可以做的是创建自己的选择组件。为了获得所有内容,例如可访问性,运行良好可能很棘手。

您可以将 headless ui listbox 作为起点。这是一个未风格的自定义选择,可以用尾风CSS创建样式。

希望这会有所帮助。

Indeed, you cannot style the select options with CSS. What you can do is create your own select component. To get everything, like accessibility, working well can be tricky though.

You could take the Headless UI listbox as a starting point. This is an unstyled custom select, created to style with Tailwind CSS.

Hope this helps.

帅气尐潴 2025-02-18 00:51:29

DOM中没有可访问的选项容器(包装器)元素可以更改其样式。
您可以创建自己的下拉列表:

    <!-- Component Start -->
    <div class="relative">
        <button class="flex items-center h-8 pl-3 pr-2 border border-black focus:outline-none">
            <span class="text-sm leading-none">
                Dropdown
            </span>
            <svg class="w-4 h-4 mt-px ml-2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
                <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>
        </button>
        <div class="absolute flex flex-col w-40 mt-1 border border-black shadow-lg">
            <a class="flex items-center h-8 px-3 text-sm hover:bg-gray-200" href="#">Item 1</a>
            <a class="flex items-center h-8 px-3 text-sm hover:bg-gray-200" href="#">Item 2</a>
            <a class="flex items-center h-8 px-3 text-sm hover:bg-gray-200" href="#">Item 3</a>
            <a class="flex items-center h-8 px-3 text-sm hover:bg-gray-200" href="#">Item 4</a>
        </div>
    </div>
    <!-- Component End  -->

there is no accessible options container (wrapper) element in the Dom in order to change it's style.
you can create your own dropdown :

    <!-- Component Start -->
    <div class="relative">
        <button class="flex items-center h-8 pl-3 pr-2 border border-black focus:outline-none">
            <span class="text-sm leading-none">
                Dropdown
            </span>
            <svg class="w-4 h-4 mt-px ml-2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
                <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>
        </button>
        <div class="absolute flex flex-col w-40 mt-1 border border-black shadow-lg">
            <a class="flex items-center h-8 px-3 text-sm hover:bg-gray-200" href="#">Item 1</a>
            <a class="flex items-center h-8 px-3 text-sm hover:bg-gray-200" href="#">Item 2</a>
            <a class="flex items-center h-8 px-3 text-sm hover:bg-gray-200" href="#">Item 3</a>
            <a class="flex items-center h-8 px-3 text-sm hover:bg-gray-200" href="#">Item 4</a>
        </div>
    </div>
    <!-- Component End  -->
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文