背景颜色不会超出带滚动条的 div 框中的可见区域

发布于 2024-11-17 11:51:40 字数 894 浏览 1 评论 0原文

[已关闭]

此页面上,有一个 div 框,其中包含代码示例,其中应该为某一行指定背景颜色。这种背景颜色实际上是通过使用正则表达式将开始和结束符号替换为代码来制作带有红色背景的 div 来完成的。这工作得很好,我们有红色背景,正则表达式正在做他们的工作。

但是,如果我们在代码框中滚动一点,我们会注意到红色背景颜色停止在代码框的实际边缘所在的位置(但我们可以滚动,所以这不是结束)。这应该说明我的意思: 图一:我们的背景颜色在它应该之前终止

我已经尝试了几乎所有我能想到的与 firebug 相关的 CSS 值,包括尝试所有可能的溢出选项。对于宽度,如果我手动给出绝对宽度,它可以进一步扩展它,但这不会这样做,因为背景颜色是自动生成的,JavaScript 使用具有良好后备的方法,以防 JavaScript 加载失败或被禁用。

那么,有人知道如何让这些背景一直延伸到最后吗?我考虑过计算字符数,但由于背景颜色通常覆盖不止一行,甚至在其他页面上覆盖数百行,这似乎不切实际,而且相当资源化。首选 CSS 方法,但如果需要的话,我会使用 javascript 修复。

如果您想亲自查看该页面,请随意,该页面只是一个显示特定问题的沙箱,并且可以找到用 div 元素替换某些注释以制作此背景图片的脚本 此处

预先感谢您的任何帮助和/或建议。

[CLOSED]

On this page, there is a div box which holds a code example, where a certain line is supposed to be given a background color. This background color is actually done by using regular expressions to replace a start and end symbol with the code to make a div with our red background. This works fine, we have our red background, the regular expressions are doing their work.

However, if we scroll over a bit in code box, we notice that the red background color stops where the actual edge to the code box is (but we can scroll over, so it's not the end). This should illustrate what I mean:
Figure One: Our background color terminating before it should be

I've tried pretty much every CSS value I could think of with firebug, including trying every possible overflow option. With width, if I manually give an absolute width, it can extend it further, but this won't do because the background coloring is generated automatically, with javascript using a method with good fallback in case the javascript fails to load or is disabled.

So, does anyone know a way to get those backgrounds extending all the way to the end? I considered counting the characters, but since the background colors often cover more than a single line, and even hundreds of lines on some other pages, it seems impractical and rather resourcy. A CSS method would be prefered, though should it come to it, I'll go with a javascript fix.

If you want to take a look at the page for yourself, feel free, that one is just a sandbox to show the specific problem, and the script that replaces certain comments with div elements to make this background image is found here.

Thanks in advance for any help and/or advice.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

知足的幸福 2024-11-24 11:51:40

overflow:auto 不能很好地协同工作,并且可能是问题的根源。

尝试使用

作为滚动容器。

所以:

<div style="overflow: auto">
  <pre>
    ...content...
  </pre>
</div>

而不是

<pre style="overflow: auto">
  ...content...
</pre>

<pre> and overflow:auto doesn't play nice together, and is likely the base of your problem.

Try to use a <div> as scroll container instead.

So:

<div style="overflow: auto">
  <pre>
    ...content...
  </pre>
</div>

Instead of

<pre style="overflow: auto">
  ...content...
</pre>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文