自定义光标围绕应用程序中所有文本实例,而不使用 ?
我正在向我的一个 Web 应用程序添加自定义光标,但我不希望所有内容都使用指针光标。当您将鼠标悬停在文本上时,您的 Web 浏览器将更改为文本光标,因此我也希望在我的应用程序中使用自定义文本光标。
您可以仅使用类似我希望有一些更简单的方法来更改文本的光标
<span class="curText">This is some text</span>
.curText { cursor: url(textcursor.cur), auto; }
,即使它有点“hacky”,即使它涉及CSS和/或JavaScript,选择应用程序中的所有文本。否则,我必须记住在我想要文本光标的任何文本周围添加。这当然是可行的,尽管我希望有一种更简单的方法。
I am adding custom cursors to one of my web applications and I don't want the pointer cursor for everything. When you hover over text, your web browser will change to the text cursor, so I want a custom text cursor in my application as well.
You can change the cursor for text only using something like
<span class="curText">This is some text</span>
.curText { cursor: url(textcursor.cur), auto; }
I was hoping there was some easier way, even if it's a little "hacky", even if it involves both CSS and/or JavaScript, of selecting all text in an application. Otherwise, I will have to remember to add the around any text that I want the text cursor for. This is certainly doable, though I am hoping there is an easier way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定您为什么不想使用
标签,因为它的用途非常适合您。据我所知,没有其他纯 CSS 方法可以解决您的问题。我确信你可以在 jQuery 中破解它(也许使用
:parent
和/或:empty
选择器,但这会更加混乱,我真的不想要引导你朝那个方向...),但我想说的是正确地使用span
,特别是如果它“当然可行”。您不必将
curText
类应用于您的跨度,您只需添加p span、div span、li span
等声明,因为您希望样式全面适用,而不仅仅是特定范围I'm not sure why you would not want to use the
<span>
tag, because its purpose is pretty much exactly right for you. There's no other pure CSS way that I know of to solve your problem. I'm sure you could hack it in jQuery (maybe using the:parent
and/or:empty
selectors, but that would be so much messier I don't really want to lead you in that direction...), but I'd say do it right and usespan
, especially if it's "certainly doable".You don't have to apply your
curText
class to your spans, you could just add declarations forp span,div span,li span
etc. since you want the style to apply accross the board and not just to specific spans