Problem with controlling the width of a div.
Moderator: General Moderators
- jlising
- Forum Commoner
- Posts: 33
- Joined: Mon Mar 19, 2007 1:48 am
- Location: Pampanga, Philippines
- Contact:
Problem with controlling the width of a div.
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!
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!
-
bmoyles0117
- Forum Newbie
- Posts: 22
- Joined: Sun Nov 02, 2008 1:46 am
Re: Problem with controlling the width of a div.
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 width="700">Content</div>Code: Select all
<div style="width : 700px;">Content</div>- jlising
- Forum Commoner
- Posts: 33
- Joined: Mon Mar 19, 2007 1:48 am
- Location: Pampanga, Philippines
- Contact:
Re: Problem with controlling the width of a div.
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.

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.
-
bmoyles0117
- Forum Newbie
- Posts: 22
- Joined: Sun Nov 02, 2008 1:46 am
Re: Problem with controlling the width of a div.
Does it work now? If you have the snippet of your source code you can show please do so that I may examine it.
- jlising
- Forum Commoner
- Posts: 33
- Joined: Mon Mar 19, 2007 1:48 am
- Location: Pampanga, Philippines
- Contact:
Re: Problem with controlling the width of a div.
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);
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);
-
bmoyles0117
- Forum Newbie
- Posts: 22
- Joined: Sun Nov 02, 2008 1:46 am
Re: Problem with controlling the width of a div.
My friend javascript does not use $ to announce it's variables. So you would do somewhere in your onload function or calljlising 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);
Code: Select all
document.getElementById('searchresult').setStyle({width : }+screen.width+{px;});- jlising
- Forum Commoner
- Posts: 33
- Joined: Mon Mar 19, 2007 1:48 am
- Location: Pampanga, Philippines
- Contact:
Re: Problem with controlling the width of a div.
Yes my friend. But i'm using a plug in.
=)
=)
-
bmoyles0117
- Forum Newbie
- Posts: 22
- Joined: Sun Nov 02, 2008 1:46 am
Re: Problem with controlling the width of a div.
What's the purpose of overriding such simple commands with simply written plugins. For something so unnecessary just use javascript's core commands 