Problem with controlling the width of a div.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
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.

Post 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!
bmoyles0117
Forum Newbie
Posts: 22
Joined: Sun Nov 02, 2008 1:46 am

Re: Problem with controlling the width of a div.

Post by bmoyles0117 »

You're overcomplicating this... Don't use javascript for something as simple as a width.

Code: Select all

<div width="700">Content</div>
Or if you'd like to go with styling

Code: Select all

<div style="width : 700px;">Content</div>
User avatar
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.

Post 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.
:(
bmoyles0117
Forum Newbie
Posts: 22
Joined: Sun Nov 02, 2008 1:46 am

Re: Problem with controlling the width of a div.

Post 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.
User avatar
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.

Post 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);
bmoyles0117
Forum Newbie
Posts: 22
Joined: Sun Nov 02, 2008 1:46 am

Re: Problem with controlling the width of a div.

Post 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.
User avatar
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.

Post by jlising »

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.

Post 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 :)
Post Reply