From c7d64100a3f4707b677945396b1ca9dca68d3dee Mon Sep 17 00:00:00 2001 From: allenpbiju <33065555+allenpbiju@users.noreply.github.com> Date: Sun, 28 Oct 2018 09:30:19 +0530 Subject: [PATCH] Changes on centering an element using margins. (#20170) Changes has been made on aligning an element to the center by changing the margin values. --- guide/english/css/margins/index.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/guide/english/css/margins/index.md b/guide/english/css/margins/index.md index 59322f97d6..ca74ab1644 100644 --- a/guide/english/css/margins/index.md +++ b/guide/english/css/margins/index.md @@ -42,6 +42,18 @@ The margin property in CSS defines the outermost portion of the box model, creat ## Collapsing margins Vertical margins on different elements that touch each other (thus have no content, padding, or borders separating them) will collapse, forming a single margin that is equal to the greater of the adjoining margins. This does not happen on horizontal margins (left and right), only vertical (top and bottom). +## Centering an element using margin +An element can be aligned to the center by making it a block element and changing the values of the left and right margins to auto. + +```css +.c-pos { + display: block; + margin-left: auto; + margin-right: auto; +} +``` + + ## Browser Support It is effectively supported in all browsers (since IE6+, Firefox 2+, Chrome 1+ etc)