简体   繁体   English

我为我的网页设置了焦点状态。 但即使在我完成点击按钮/链接之后,焦点仍然存在,除非我点击空格。 我该怎么做?

[英]I styled focus state for my webpage. But even after I'm done clicking button/link, the focus stays, unless I click whitespaces. How do I make it go?

I've styled the focus state for my webpage to my liking.我已经根据自己的喜好为我的网页设置了焦点状态。 But now it stays on the buttons/links even when I'm done clicking them.但是现在即使我完成了单击它们,它也会保留在按钮/链接上。 I have to click the blank spaces to make it go away.我必须单击空白处才能使其消失。 I only want the focus state to be visible when we use TAB key for shifting focus, and(optional) when the buttons are clicked.我只希望当我们使用 TAB 键移动焦点时焦点状态可见,并且(可选)单击按钮时可见。 How can I do that?我怎样才能做到这一点? Do I need to write some JavaScript for that?我需要为此编写一些 JavaScript 吗? Basically I want the focus state to behave in a default way, the way it did before I styled it.基本上我希望焦点状态以默认方式运行,就像我设置它之前所做的那样。

*:focus {
  outline: none;
  box-shadow: 0 0 0 0.5rem rgba(61, 112, 46, 0.5);
}

.cta *:focus {
  box-shadow: 0 0 0 0.5rem rgba(255, 255, 255, 0.5);
}

try using this css selector instead of *:focus尝试使用这个 css 选择器而不是*:focus

*:focus-visible{
    outline: none;
    box-shadow: 0 0 0 0.5rem rgba(61, 112, 46, 0.5);

}

暂无
暂无

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

相关问题 我正在尝试在网页上动态上下移动元素。 我怎么做? - I'm trying to dynamically move elements up and down on my webpage. How do I do that? 焦点仅在我使用选项卡转到按钮时有效,之后当我单击按钮时焦点不起作用 - focus only works when I go to the button with tab, after that when I click on button focus is not working 单击弹出按钮后,我想在网页上显示一些文本。 但是不起作用,有什么建议吗? - After clicking popup button I want to display some text on the webpage. But not working, any suggestions? 我的网页上的暗模式按钮有问题。 无论我做什么,它总是出错,就好像它是一个无限循环 - I have a problem with the dark mode button on my webpage. Whatever i do, it always bugs as if it was a infinity loop 在 Vue 3 中单击按钮而不闪烁后,如何将注意力集中在输入上? - How do I keep the focus on an input, after i click on a button without flickering in Vue 3? 如何在 ReactJS 中单击按钮 - How can I focus a button on click in ReactJS 我已将此数据读入控制台。 我想在我的网页中显示“ exampleHeader”和“ exampleBody”。 我该怎么办? - I have this data reading into my Console. I want to display the “exampleHeader” and “exampleBody” in my webpage. How would I do so? 单击按钮时如何将焦点保持在所选文本上? - How can I keep the focus to my selected text when I click a button? 我怎样才能使分享这个按钮分享它留在旁边的链接? - How can I make the Share This button to share the link it stays beside? 当我单独单击带有 JavaScript 的按钮时,如何聚焦输入 - How do I focus an input when I click a button with JavaScript alone
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM