HTML Marquee 在一定长度后缩小

问题描述 投票:0回答:1

我正在尝试使用 HTML Marquee 在标题上创建简单的滚动文本。但是,根据当前的文本长度,在达到一定量的文本后,容器似乎会缩小,从而切断文本。我的代码如下。

<html>
<head>
<style>
marquee {
  color: black;
  font-family: courier;
  font-size:16pt;
  text-align: center;
}
</style>
</head>
<body>

<marquee
  bgcolor="#ECC039"
  width="100%"
  height="32">
  <marquee> 
    <strong>EXAMPLE EXAMPLE EXAMPLE EXAMPLE EXAMPLE EXAMPLE EXAMPLE EXAMPLE</strong>
    <span style="margin-left:1in;"></span> 
    <strong>EXAMPLE EXAMPLE EXAMPLE EXAMPLE EXAMPLE EXAMPLE EXAMPLE EXAMPLE</strong>
  </marquee>
</marquee>
  
</body>
</html>

我尝试过在像素指定宽度和百分比宽度之间进行更改,更改滚动速度等。它似乎只有在开始切断时才会发生变化。

html marquee
1个回答
0
投票

文本被截断的原因是您在另一个选取框内使用了嵌套选取框。这不是有效的 HTML 结构,可能会在不同的浏览器中导致不可预测的行为。内部选取框不知道外部选取框的宽度,并且可能会溢出或缩小,具体取决于浏览器的渲染引擎。

要解决此问题,您应该仅使用一个选取框元素并将其宽度设置为 100%。您还可以使用scrollamount属性来控制滚动文本的速度。

<html>
<head>
<style>
marquee {
color: black;
font-family: courier;
font-size:16pt;
text-align: center;
}
</style>
</head>
<body>

<marquee
bgcolor="#ECC039"
width="100%"
height="32"
scrollamount="10">
<strong>EXAMPLE EXAMPLE EXAMPLE EXAMPLE EXAMPLE EXAMPLE EXAMPLE EXAMPLE</strong>
<span style="margin-left:1in;"></span> 
<strong>EXAMPLE EXAMPLE EXAMPLE EXAMPLE EXAMPLE EXAMPLE EXAMPLE EXAMPLE</strong>
</marquee>

</body>
</html>

© www.soinside.com 2019 - 2024. All rights reserved.