Page 1 of 1
Problem with controlling the width of a div.
Posted: Sun Nov 02, 2008 11:38 pm
by jlising
Hello,
Do you have a solution how to prevent div width from stretching?
I have an application using divs, but the width of each div stretches when the content is wide enough. I tried to control the width using the statement $(objDiv).setStyle('max-width',screen.width) but it seems not working fine in IE. I tried also controlling the max-width in css and its not working too.
I have this doctype before the HTML tag.
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"
http://www.w3.org/TR/html4/loose.dtd\">";
Please help!
Re: Problem with controlling the width of a div.
Posted: Mon Nov 03, 2008 12:07 am
by bmoyles0117
You're overcomplicating this... Don't use javascript for something as simple as a width.
Or if you'd like to go with styling
Code: Select all
<div style="width : 700px;">Content</div>
Re: Problem with controlling the width of a div.
Posted: Mon Nov 03, 2008 12:10 am
by jlising
Thanks bmoyles0117,
At first, I tried the styling or using the width property instead javascript but it didn't work. That's why i tried different ways.

Re: Problem with controlling the width of a div.
Posted: Mon Nov 03, 2008 12:13 am
by bmoyles0117
Does it work now? If you have the snippet of your source code you can show please do so that I may examine it.
Re: Problem with controlling the width of a div.
Posted: Mon Nov 03, 2008 12:16 am
by jlising
Thanks very much!
I tried the simplest way.
<div id="searchresult" style="overflow-x:auto;overflow-y:auto;width:775px;height:355px;padding-bottom:0px;margin-bottom:0px;"></div>
Then i added this javascript statement in onDomReady event to control the width based from the screen resolution.
$('searchresult').setStyle('width',screen.width);
Re: Problem with controlling the width of a div.
Posted: Mon Nov 03, 2008 12:23 am
by bmoyles0117
jlising wrote:Thanks very much!
I tried the simplest way.
<div id="searchresult" style="overflow-x:auto;overflow-y:auto;width:775px;height:355px;padding-bottom:0px;margin-bottom:0px;"></div>
Then i added this javascript statement in onDomReady event to control the width based from the screen resolution.
$('searchresult').setStyle('width',screen.width);
My friend javascript does not use $ to announce it's variables. So you would do somewhere in your onload function or call
Code: Select all
document.getElementById('searchresult').setStyle({width : }+screen.width+{px;});
That should be correct.
Re: Problem with controlling the width of a div.
Posted: Mon Nov 03, 2008 12:25 am
by jlising
Yes my friend. But i'm using a plug in.
=)
Re: Problem with controlling the width of a div.
Posted: Mon Nov 03, 2008 1:44 am
by bmoyles0117
What's the purpose of overriding such simple commands with simply written plugins. For something so unnecessary just use javascript's core commands
