Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of `auto` value in a CSS property.

Tags:

css

What is the meaning of auto value of a CSS property. What happens when value of a CSS property is set to auto?

like image 631
sushil bharwani Avatar asked Dec 17 '10 15:12

sushil bharwani


People also ask

What is the Auto Value in CSS?

The auto ValueYou can set the margin property to auto to horizontally center the element within its container. The element will then take up the specified width, and the remaining space will be split equally between the left and right margins.

What does width auto do in CSS?

Width: auto When an element has auto as a value for width, it can have margin, padding, and border without becoming bigger than its parent element. The width of its content box will be the content itself with the subtraction of margin, padding, and border.

What is height auto CSS?

If height: auto; the element will automatically adjust its height to allow its content to be displayed correctly. If height is set to a numeric value (like pixels, (r)em, percentages) then if the content does not fit within the specified height, it will overflow.


1 Answers

The value of said property is adjusted automatically according to the content or the context of the element.

For example, a block-level element with height: auto will grow taller as it contains more text. For another example, a block element with margin: 0 auto will have the left and right margins increased until it becomes centered along the y-axis of the viewport.

It really depends on the property you give the value to, different properties behave differently depending on the content and context.

like image 66
BoltClock Avatar answered Sep 22 '22 05:09

BoltClock