{"id":7557,"date":"2021-04-07T19:33:50","date_gmt":"2021-04-07T16:33:50","guid":{"rendered":"https:\/\/elzero.org\/?p=7557"},"modified":"2023-10-01T21:27:35","modified_gmt":"2023-10-01T18:27:35","slug":"tutorials-centering-elements-horizontally-and-vertically","status":"publish","type":"post","link":"https:\/\/elzero.org\/old\/tutorials-centering-elements-horizontally-and-vertically\/","title":{"rendered":"Centering Elements Horizontally And Vertically"},"content":{"rendered":"<h3>\u0627\u0644 Code<\/h3>\r\n\r\n<script type=\"text\/plain\" class=\"language-html\">\r\n<div class=\"box\">\r\n  <div class=\"item\"><\/div>\r\n<\/div>\r\n<\/script>\r\n\r\n<script type=\"text\/plain\" class=\"language-css\">\r\n* {\r\n  box-sizing: border-box;\r\n  padding: 0;\r\n  margin: 0;\r\n}\r\nbody {\r\n  font-family: Arial, Tahoma;\r\n}\r\n\r\n\/* For Demo Only *\/\r\n.box {\r\n  background-color: #eee;\r\n  margin: 40px auto;\r\n  width: 800px;\r\n  height: 300px;\r\n  position: relative;\r\n}\r\n.box:before {\r\n  width: 4px;\r\n  height: 100%;\r\n  left: 50%;\r\n  margin-left: -2px;\r\n}\r\n.box:after {\r\n  height: 4px;\r\n  width: 100%;\r\n  top: 50%;\r\n  margin-top: -2px;\r\n}\r\n.box:before,\r\n.box:after {\r\n  content: \"\";\r\n  background-color: #ddd;\r\n  position: absolute;\r\n}\r\n.box .item {\r\n  background-color: #f00;\r\n  width: 200px;\r\n  height: 100px;\r\n}\r\n\/* For Demo Only *\/\r\n\r\n\/* Margin + Position *\/\r\n.box .item { \r\n  position: absolute;\r\n  left: 50%;\r\n  margin-left: -100px;\r\n  margin-top: -50px;\r\n  top: 50%;\r\n  z-index: 2;\r\n}\r\n\r\n\/* Position + Transform *\/\r\n.box .item {\r\n  position: absolute;\r\n  left: 50%;\r\n  top: 50%;\r\n  transform: translate(-50%, -50%);\r\n  z-index: 2;\r\n}\r\n\r\n\/* Flex *\/\r\n.box {\r\n  display: flex;\r\n  justify-content: center;\r\n  align-items: center;\r\n}\r\n\r\n<\/script>","protected":false},"excerpt":{"rendered":"<p>\u0627\u0644 Code<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[879],"tags":[],"class_list":["post-7557","post","type-post","status-publish","format-standard","hentry","category-front-end-tutorials"],"_links":{"self":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/7557","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/comments?post=7557"}],"version-history":[{"count":2,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/7557\/revisions"}],"predecessor-version":[{"id":13787,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/7557\/revisions\/13787"}],"wp:attachment":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/media?parent=7557"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/categories?post=7557"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/tags?post=7557"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}