tags:

views:

28

answers:

2

Hi,

I'm stumped on a css problem. I've put up a test page here: http://georgecrawford.com/test/ for you to check.

I have a left-floated sidebar div, and a main content div which follows it (and which should wrap around it). If the content is just paragraphs, there's no problem, as the text wraps nicely around the float. However, I have some blockquotes in the content, and I'd like these to have a background-color and/or a border. The text in these is no problem, it wraps nicely around the sidebar of course. However, the blockquote itself spans the entire width of the content div, which means a border around it would run over the top of the sidebar.

How can I ensure that blockquotes in the content div are shortened horizontally to be the same width as the text lines (the 'line boxes') within them? Paragraphs have the same behaviour, but I don't need a border around my paragraphs!

Thanks for any help!

+1  A: 

The problem is not the blockquote - that just does what it's told, it stretches to 100% of it's parent's width. It's the parent div with the id content that does not have a float property, and thus spans across the floated div.

Can you try putting the sidebar as a child into content, and not as a sibling next to it? I think the blockquote should then adhere to the width rules.

Alternatively, you can always set the blockquote to display: inline, but that may not be what you want, as it then won't stretch to the full width anymore.

Pekka
Hi, thanks for answering.FYI, putting sidebar as a child of content changes nothing I'm afraid.
George Crawford
+1  A: 

I've stumbled upon a potential fix for this problem.

If I set all blockquotes with the CSS property overflow: auto, it makes them reduce to the desired width when they'd otherwise overlap the floated sidebar. I've updated the demo at http://georgecrawford.com/test/ so you can see the difference. It's perfect in Safari/OS X, but I haven't yet tested in other browsers.

Any comments? Does this solution have any drawbacks? Many thanks again for your help.

George Crawford
Interesting fix. Works for me in Firefox 3.5, IE 7 and 8 on Windows 7. Doesn't work on IE5.5 and IE6. You could try a `display: inline` based workaround and target it at IE6 using a CSS hack. It won't look perfect but at least it will be readable and not broken. One could argue that while IE6 is still important enough to justify fixing pages that are right-out broken in it, it's not worth the effort making things look 100% the same as in modern browsers.
Pekka