Is it possible to let :after pseudo element get focus when press tab

北城以北 提交于 2019-12-18 07:02:44

问题


I have one h1 element, which has a :after pseudo element, when firstly press tab, this h1 element will get focus, but when I press tab again, the focus will go to next REAL element, how could I make the focus go to the pseudo element?

HTML:

<h1 class="title" tabindex="0">Some text</h1>

CSS:

title::after {
   width: 16px;
   height: 16px;
   background: url('image')
}

I want to let focus go to this 16X16 image, is it possible?


回答1:


The ::before and ::after pseudo-elements are not focusable.

If you absolutely need this box to be focusable you will have to make it a real element, possibly inserted using JS if you don't feel comfortable polluting your markup.



来源:https://stackoverflow.com/questions/31578805/is-it-possible-to-let-after-pseudo-element-get-focus-when-press-tab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!