如何删除HTML选择标签的默认箭头?

huangapple go评论80阅读模式
英文:

How to remove the HTML select tag's default arrow?

问题

我正在使用vuejs和tailwindcss。
如何删除HTML选择元素的默认箭头?
我已经尝试使用CSS删除外观:

select {
    -moz-appearance: none;
    -webkit-appearance: none;
    -ms-appearance: none;
    -o-appearance: none;
    appearance: none;
}

以及使用tailwind的appearance-none类:

<select :onchange="selectChanged()"
        class="bg-transparent text-xl border-0 rounded-md hover:bg-slate-800 appearance-none" ref="eventSelect">

我的当前模板代码如下:

<template>
    <div>
        <select :onchange="selectChanged()"
                class="bg-transparent text-xl border-0 rounded-md hover:bg-slate-800 appearance-none" ref="eventSelect">
            <option class="bg-slate-800">50m </option>
            <option class="bg-slate-800"> 60m </option>
            <option class="bg-slate-800"> 100m </option>
            <option class="bg-slate-800"> 300m </option>
        </select>
    </div>
</template>

它的外观如下图所示:
如何删除HTML选择标签的默认箭头?
我似乎无法将其删除,不知何故 如何删除HTML选择标签的默认箭头?

英文:

I am using vuejs and tailwindcss.
How do I remove the default arrow from HTML select's element?
I've already tried removing appearance with css:

select {
    -moz-appearance: none;
    -webkit-appearance: none;
    -ms-appearance: none;
    -o-appearance: none;
    appearance: none;
}

as well as with tailwind's appearance-none

&lt;select :onchange=&quot;selectChanged()&quot;
            class=&quot;bg-transparent text-xl border-0 rounded-md hover:bg-slate-800 appearance-none&quot; ref=&quot; eventSelect&quot;&gt;

My current template code:

&lt;template&gt;
    &lt;div&gt;
        &lt;select :onchange=&quot;selectChanged()&quot;
            class=&quot;bg-transparent text-xl border-0 rounded-md hover:bg-slate-800 appearance-none&quot; ref=&quot; eventSelect&quot;&gt;
            &lt;option class=&quot;bg-slate-800&quot;&gt;50m &lt;/option&gt;
            &lt;option class=&quot;bg-slate-800&quot;&gt; 60m &lt;/option&gt;
            &lt;option class=&quot;bg-slate-800&quot;&gt; 100m &lt;/option&gt;
            &lt;option class=&quot;bg-slate-800&quot;&gt; 300m &lt;/option&gt;
        &lt;/select&gt;
    &lt;/div&gt;
&lt;/template&gt;

It looks like this:

如何删除HTML选择标签的默认箭头?

I just can't seem to get it removed for some reason 如何删除HTML选择标签的默认箭头?

答案1

得分: 2

几周后,我找到了适合我的解决方案...
由于某种原因(可能是vuejs的默认设置),&lt;select&gt;元素被样式化为包含箭头的背景图像。如果将其移除,仍会保留默认填充,为了重置这两个值,我添加了以下内容:

&lt;style&gt;

select {
background: none;
padding: 0;
}

&lt;/style&gt;
英文:

After couple of weeks I found something that have worked for me...
For some reason (probably vuejs default settings) the &lt;select&gt; element is styled with background image that contains an arrow. If you remove it, you are still left with default padding, so to reset those two values, I added this:

&lt;style&gt;

select {
background: none;
padding: 0;
}

&lt;/style&gt;

答案2

得分: 0

.custom-select {
  /* 隐藏默认箭头 */
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
}
<select class="custom-select">
  <option value="option1">选项 1</option>
  <option value="option2">选项 2</option>
  <option value="option3">选项 3</option>
</select>
如你所见,以下代码行按预期工作,我猜你需要确保你的 CSS 正常工作并且你的样式应用到你的 HTML 中。
英文:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.custom-select {
  /* Hide the default arrow */
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
}

<!-- language: lang-html -->

&lt;select class=&quot;custom-select&quot;&gt;
  &lt;option value=&quot;option1&quot;&gt;Option 1&lt;/option&gt;
  &lt;option value=&quot;option2&quot;&gt;Option 2&lt;/option&gt;
  &lt;option value=&quot;option3&quot;&gt;Option 3&lt;/option&gt;
&lt;/select&gt;

<!-- end snippet -->

as you can see the following line of code works as expected, I guess you need to make sure that your CSS is working properly and your styles are applied to your HTML

huangapple
  • 本文由 发表于 2023年5月13日 16:29:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76241788.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定