Morpheus
Morpheus

Reputation: 3

Changing the width of HTML div element automatically using jQuery

I have 4 div elements on the same line, each set at 25% width to fit the screen. When I click on a div it should disappear, which I have achieved using jQuery. Then, I manually set the width of each of the divs to 33%.

I can keep on doing this manually for more clicks, but is there a way the divs automatically resize them selves like this using jQuery and even continue when 2 divs are on screen so each would should be 50%?

Upvotes: 0

Views: 124

Answers (2)

Piotrek
Piotrek

Reputation: 11211

Creating tables will solve this problem. Table columns will automatically resize when you delete one of them. You can easly make div's behave like table.

http://snook.ca/archives/html_and_css/getting_your_di

Upvotes: 1

Abdul Jabbar
Abdul Jabbar

Reputation: 2573

In that case, you don't need to specify fix width e.g 25, 33.. just set it to auto:

width: auto

That should do the trick for as far as i could understand your question. If that didn't help, you should include your css and html code in the question.

Upvotes: 0

Related Questions