Anders Pedersen
Anders Pedersen

Reputation: 2385

Width/height as auto value forced as percentage?

if i have an element where width and height is sat to auto, can i force it to auto as em / percent in css ?

The reason for this is because pixel decimal values are not respected by the browser and will be rounded up/down.

Upvotes: 0

Views: 56

Answers (2)

BoltClock
BoltClock

Reputation: 723448

Any length value, regardless of its specified unit, will resolve to a used value in pixels. Even if you could change the behavior of auto — which you can't — you'd still end up with a pixel used value.

Rounding inconsistencies are an unfortunate consequence of divergent implementations. There is not much you can do about it.

Upvotes: 3

Bonzai
Bonzai

Reputation: 159

Yes, you can set the width or height of an element to a percentage.

In your CSS it would be:

height: 50%;

Upvotes: -1

Related Questions