如何替换文本而不使后面的内容“跳转”?
我有网页,中间有一段文字。当用户将光标悬停在图像上时,我想替换文本,但我不希望页面看起来在跳来跳去,并且有几种可能的文本 - 长度不同。
我想这意味着我需要为文本保留固定的大小,但是哪个呢?
文本不多,只有少数,所以我不需要编写任何代码来确定最大的大小,我可以手动完成。但是什么是一个好的文本容器呢?由于旧的和新的长度不同,替换它不会使页面内容在向上或向下跳转后。新文本?
I have web page and in the middle of it is a paragraph of text. I want to replace the text when the user hovers the cursor over an image, but I don't want the page to seem to jump around and there are several possible texts - of differing lengths.
I guess that that means that I need to reserve a fixed size are for the text, but which?
There are not so many texts, just a handful, so I don't need to write any code to determine the size of the largest, I can just do it manually. But what's a good container for the text to that replacing it does not make the page contents after either jump up or down owing to difference of length of old & new text?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果文本较长,则放置滚动条;如果文本较短,则留出空白空间怎么样?
How about putting a scroller bar if the text is longer and leave empty space if it's shorter?
该段落可以位于带有
overflow: hide;
属性的 div 中并设置宽度和高度this paragraph could be in div with
overflow: hidden;
attribute and set width and height为什么不使用覆盖 div,而不是替换文本呢?
Instead of replacing the text, why not have an overlay div?