From 61ea7f7caee2c656e05d45c17e3248383936b01f Mon Sep 17 00:00:00 2001 From: Mehran Dehghanian Date: Sat, 6 Mar 2021 10:45:15 +0330 Subject: [PATCH] Add 'How to align a DIV horizontally center using CSS' --- ...ign-a-DIV-horizontally-center-using-CSS.md | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 How-to-align-a-DIV-horizontally-center-using-CSS.md diff --git a/How-to-align-a-DIV-horizontally-center-using-CSS.md b/How-to-align-a-DIV-horizontally-center-using-CSS.md new file mode 100644 index 0000000..691c763 --- /dev/null +++ b/How-to-align-a-DIV-horizontally-center-using-CSS.md @@ -0,0 +1,30 @@ +### How to align a DIV horizontally center using CSS + +Use the CSS margin property +If you would like to center align a `
` element horizontally with respect to the parent element you can use the CSS margin property with the value auto for the left and right side, i.e. set the style rule `margin: 0 auto;` for the div element. The auto value automatically adjusts the left and right margin and horizontally center align the div element's block box. + +However, this solution will work only when the width of the parent element is more than the containing div element that you want to align. Let's check out an example: + +``` + + + + +Horizontally Center a Div Using CSS + + + +
+

This is a heading

+

This is a paragraph.

+
+ + +``` \ No newline at end of file