简体   繁体   English

html / css / javascript hover 文本'dictionary

[英]html / css / javascript hover text 'dictionary'

I plan on making several pages of instructional topics in which some words should have popup text to further define a word.我计划制作几页教学主题,其中一些单词应该有弹出文本以进一步定义一个单词。 So far, my limited knowledge of creating a popup text includes (if an image):到目前为止,我创建弹出文本的有限知识包括(如果是图像):

<img src="\images\image1.png" alt="" title="hover text" />

But I am more after a popup box when hovering over text such as:但是当悬停在文本上时,我更喜欢弹出框,例如:

<p><dfn title="HyperText Markup Language">HTML</dfn> is the standard markup language for creating web pages.</p>
<p><dfn title="Cascading Style Sheets">CSS</dfn> is another standard markup language for creating web pages.</p>

If I have multiple instances of 'HTML' that I want associated with a popup to occur throughout a page, that would become rather cumbersome to ensure I have the exact same wordage for the definitions of 'HTML' or 'CSS' where they might appear.如果我有多个“HTML”实例,我希望在整个页面中出现与弹出窗口相关联,那么要确保它们可能出现的“HTML”或“CSS”的定义具有完全相同的措辞,这将变得相当麻烦. Is there some sort of class definition dictionary or perhaps a sort of function that can be utilized to wrap around every 'HTML' or 'CSS' instance?是否有某种 class 定义字典或某种 function 可用于环绕每个“HTML”或“CSS”实例? For example:例如:

Here is some text leading up to the word <class = "definition", id = "HTML"> and I am continuing some text until I get to <class = "definition", id = "CSS"> and then I continue my text.

What would be the best practice for such a scenario?这种情况下的最佳实践是什么? I want to ensure that the definitions are the same throughout the text and, as I expand to other pages, the same as well.我想确保整个文本中的定义是相同的,并且当我扩展到其他页面时,它们也是相同的。

While the dfn element allows for making in-page links, this is not as smooth an experience for the user as hovering over a word as they have to do something to go back to where they were.虽然 dfn 元素允许创建页内链接,但对于用户而言,这并不像将鼠标悬停在一个单词上那样流畅,因为他们必须对 go 做一些事情回到原来的位置。 It also doesn't automatically work across pages.它也不会自动跨页面工作。

How about using CSS classes and after pseudo elements on dfns?在 dfns 上使用 CSS 类和伪元素之后怎么样? I know this is putting stuff with actual meaning in the content, but it does work to a certain extent (there are the usual problems with where to fit your popup if near the end of a line for example).我知道这是在内容中添加了具有实际意义的东西,但它确实在一定程度上起作用(例如,如果在行尾附近放置弹出窗口的位置通常会出现问题)。

To create the CSS you'd probably want to knock up some JS or some back-end script if you have a very long list of definitions.要创建 CSS,如果您有很长的定义列表,您可能需要敲一些 JS 或一些后端脚本。

Here is the code from the question marked up this way:这是以这种方式标记的问题中的代码:

 dfn:hover::after { position: absolute; z-index: 9999; background-color: white; border-color: red; border-style: solid; padding: 5px; }.html:hover::after { content: 'HyperText Markup Language'; }.css:hover::after { content: 'Cascading Style Sheet'; }
 <p><dfn class="html">HTML</dfn> is the standard markup language for creating web pages.</p> <p><dfn class="css">CSS</dfn> is another standard markup language for creating web pages.</p>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM