10

I'm using a jQuery slider to adjust the padding of a DIV containing paragraph text. As I increase the padding on all sides equally, it should force the enclosed paragraphs into an ever-narrower column, in the center of the page.

This works in Firefox, but in Chrome the paragraph widths remain constant (i.e. they don't become narrower as the DIV's padding pushes in on them), so pushing the layout to the right.

I've recreated the issue here: jsfiddle.net/ms3Jd. You can try it in Chrome and Firefox to see the difference.

Any ideas on how to force Chrome to refresh the enclosed paragraphs?

2
  • 2
    Looks like a WebKit bug to me. Commented Jan 19, 2012 at 14:23
  • Could be - but I know there are ways to force (or trick) Chrome to refresh/redraw/recalcuate the page elements, but don't know how to do it. Any ideas? Commented Jan 19, 2012 at 14:32

3 Answers 3

13

I know there are ways to force (or trick) Chrome to refresh/redraw/recalcuate the page elements, but don't know how to do it. Any ideas?

Taken from here: How can I force WebKit to redraw/repaint to propagate style changes?

sel.style.display='none';
sel.offsetHeight; // no need to store this anywhere, the reference is enough
sel.style.display='block';

I quickly applied it here, but you should make it into a function: http://jsfiddle.net/thirtydot/ms3Jd/5/

Sign up to request clarification or add additional context in comments.

2 Comments

A jQuery plugin version: jsfiddle.net/thirtydot/ms3Jd/7. Might be overkill..
It works - thank you (and other answerers) - you are a genius!
3

I'm using fadeTo to force chrome to refresh.
Not sure but I guess it's the animate on fadeTo that does the trick
try that line on jsfiddle.

$('#preview > div').css('padding', ui.value + '%' ).children('p').fadeTo(1, .99).fadeTo(1, 1);

Comments

0

You can add the overflow and float properties:

#preview > div {
    padding: 5%;
    overflow: auto;
    float: left;
}

1 Comment

Hmmm... that is progress, and gets us half way there. Thanks. I tried in in jsfiddle - as we increase the padding, the paragraphs DO recalculate. But if we then decrease the padding again, they don't widen again. Any further refinement you can offer?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.