gpt4 book ai didi

javascript - 文本宽度不适用于跨度

转载 作者:行者123 更新时间:2023-11-30 12:28:08 25 4
gpt4 key购买 nike

我看不出如何固定跨度宽度使其不摆动:

<!DOCTYPE html>
<html>
<script>
function go() {
x='this message will self-destruct in five seconds.......';
xl=x.length;
x+=x;
n=0;
setInterval('ticker.textContent=x.slice(n++,n+10);if (n>xl-10) n=0;',100);
}
</script>
<body onload='go();'>
<span style='background-color:red;width:100pt' id='ticker'></span>
</body>
</html>

JSFiddle 的链接.

最佳答案

span 元素是一个 inline 元素,这意味着它的 widthheight 由内容控制,您需要使用 display:inline-blockdisplay:block ,具体取决于与其他元素的交互。

关于javascript - 文本宽度不适用于跨度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28653505/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com