{"id":2012,"date":"2009-11-13T16:26:59","date_gmt":"2009-11-13T15:26:59","guid":{"rendered":"http:\/\/www.bitvolution.com\/?p=307"},"modified":"2016-12-04T09:44:16","modified_gmt":"2016-12-04T09:44:16","slug":"web-design-tutorial-centered-area-with-drop-shadow","status":"publish","type":"post","link":"https:\/\/www.tomfotherby.com\/blog\/index.php\/2009\/11\/web-design-tutorial-centered-area-with-drop-shadow\/","title":{"rendered":"Web Design Tutorial &#8211; Centered area with drop shadow"},"content":{"rendered":"<p>In this tutorial we are going to create a very basic &#8220;blank canvas&#8221; webpage which has a central white cut-out with a drop shadow effect. Our &#8220;page&#8221; will be 960px wide, floated in the center of the browser window:<\/p>\n<div class=\"clearAfter\" style=\"width:570px;margin:0 auto 20px auto\">\n<div class=\"alignleft\" style=\"width:265x;padding:0 5px 0 0;margin:0;border-right:1px dashed black;text-align:center\">\n<h2>Tutorial end product<\/h2>\n<p><a href=\"https:\/\/i0.wp.com\/www.tomfotherby.com\/blog\/wp-content\/uploads\/2009\/11\/aBlankCanvas.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.tomfotherby.com\/blog\/wp-content\/uploads\/2009\/11\/aBlankCanvas1.png?resize=255%2C168&#038;ssl=1\" alt=\"aBlankCanvas\" width=\"255\" height=\"168\" class=\"alignnone size-full wp-image-433\" style=\"margin:0;padding:0;border:0\" \/><br \/>\nClick to enlarge<\/a><\/p>\n<\/div>\n<div class=\"alignleft\" style=\"width:300px;padding:0 0 0 5px;margin:0;text-align:center\">\n<h2>Real-world example<\/h2>\n<p><a href=\"https:\/\/i0.wp.com\/www.tomfotherby.com\/blog\/wp-content\/uploads\/2009\/11\/anonBlankCanvas.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.bitvolution.com\/files\/2009\/11\/anonBlankCanvas-300x168.png?resize=300%2C168\" alt=\"a non-blank Canvas\" width=\"300\" height=\"168\" class=\"alignnone size-medium wp-image-346\" style=\"margin:0;padding:0;border:0\" \/><br \/>\nClick to enlarge<\/a><\/p>\n<\/div>\n<\/div>\n<p><!--more--><\/p>\n<p>The following is a list of steps needed to create the drop-shadow page edge images using the freely available <a href=\"http:\/\/www.gimp.org\/\">GNU Imagine Manipulation Program<\/a> (v2.6.6):<\/p>\n<ol class=\"instructionList\">\n<li>Create a new image: <span class=\"demoCom\">File &gt; New<\/span>. <span class=\"demoSetting\">Image size: 960 x 60, Fill with Transparency<\/span>.<\/li>\n<li>Using the &#8220;Rectangle select tool&#8221; <span class=\"demoCom\">R<\/span>, draw a random rectangle, it doesn&#8217;t matter where you draw it or how big you draw it because once you have a arbitrary selection, specify the following attributes in the Toolbox: <span class=\"demoSetting\">Position: 10, 10. Size: 940, 40 px<\/span>. The result should be a central rectanglar selection with a 10px margin on each side.<\/li>\n<li>Select the &#8220;Bucket fill tool&#8221; <span class=\"demoCom\">Shift+b<\/span>, make sure the current foreground colour is black (<span class=\"demoCom\">d<\/span>) and click inside the selection to create a black rectangle.\n<li>Shrink the selection by a pixel: <span class=\"demoCom\">Select &gt; Shrink<\/span>, <span class=\"demoSetting\">1 pixel<\/span>.<\/li>\n<li>Switch the foreground\/background colours (<span class=\"demoCom\">x<\/span>) so it&#8217;s now white and bucket fill the new selection to create a white rectangle with a black border.\n<li>Add the shadow: <span class=\"demoCom\">Filters &gt; Light and Shadow &gt; Drop Shadow<\/span>. <span class=\"demoSetting\">Offset X: 0, Offset Y: 0, Blur radius 10, Colour: black, Opacity: 50, Allow resizing: unticked<\/span>. The shadow is quite faint so it might be difficult to see until we have a white background.<\/li>\n<li>Add two horizonal guides. <span class=\"demoCom\">Image &gt; Guides &gt; New Guide<\/span>. <span class=\"demoSetting\">Horizontal, Position: 20<\/span> and <span class=\"demoCom\">Image &gt; Guides &gt;New Guide<\/span>. <span class=\"demoSetting\">Horizontal, Position: 40<\/span>.<\/li>\n<li>The guides make is so we can slice the image into three: <span class=\"demoCom\">Image &gt; Transform &gt; Guillotine<\/span>. Three new gimp windows will pop up. Save them as  <em>topShadow.png<\/em>, <em>edgeShadow.png<\/em> and <em>bottomShadow.png<\/em> and we&#8217;re done.<\/li>\n<\/ol>\n<p>Here is the smallest amount of HTML (that I can think of) that uses these drop-shadow images to create a valid webpage:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n    &lt;meta charset=&quot;utf-8&quot;&gt;\r\n    &lt;title&gt;Mockup&lt;\/title&gt;\r\n    &lt;link rel=&quot;stylesheet&quot; href=&quot;http:\/\/yui.yahooapis.com\/2.8.0r4\/build\/reset\/reset-min.css&quot; \/&gt;\r\n    &lt;style&gt;\r\n    .row {width: 960px;margin: 0 auto}\r\n    .topShadow {background: transparent url('topShadow.png') 0 0 no-repeat;padding-top:20px;margin-top:40px}\r\n    .edgeShadow {background: transparent url('edgeShadow.png') 0 0 repeat-y}\r\n    .bottomShadow {background: transparent url('bottomShadow.png') bottom left no-repeat;padding-bottom:20px}\r\n    &lt;\/style&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;div class=&quot;row topShadow&quot;&gt;&lt;\/div&gt;\r\n&lt;div class=&quot;row edgeShadow&quot;&gt;&lt;p style=&quot;height:400px;text-align:center&quot;&gt;Hello world!&lt;\/p&gt;&lt;\/div&gt;\r\n&lt;div class=&quot;row bottomShadow&quot;&gt;&lt;\/div&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>Notes:<\/p>\n<ul>\n<li>Inline CSS is bad &#8211; The only reason I used it was to condense the example into a single file.<\/li>\n<li>I used the Yahoo reset &#8211; amongst other things, it strips all margin and padding from divs.<\/li>\n<li>The page is centered using <span class=\"codeFont\">margin: 0 auto;<\/span> on the row class.<\/li>\n<li>The padding on the <em>topShadow<\/em> and <em>bottomShadow<\/em> divs is the same height as the background drop-shadow images.<\/li>\n<li>The <em>edgeShadow<\/em> div background is repeated vertically so the page can be any height.<\/li>\n<\/ul>\n<p>There&#8217;s a few problems with what we&#8217;ve done so far:<\/p>\n<ul>\n<li>We <a href=\"http:\/\/webdosanddonts.com\/dont-use-empty-html-elements\">shouldn&#8217;t use a empty <span class=\"codeFont\">div<\/span> elements<\/a> for the top and bottom shadows.<\/li>\n<li>The transparency used in the shadow images won&#8217;t work in IE6 because it doesn&#8217;t support 24bit png images. If you want to support IE6, <a href=\"http:\/\/mcapewell.wordpress.com\/2006\/09\/07\/how-to-make-a-transparent-png-image-for-ie-6-in-the-gimp\/\">here is one solution<\/a>.<\/li>\n<li>We use 3 images for the page outline &#8211; we could save two HTTP requests if we could use a single image.<\/li>\n<li>The process we used to build the shadow images didn&#8217;t involve any creativity. The programmer inside me says that if a robot could do a task, a robot should do the task &#8211; I have written <a href=\"http:\/\/www.bitvolution.com\/web-design-tutorial-scripting-gimp\">a script that generates these images automatically<\/a>.<\/li>\n<\/ul>\n<p>Let&#8217;s convert the toy example into something that is actually usable.<\/p>\n<p>The first thing to do is to concatenate the 3 shadow images into a single image, tiled horizontally. e.g.<\/p>\n<p><span class=\"iconTerminal\">montage -mode concatenate topShadow.png edgeShadow.png bottomShadow.png pageShadow_horzSprite.png<\/span><\/p>\n<p>Good info about sprites can be found at <a href=\"http:\/\/www.alistapart.com\/articles\/sprites\/\">alistapart<\/a>. We use the sprite image as follows:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n    &lt;meta charset=&quot;utf-8&quot;&gt;\r\n    &lt;title&gt;Mockup&lt;\/title&gt;\r\n    &lt;link rel=&quot;stylesheet&quot; href=&quot;http:\/\/yui.yahooapis.com\/2.8.0r4\/build\/reset\/reset-min.css&quot; \/&gt;\r\n&lt;style&gt;\r\n&lt;!--\r\n\/* 1KB Grid *\/\r\n.grid_1 { width:60px}\r\n.grid_2 { width:140px}\r\n.grid_3 { width:220px}\r\n.grid_4 { width:300px}\r\n.grid_5 { width:380px}\r\n.grid_6 { width:460px}\r\n.grid_7 { width:540px}\r\n.grid_8 { width:620px}\r\n.grid_9 { width:700px}\r\n.grid_10 { width:780px}\r\n.grid_11 { width:860px}\r\n.grid_12 { width:940px}\r\n.column { margin: 0 10px;overflow: hidden;float: left;display: inline}\r\n.row { width: 960px;margin: 0 auto;overflow: hidden}\r\n.row .row { margin: 0 -10px;width: auto;display: inline-block}\r\n\r\n\/* Theme *\/\r\n\r\nbody {padding-top:40px;}\r\n\r\n.topShadow {\r\n  background: transparent url('pageShadow_horzSprite.png') 0 0 no-repeat;\r\n  padding-top:20px;\r\n}\r\n.edgeShadow {\r\n  background: transparent url('pageShadow_horzSprite.png') -960px 0 repeat-y;\r\n}\r\n.bottomShadow {\r\n  background: transparent url('pageShadow_horzSprite.png') bottom right no-repeat;\r\n  padding-bottom:20px;\r\n}\r\n.topShadow .grid_12, .bottomShadow .grid_12 {\r\n  background: transparent url('pageShadow_horzSprite.png') -960px 0 repeat-y;\r\n  margin:0;\r\n  padding:0 10px;\r\n}\r\n\r\n\/* Base - used just for demo*\/\r\nul li {list-style-type:disc;margin: 0 20px;}\r\nh2 {font-weight:bold;font-size:1.2em;margin:0.5em 0}\r\np {font:40px\/55px Helvetica;text-align: center;border: 1px dashed #000;}\r\n--&gt;\r\n&lt;\/style&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n&lt;div class=&quot;row topShadow&quot;&gt;\r\n    &lt;div class=&quot;column grid_12&quot;&gt;&lt;p&gt;header goes here (12)&lt;\/p&gt;&lt;\/div&gt;\r\n&lt;\/div&gt;\r\n\r\n&lt;div class=&quot;row edgeShadow&quot;&gt;\r\n    &lt;div class=&quot;column grid_8&quot;&gt;&lt;p&gt;8&lt;\/p&gt;\r\n        &lt;div class=&quot;row&quot;&gt;\r\n            &lt;div class=&quot;column grid_4&quot;&gt;&lt;p&gt;4&lt;\/p&gt;&lt;\/div&gt;\r\n            &lt;div class=&quot;column grid_4&quot;&gt;&lt;p&gt;4&lt;\/p&gt;&lt;\/div&gt;\r\n        &lt;\/div&gt;\r\n        &lt;div class=&quot;row&quot;&gt;\r\n            &lt;div class=&quot;column grid_2&quot;&gt;&lt;p&gt;2&lt;\/p&gt;&lt;\/div&gt;\r\n            &lt;div class=&quot;column grid_2&quot;&gt;&lt;p&gt;2&lt;\/p&gt;&lt;\/div&gt;\r\n            &lt;div class=&quot;column grid_2&quot;&gt;&lt;p&gt;2&lt;\/p&gt;&lt;\/div&gt;\r\n            &lt;div class=&quot;column grid_2&quot;&gt;&lt;p&gt;2&lt;\/p&gt;&lt;\/div&gt;\r\n        &lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n    &lt;div class=&quot;column grid_4&quot;&gt;&lt;p style=&quot;line-height: 222px;&quot;&gt;4&lt;\/p&gt;&lt;\/div&gt;\r\n&lt;\/div&gt;\r\n\r\n&lt;div class=&quot;row bottomShadow&quot;&gt;\r\n    &lt;div class=&quot;column grid_12&quot;&gt;&lt;p&gt;footer goes here (12)&lt;\/p&gt;&lt;\/div&gt;\r\n&lt;\/div&gt;\r\n\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>This is what the resulting page looks like:<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/www.tomfotherby.com\/blog\/wp-content\/uploads\/2009\/11\/screenshot_1kbgridWithShadow.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.bitvolution.com\/files\/2009\/11\/screenshot_1kbgridWithShadow-300x120.png?resize=300%2C120\" alt=\"Click to see full size version\" width=\"300\" height=\"120\" class=\"aligncenter size-medium wp-image-494\" \/><\/a><\/p>\n<p>How does it work?<\/p>\n<ul>\n<li><a href=\"http:\/\/www.1kbgrid.com\/\">The 1KB grid<\/a> is used to allow for a flexible layout structure.<\/li>\n<li>A single image (<em>pageShadow_horzSprite.png<\/em>) with varying offsets is used for the page shadow. To tile images vertically we need to use a horizontal sprite and set the horizontal offset. This is how we access the sprite image to get the 3 background page shadows:<\/li>\n<ul>\n<li><code>background: transparent url('pageShadow_horzSprite.png') 0 0 no-repeat;<\/code>\n<li><code>background: transparent url('pageShadow_horzSprite.png') -960px 0 repeat-y;<\/code>\n<li><code>background: transparent url('pageShadow_horzSprite.png') bottom right no-repeat;<\/code>\n<\/ul>\n<\/ul>\n<p>I have done a related post which describes how to <a href=\"web-design-tutorial-scripting-gimp\">automatically generate page shadow images<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial we are going to create a very basic &#8220;blank canvas&#8221; webpage which has a central white cut-out with a drop shadow effect. Our &#8220;page&#8221; will be 960px wide, floated in the center of the browser window: Tutorial end product Click to enlarge Real-world example Click to enlarge<\/p>\n","protected":false},"author":52,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[92],"tags":[85,86,91,84],"class_list":["post-2012","post","type-post","status-publish","format-standard","hentry","category-tutorial","tag-css","tag-html","tag-thegimp","tag-webdesign"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.tomfotherby.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/2012","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tomfotherby.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tomfotherby.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tomfotherby.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/52"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tomfotherby.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=2012"}],"version-history":[{"count":2,"href":"https:\/\/www.tomfotherby.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/2012\/revisions"}],"predecessor-version":[{"id":2045,"href":"https:\/\/www.tomfotherby.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/2012\/revisions\/2045"}],"wp:attachment":[{"href":"https:\/\/www.tomfotherby.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=2012"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tomfotherby.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=2012"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tomfotherby.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=2012"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}