Gah! Quick jQuery width help - going nuts.

morkus64

Limp Gawd
Joined
Jan 22, 2006
Messages
143
No clue why I can't get this to work - I've tried a million different ways.

Bascially just want to say for #divID take half of the window width, subtract 600px and make that the width.

If the window is less than 1200px wide, then the div width = 0. (Does that need anything special or will width automatically be 0 if the result of the math is negative?)
 
GOT IT. Anything wrong with this?

$(function(){
$('#searchbarrem').width($(window).width() * .5 - 600);

$(window).resize(function(){
$('#searchbarrem').width($(window).width() * .5 - 600);
});
});
 
That's true, although you add another div wrapper and set the left and right margins to 300px on that. Then set the child width to be 50% which should net you the same result. Its not quite a 100% clean solution though.

Then you can optimize it for smaller screens with media queries. That should get you where you're trying to go.
 
Back
Top