{"id":302,"date":"2011-05-25T00:06:30","date_gmt":"2011-05-25T10:06:30","guid":{"rendered":"http:\/\/mymonkeydo.com\/?p=302"},"modified":"2020-05-03T16:34:59","modified_gmt":"2020-05-04T02:34:59","slug":"centering-wo-absolute","status":"publish","type":"post","link":"https:\/\/mymonkeydo.com\/centering-wo-absolute\/","title":{"rendered":"Centering w\/o Absolute"},"content":{"rendered":"

Problem:<\/strong><\/p>\n

I needed to add some jquery popups to my code, but the popup appeared at the very top outside the viewing area. \u00a0The popup uses absolute positioning and so it is relative to the nearest element with a “position” attribute<\/a>. \u00a0Since I centered my page with the following code, I didn’t have a nearest element with a “position” attribute so the popup was relative to the document. \u00a0And the document was just a sliver at the top because the elements within it were positioned absolutely… \u00a0here’s I mean:<\/p>\n

\"\"<\/a>
The yellow highlight is the body tag.<\/figcaption><\/figure>\n

Using Firebug, you can see, the yellow highlighted area is the width\/height of my body element (it’s actually the margin and the width\/height is zero). \u00a0So the popup appeared in that area instead of the entire page.<\/p>\n

 <\/p>\n

Solution:<\/h2>\n

The quick solution would be to change this \u00a0code:<\/p>\n

#Table_01 {\n    position:absolute;\n    left:50%;\n    top:0px;\n    height:auto;\n    margin-left:-500px;\n    width:1025px;\n    background-image:url(..\/images\/expand.png);\n    background-position:top;\n    background-repeat:repeat-y;\n}<\/pre>\n

To the following code. \u00a0The following code doesn’t use absolute, instead it uses display: table and margin: 0px auto;<\/p>\n

#Table_01 {\n    display: table;\n    margin: 0px auto;\n    width:1025px;\n    background-image:url(..\/images\/expand.png);\n    background-position:top;\n    background-repeat:repeat-y;\n}<\/pre>\n

And of course, we need some special code for our special browser Internet Explorer:<\/p>\n

\n        \nbody { text-align: center; }\nbody * { text-align: left; }\n#Table_01 {\n    zoom: 1;\n\tdisplay: inline;\n}\n\n<\/pre>\n

 <\/p>\n

Table_01 <\/strong>is the first element inside of the Body <\/strong>tag. \u00a0For a full explanation head on to where i found the solution. \u00a0Also do not forget the Doc Type<\/a> for IE to work propery.<\/p>\n

 <\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[2],"tags":[17,34],"yoast_head":"\nCentering w\/o Absolute - My Monkey Do<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/mymonkeydo.com\/centering-wo-absolute\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Centering w\/o Absolute - My Monkey Do\" \/>\n<meta property=\"og:url\" content=\"https:\/\/mymonkeydo.com\/centering-wo-absolute\/\" \/>\n<meta property=\"og:site_name\" content=\"My Monkey Do\" \/>\n<meta property=\"article:published_time\" content=\"2011-05-25T10:06:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-05-04T02:34:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/mymonkeydo.com\/wp-content\/uploads\/2011\/05\/css-1024x285.jpg\" \/>\n<meta name=\"author\" content=\"Webhead\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Webhead\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/mymonkeydo.com\/centering-wo-absolute\/\",\"url\":\"https:\/\/mymonkeydo.com\/centering-wo-absolute\/\",\"name\":\"Centering w\/o Absolute - My Monkey Do\",\"isPartOf\":{\"@id\":\"https:\/\/mymonkeydo.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/mymonkeydo.com\/centering-wo-absolute\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/mymonkeydo.com\/centering-wo-absolute\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/mymonkeydo.com\/wp-content\/uploads\/2011\/05\/css-1024x285.jpg\",\"datePublished\":\"2011-05-25T10:06:30+00:00\",\"dateModified\":\"2020-05-04T02:34:59+00:00\",\"author\":{\"@id\":\"https:\/\/mymonkeydo.com\/#\/schema\/person\/b16fc650a8c182faaac896bab099b829\"},\"breadcrumb\":{\"@id\":\"https:\/\/mymonkeydo.com\/centering-wo-absolute\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/mymonkeydo.com\/centering-wo-absolute\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/mymonkeydo.com\/centering-wo-absolute\/#primaryimage\",\"url\":\"https:\/\/mymonkeydo.com\/wp-content\/uploads\/2011\/05\/css.jpg\",\"contentUrl\":\"https:\/\/mymonkeydo.com\/wp-content\/uploads\/2011\/05\/css.jpg\",\"width\":1109,\"height\":309,\"caption\":\"The yellow highlight is the body tag.\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/mymonkeydo.com\/centering-wo-absolute\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/mymonkeydo.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Centering w\/o Absolute\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/mymonkeydo.com\/#website\",\"url\":\"https:\/\/mymonkeydo.com\/\",\"name\":\"My Monkey Do\",\"description\":\"A Log of Coding Solutions\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/mymonkeydo.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/mymonkeydo.com\/#\/schema\/person\/b16fc650a8c182faaac896bab099b829\",\"name\":\"Webhead\",\"url\":\"https:\/\/mymonkeydo.com\/author\/corey\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Centering w\/o Absolute - My Monkey Do","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/mymonkeydo.com\/centering-wo-absolute\/","og_locale":"en_US","og_type":"article","og_title":"Centering w\/o Absolute - My Monkey Do","og_url":"https:\/\/mymonkeydo.com\/centering-wo-absolute\/","og_site_name":"My Monkey Do","article_published_time":"2011-05-25T10:06:30+00:00","article_modified_time":"2020-05-04T02:34:59+00:00","og_image":[{"url":"https:\/\/mymonkeydo.com\/wp-content\/uploads\/2011\/05\/css-1024x285.jpg"}],"author":"Webhead","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Webhead","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/mymonkeydo.com\/centering-wo-absolute\/","url":"https:\/\/mymonkeydo.com\/centering-wo-absolute\/","name":"Centering w\/o Absolute - My Monkey Do","isPartOf":{"@id":"https:\/\/mymonkeydo.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/mymonkeydo.com\/centering-wo-absolute\/#primaryimage"},"image":{"@id":"https:\/\/mymonkeydo.com\/centering-wo-absolute\/#primaryimage"},"thumbnailUrl":"https:\/\/mymonkeydo.com\/wp-content\/uploads\/2011\/05\/css-1024x285.jpg","datePublished":"2011-05-25T10:06:30+00:00","dateModified":"2020-05-04T02:34:59+00:00","author":{"@id":"https:\/\/mymonkeydo.com\/#\/schema\/person\/b16fc650a8c182faaac896bab099b829"},"breadcrumb":{"@id":"https:\/\/mymonkeydo.com\/centering-wo-absolute\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/mymonkeydo.com\/centering-wo-absolute\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/mymonkeydo.com\/centering-wo-absolute\/#primaryimage","url":"https:\/\/mymonkeydo.com\/wp-content\/uploads\/2011\/05\/css.jpg","contentUrl":"https:\/\/mymonkeydo.com\/wp-content\/uploads\/2011\/05\/css.jpg","width":1109,"height":309,"caption":"The yellow highlight is the body tag."},{"@type":"BreadcrumbList","@id":"https:\/\/mymonkeydo.com\/centering-wo-absolute\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/mymonkeydo.com\/"},{"@type":"ListItem","position":2,"name":"Centering w\/o Absolute"}]},{"@type":"WebSite","@id":"https:\/\/mymonkeydo.com\/#website","url":"https:\/\/mymonkeydo.com\/","name":"My Monkey Do","description":"A Log of Coding Solutions","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/mymonkeydo.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/mymonkeydo.com\/#\/schema\/person\/b16fc650a8c182faaac896bab099b829","name":"Webhead","url":"https:\/\/mymonkeydo.com\/author\/corey\/"}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/mymonkeydo.com\/wp-json\/wp\/v2\/posts\/302"}],"collection":[{"href":"https:\/\/mymonkeydo.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mymonkeydo.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mymonkeydo.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mymonkeydo.com\/wp-json\/wp\/v2\/comments?post=302"}],"version-history":[{"count":0,"href":"https:\/\/mymonkeydo.com\/wp-json\/wp\/v2\/posts\/302\/revisions"}],"wp:attachment":[{"href":"https:\/\/mymonkeydo.com\/wp-json\/wp\/v2\/media?parent=302"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mymonkeydo.com\/wp-json\/wp\/v2\/categories?post=302"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mymonkeydo.com\/wp-json\/wp\/v2\/tags?post=302"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}