在标签内添加按钮,但不更改任何样式。

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

Add button inside the label but without changing any styles

问题

我在我的网站上有这段代码,其中包含一个标题:<h3 class="label" type="button">
这是一个手风琴效果,所以我想通过以下方式增加可访问性:<h3 class="label"><button aria-expanded="true">
但它会在按钮上添加一些样式,我不想要这个,我想保留当前的样式。是否有一种高效的方法来实现这一点,而不仅仅是为按钮的特殊类添加样式?

英文:

I have the code on my website with a header: <h3 class="label" type="button">
It is an accordion so I'd like to make it more accessible by changing it to:
<h3 class="label"><button aria-expanded="true">. But it adds some styling on top for the button. I don't want this, I would like to keep the styling that is now. Is there any efficient way to do this, other than just styling the special class of the button?

答案1

得分: 1

它需要 all: inherit 样式,可以内联添加。

英文:

It needs all: inherit style, can be added inline.

答案2

得分: 0

你可以对按钮元素应用一个全局继承:

button.aria-button {
    all: inherit;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

以及HTML:

<h3 class="label">
    <button class="aria-button" aria-expanded="true">
        {你的文本}
    </button>
</h3>
英文:

You can apply a global inherit to the button element:

button.aria-button {
    all: inherit;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

and html:

&lt;h3 class=&quot;label&quot;&gt;
    &lt;button class=&quot;aria-button&quot; aria-expanded=&quot;true&quot;&gt;
        {yourText}
    &lt;/button&gt;
&lt;/h3&gt;

huangapple
  • 本文由 发表于 2023年6月12日 18:59:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/76455993.html
匿名

发表评论

匿名网友

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

确定