Text width not applying in span

2019-08-15 06:46发布

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>

A link to JSFiddle.

3条回答
2楼-- · 2019-08-15 07:10

display as "block":

<span style='background-color:red; width:65pt; display: block' id='ticker'></span>
查看更多
SAY GOODBYE
3楼-- · 2019-08-15 07:11

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.

查看更多
我想做一个坏孩纸
4楼-- · 2019-08-15 07:11

You can wrap it in a containing div also and apply the styling to the div..

http://jsfiddle.net/w9ccq96x/1/

<div style="background-color:red;width:100px;overflow:hidden;"><span id='ticker'></span></div>
查看更多
登录 后发表回答