{"id":74,"date":"2015-09-07T05:24:11","date_gmt":"2015-09-07T05:24:11","guid":{"rendered":"http:\/\/roguedzines.com\/blog\/?p=74"},"modified":"2015-09-07T05:24:11","modified_gmt":"2015-09-07T05:24:11","slug":"trouble-centering-your-layout","status":"publish","type":"post","link":"http:\/\/thischickcodes.com\/index.php\/2015\/09\/07\/trouble-centering-your-layout\/","title":{"rendered":"Trouble centering your layout?"},"content":{"rendered":"<p>I have come across a number of websites and have helped a few people with this problem with not being able to center their layout &#8211; the<em> correct<\/em> way.<\/p>\n<p>First things first you should be using a reset CSS such as <a href=\"http:\/\/meyerweb.com\/eric\/tools\/css\/reset\/\" target=\"_blank\">Eric Meyer&#8217;s<\/a>, this will get rid of unnecessary margins, padding etc that are default.<\/p>\n<p>I like to create a div that everything gets &#8220;wrapped&#8221; in, for this we will use the ID wrapper. (remember you can only use ID&#8217;s once &#8211; class names can be used more than once).<br \/>\nDo not set a width to this and by default <strong>DIV&#8217;s are blocks and width is automatically 100%<\/strong>. Our #main-container will have a set width, <strong>margin 0 auto will center<\/strong> it.<\/p>\n<p>For this tutorial I added a border to show that the container is centered. Then finally a class name main-content which has a padding of 20px so it&#8217;s not touching the edge.<\/p>\n<p>That&#8217;s how you center a layout, leave a comment if you have any questions.<\/p>\n<p>CSS<\/p>\n<pre><code class=\"css\">#wrapper{\nbackground: #2A7D58;\n}\n\n#main-container{\nwidth:960px;\nmargin: 0 auto;\ncolor: #fff;\nborder:1px solid #fff;\n}\n.main-content{\npadding:20px;\n}\n<\/code>\n<\/pre>\n<p>HTML<\/p>\n<pre><code class=\"html\">&lt;div id=\"wrapper\"&gt;\n  &lt;div id=\"main-container\"&gt;\n    &lt;div class=\"main-content\"&gt;\n      &lt;p&gt;This is a centered layout!&lt;\/p&gt;\n    &lt;\/div&gt;\n  &lt;\/div&gt;\n&lt;\/div&gt;\n<\/code><\/pre>\n<p><a href=\"http:\/\/roguedzines.com\/demos\/centering\/\" target=\"_blank\">DEMO<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have come across a number of websites and have helped a few people with this problem with not being able to center their layout &#8211; the correct way. First things first you should be using a reset CSS such as Eric Meyer&#8217;s, this will get rid of unnecessary margins, padding etc that are default. [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[15,16,21],"_links":{"self":[{"href":"http:\/\/thischickcodes.com\/index.php\/wp-json\/wp\/v2\/posts\/74"}],"collection":[{"href":"http:\/\/thischickcodes.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/thischickcodes.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/thischickcodes.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/thischickcodes.com\/index.php\/wp-json\/wp\/v2\/comments?post=74"}],"version-history":[{"count":0,"href":"http:\/\/thischickcodes.com\/index.php\/wp-json\/wp\/v2\/posts\/74\/revisions"}],"wp:attachment":[{"href":"http:\/\/thischickcodes.com\/index.php\/wp-json\/wp\/v2\/media?parent=74"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/thischickcodes.com\/index.php\/wp-json\/wp\/v2\/categories?post=74"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/thischickcodes.com\/index.php\/wp-json\/wp\/v2\/tags?post=74"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}