Jon Snyder
2009-05-02 20:13:40
A:
+2
A:
If you don't mind a bit of jQuery, run the following code in Firebug on the nettuts+ website to fix the problem.
$('.dp-highlighter').each(function(){
var container = $(this);
if(this.scrollWidth !== $(this).width()) {
container.children().each(function(){
var child = $(this);
var childPaddingLeft = parseInt(child.css('paddingLeft').slice(0, -2));
child.width(container.get(0).scrollWidth - childPaddingLeft);
});
}
});
Edit: Seems to work in IE7/8 as well.
Further Edit: Here's the JavaScript necessary to fix the code you provided:
$('.syntaxhighlighter > div').each(function(){
var container = $(this);
if(this.scrollWidth !== $(this).width()) {
container.find('.content').each(function(){
var child = $(this);
child.width(container.get(0).scrollWidth);
});
}
});
Demo
I've hosted your code on JS Bin with the JavaScript fix: http://jsbin.com/axeso
brianpeiris
2009-05-02 20:27:49
This looks promising, but I haven't been able to make it work with the code in my sample (see update above.) Note that my sample uses "syntaxhighlighter" as the class for the top-level div; I assumed that I should change the script to match.
Dan Breslau
2009-05-03 05:18:50
Excellent! Thanks!
Dan Breslau
2009-05-03 16:24:54
You're welcome! Glad I could help.
brianpeiris
2009-05-03 17:36:40
Thought you might be interested in the update above. Also, I've blogged about this at http://www.outofwhatbox.com/blog/2009/05/fixing-a-scroll-where-the-grays-came-in/ . Thanks again.
Dan Breslau
2009-05-15 01:47:57
Wow Dan! An excellent write-up and thanks for the shout-out, I am honoured (/me bows). I might open another can of worms by mentioning this but if you really want to avoid jQuery I don't think that re-writing the code would be too difficult since the jQuery parts that you've used only constitute a small portion of the jQuery code. Anyway, I think you've greatly improved SyntaxHighlighter, enough for the original devs to incorporate your changes. (You glossed over the change to the line numbers but that's more significant IMO ;) ). Great job!
brianpeiris
2009-05-15 06:09:30
Thanks! Go ahead and open that can, I figured I'd have to go there eventually :-)
Dan Breslau
2009-05-15 13:32:29
+1
A:
Just tested this and it seems to work, even way back to ie6.
#wrapper{width:300px; height:100px;border:1px solid black; overflow:auto;position:relative;}
#inner{width:auto;position:absolute;}
.content{white-space:pre;height:20px;width:auto;overflow:show;}
.alt {background:gray;}
<div id="wrapper">
<div id="inner">
<div class="content">content content content content content content content content content </div>
<div class="content alt">content content content content content content content content content </div>
</div>
</div>
The one downside is that you have to specify the height of the wrapper or the whole thing collapses vertically. You could use javascript to fix this though (wrapper height = number of content divs * height of a content div).
wheresrhys
2009-05-02 21:18:26
I'm afraid this doesn't do what I was looking for. Try adding two more (shorter) lines, and I think you'll see what I mean: <div class="content">malcontent</div> <div class="content alt">malcontent </div>
Dan Breslau
2009-05-03 04:23:03
hmmm - you could try using the faux columns css technique sideways? If you're not familiar with it, it would involve using a background image on the inner div,repeated in both x and y directions, 1 px wide, and essentially a vertical cross-section of 2 rows. If that needws better explanatuion let me know
wheresrhys
2009-05-03 10:33:20