抱歉,如果这是一个骗局;我还没有发现任何提出同样问题的问题。
a CSS blog site
(它位于文本“为了设置定位上下文”的正下方。)我在自己的代码中也遇到了同样的问题。
div
overflow: auto
设置。)如屏幕截图所示,灰色背景的周围线条不会拉伸到填充父画布的整个宽度。相反,它们保持固定在父母的宽度上
分区
s包含单独的文本行。)
我在Firefox 3.1和IE8中看到了这一点(无论IE7兼容模式如何。)
分区
(来源:
outofwhatbox.com
)
编辑
:这是一个简单的例子。出于某种原因,滚动条在IE中不显示,但在Firefox 3.1中显示(并且与我在其他地方看到的行为相同)
Note: The CSS shown here is derived from SyntaxHighlighter
(http://alexgorbatchev.com/), released under GPL 3.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>sample</title>
<style type="text/css">
.syntaxhighlighter .line.alt1 .content {
background-color:#FFFFFF !important;
}
.syntaxhighlighter .line .content {
color:#000000 !important;
display:block !important;
font-family: "Consolas","Monaco","Bitstream Vera Sans Mono","Courier New",Courier,monospace;
font-size: 12pt;
font-weight: 400;
color: #000000;
white-space: nowrap;
}
.syntaxhighlighter .line.alt2 .content {
background-color:#F0F0F0 !important;
}
.syntaxhighlighter {
background-color:#E7E5DC !important;
margin:1em 0 !important;
padding:1px !important;
width:497px !important;
height: auto !important;
}
.line {
overflow:visible !important;
}
.lines {
overflow-x:auto !important;
}
</style>
</head>
<body>
<div class="syntaxhighlighter" >
<div class="lines">
<div class="line alt1">
<span class="content">
<span style="margin-left: 0px ! important;" class="block">
<code class="plain">this is line 1 </code>
</span>
</span>
</div>
<div class="line alt2">
<span class="content">
<span style="margin-left: 20px ! important;" class="block">
<code class="plain">this is line 2</code>
</span>
</span>
</div>
<div class="line alt1">
<span class="content">
<span style="margin-left: 40px ! important;" class="block">
<code class="plain">this is a very very very very very very long line number 3</code>
</span>
</span>
</div>
<div class="line alt2">
<span class="content">
<span style="margin-left: 0px ! important;" class="block">
<code class="keyword">this is line 4</code>
</span>
</span>
</div>
<div class="line alt1">
<span class="content">
<span style="margin-left: 20px ! important;" class="block">
<code class="plain">and this is line 5.</code>
</span>
</span>
</div>
</div>
</div>
更新
2009/05/14:这是我部署的脚本,基于
brianpeiris's answer
more detailed description
// Ensure that each content <span> is sized to fit the width of the scrolling region.
// (When there is no horizontal scrollbar, use the width of the parent.)
fixContentSpans : function() {
jQuery('.syntaxhighlighter > div.lines').each(function(){
var container = jQuery(this);
var scrollWidth = this.scrollWidth;
var width = jQuery(this).width();
var contents = container.find('.content');
jQuery(contents).each(function(){
var child = jQuery(this);
var widthAvail =
scrollWidth - parseFloat(child.css("margin-left"))
- parseFloat(child.css("padding-left"))
- parseFloat(child.css("padding-right"));
var borderLeft = parseFloat(child.css("border-left-width"));
// IE uses names (e.g. "medium") for border widths, resulting in NaN
// when we parse the value. Rather than trying to get the numeric
// value, we'll treat it as 0. This may add a few additional pixels
// in the scrolling region, but probably not enough to worry about.
if (!isNaN(borderLeft)) {
widthAvail -= borderLeft;
}
child.width(widthAvail);
});
});
},