[英]Text width not applying in span
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>
span
元素是一个inline
元素,这意味着它的width
和height
由内容控制,您需要使用display:inline-block
或display:block
具体取决于与其他元素的需要交互。
显示为“块”:
<span style='background-color:red; width:65pt; display: block' id='ticker'></span>
You can wrap it in a containing div also and apply the styling to the div.. 您也可以将它包装在一个包含div中,并将样式应用于div。
http://jsfiddle.net/w9ccq96x/1/ http://jsfiddle.net/w9ccq96x/1/
<div style="background-color:red;width:100px;overflow:hidden;"><span id='ticker'></span></div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.