Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Make a Div height always round to an even number… Reply To: Make a Div height always round to an even number…

#197796
Senff
Participant

The most common way of making sure if a div always has a height that is an even number:

1) check current height
2) divide by 2
3) round up the result to the nearest full number
4) multiply by 2
5) apply result to div

For example:

1) height is 151 px
2) half is 75.5
3) rounding up to 76
4) multply by 2 gives 152
5) apply that to div

OR

1) height is 200 px
2) half is 100
3) rounding up to 100
4) multply by 2 gives 200
5) apply that to div

In the second example nothing actually changes, but that’s OK.

So in essence, you might want to have a script/listener that checks the height of the div on load/resize (or every X ms) and applies the height.