文字宽度不适用于跨度 [英] Text width not applying in span

查看:76
本文介绍了文字宽度不适用于跨度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看不到如何固定跨度宽度,因此它不会摆动:

I can't see how to fix the span width so it doesn't wobble:

<!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取决于与其他元素的交互作用.

the span element is an inline element, this means its width and height are controlled by the content, you need to use either display:inline-block or display:block depending on the wanted interaction with other elements.

这篇关于文字宽度不适用于跨度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆