{"id":1753,"date":"2015-01-15T17:33:42","date_gmt":"2015-01-15T16:33:42","guid":{"rendered":"http:\/\/denbeke.be\/blog\/?p=1753"},"modified":"2015-01-15T08:34:28","modified_gmt":"2015-01-15T07:34:28","slug":"css-semi-transparent-border-on-images","status":"publish","type":"post","link":"https:\/\/denbeke.be\/blog\/webdevelopment\/css-semi-transparent-border-on-images\/","title":{"rendered":"CSS: semi-transparent border on images"},"content":{"rendered":"<p>When you display images on a white background (but also on other colors)\u00a0you&#8217;d want to add a border to the image. But adding a &#8216;normal&#8217; CSS border doesn&#8217;t always look very well.<\/p>\n<p>The solution: semi-transparant borders that are not positioned <strong>around<\/strong>, but <strong>on<\/strong> the images. This subtle design element will make your galleries look way better. (Facebook, Flickr, Google, &#8230; they all use it)<\/p>\n<figure id=\"attachment_1754\" aria-describedby=\"caption-attachment-1754\" style=\"width: 744px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/denbeke.be\/blog\/webdevelopment\/css-semi-transparent-border-on-images\/attachment\/no-border\/\" rel=\"attachment wp-att-1754\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1754 size-full\" src=\"http:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/01\/no-border.png\" alt=\"no border\" width=\"744\" height=\"265\" srcset=\"https:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/01\/no-border.png 744w, https:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/01\/no-border-300x106.png 300w\" sizes=\"auto, (max-width: 744px) 100vw, 744px\" \/><\/a><figcaption id=\"caption-attachment-1754\" class=\"wp-caption-text\">No border around\/on the images<\/figcaption><\/figure>\n<figure id=\"attachment_1755\" aria-describedby=\"caption-attachment-1755\" style=\"width: 743px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/denbeke.be\/blog\/webdevelopment\/css-semi-transparent-border-on-images\/attachment\/semi-transparent-border-on-images\/\" rel=\"attachment wp-att-1755\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1755 size-full\" src=\"http:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/01\/semi-transparent-border-on-images.png\" alt=\"semi-transparent border on images\" width=\"743\" height=\"263\" srcset=\"https:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/01\/semi-transparent-border-on-images.png 743w, https:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/01\/semi-transparent-border-on-images-300x106.png 300w\" sizes=\"auto, (max-width: 743px) 100vw, 743px\" \/><\/a><figcaption id=\"caption-attachment-1755\" class=\"wp-caption-text\">Semi-transparent border on images<\/figcaption><\/figure>\n<p>Adding this borders can be done very easily using CSS.<\/p>\n<h3>Technique 1: outline<\/h3>\n<p>A first solution is using the <code>outline<\/code> and <code>outline-offset<\/code> property in CSS:<\/p>\n<pre><code>img.image {\r\n    outline: 1px solid rgba(0, 0, 0, 0.1);\r\n    outline-offset: -1px;\r\n}<\/code><\/pre>\n<p>This is very easy and works perfectly in a lot of browsers, but sadly it isn&#8217;t supported in Internet Explorer 9 &amp; 10, which have together a market share of over 15% (on the desktop).<\/p>\n<h3>Technique 2: psuedo element<\/h3>\n<p>Using the <code>:after<\/code> pseudo element has much better browser support. All modern browsers support it.<\/p>\n<pre><code>div.image-container:after {\r\n    border: 1px solid rgba(0, 0, 0, 0.1);\r\n    content: '';\r\n\r\n    position: absolute;\r\n    top: 0;\r\n    right: 0;\r\n    bottom: 0;\r\n    left: 0;\r\n}<\/code><\/pre>\n<p>The \u00a0above CSS code will use a pseudo element to position the border right on top\u00a0the image.<\/p>\n<p>Even though working with the pseudo element is better supported, it can be a bit harder to get it working. People often tend to forget how CSS really works. So mind that the parent div should have <code>position:\u00a0relative<\/code> and that\u00a0<code>:after<\/code> doesn&#8217;t work on <code>img<\/code> elements. (Look it up, because explaining all this would lead us way too far from the original topic.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When you display images on a white background (but also on other colors)\u00a0you&#8217;d want to add a border to the image. But adding a &#8216;normal&#8217; CSS border doesn&#8217;t always look very well. The solution: semi-transparant borders that are not positioned around, but on the images. This subtle design element will make your galleries look way [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[112],"tags":[58,244],"class_list":["post-1753","post","type-post","status-publish","format-standard","hentry","category-webdevelopment","tag-css","tag-webdesign","entry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>CSS: semi-transparent border on images &#8211; DenBeke<\/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:\/\/denbeke.be\/blog\/webdevelopment\/css-semi-transparent-border-on-images\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"CSS: semi-transparent border on images &#8211; DenBeke\" \/>\n<meta property=\"og:description\" content=\"When you display images on a white background (but also on other colors)\u00a0you&#8217;d want to add a border to the image. But adding a &#8216;normal&#8217; CSS border doesn&#8217;t always look very well. The solution: semi-transparant borders that are not positioned around, but on the images. This subtle design element will make your galleries look way [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/denbeke.be\/blog\/webdevelopment\/css-semi-transparent-border-on-images\/\" \/>\n<meta property=\"og:site_name\" content=\"DenBeke\" \/>\n<meta property=\"article:published_time\" content=\"2015-01-15T16:33:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/01\/no-border.png\" \/>\n\t<meta property=\"og:image:width\" content=\"744\" \/>\n\t<meta property=\"og:image:height\" content=\"265\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Mathias Beke\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@MthsBk\" \/>\n<meta name=\"twitter:site\" content=\"@MthsBk\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mathias Beke\" \/>\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\":\"Article\",\"@id\":\"https:\\\/\\\/denbeke.be\\\/blog\\\/webdevelopment\\\/css-semi-transparent-border-on-images\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/denbeke.be\\\/blog\\\/webdevelopment\\\/css-semi-transparent-border-on-images\\\/\"},\"author\":{\"name\":\"Mathias Beke\",\"@id\":\"https:\\\/\\\/denbeke.be\\\/blog\\\/#\\\/schema\\\/person\\\/386878f712fe3fe22227216f087772dc\"},\"headline\":\"CSS: semi-transparent border on images\",\"datePublished\":\"2015-01-15T16:33:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/denbeke.be\\\/blog\\\/webdevelopment\\\/css-semi-transparent-border-on-images\\\/\"},\"wordCount\":246,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/denbeke.be\\\/blog\\\/webdevelopment\\\/css-semi-transparent-border-on-images\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/denbeke.be\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/01\\\/no-border.png\",\"keywords\":[\"css\",\"webdesign\"],\"articleSection\":[\"Webdevelopment\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/denbeke.be\\\/blog\\\/webdevelopment\\\/css-semi-transparent-border-on-images\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/denbeke.be\\\/blog\\\/webdevelopment\\\/css-semi-transparent-border-on-images\\\/\",\"url\":\"https:\\\/\\\/denbeke.be\\\/blog\\\/webdevelopment\\\/css-semi-transparent-border-on-images\\\/\",\"name\":\"CSS: semi-transparent border on images &#8211; DenBeke\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/denbeke.be\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/denbeke.be\\\/blog\\\/webdevelopment\\\/css-semi-transparent-border-on-images\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/denbeke.be\\\/blog\\\/webdevelopment\\\/css-semi-transparent-border-on-images\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/denbeke.be\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/01\\\/no-border.png\",\"datePublished\":\"2015-01-15T16:33:42+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/denbeke.be\\\/blog\\\/#\\\/schema\\\/person\\\/386878f712fe3fe22227216f087772dc\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/denbeke.be\\\/blog\\\/webdevelopment\\\/css-semi-transparent-border-on-images\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/denbeke.be\\\/blog\\\/webdevelopment\\\/css-semi-transparent-border-on-images\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/denbeke.be\\\/blog\\\/webdevelopment\\\/css-semi-transparent-border-on-images\\\/#primaryimage\",\"url\":\"https:\\\/\\\/denbeke.be\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/01\\\/no-border.png\",\"contentUrl\":\"https:\\\/\\\/denbeke.be\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/01\\\/no-border.png\",\"width\":744,\"height\":265},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/denbeke.be\\\/blog\\\/webdevelopment\\\/css-semi-transparent-border-on-images\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/denbeke.be\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"CSS: semi-transparent border on images\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/denbeke.be\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/denbeke.be\\\/blog\\\/\",\"name\":\"DenBeke\",\"description\":\"Mathias Beke\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/denbeke.be\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/denbeke.be\\\/blog\\\/#\\\/schema\\\/person\\\/386878f712fe3fe22227216f087772dc\",\"name\":\"Mathias Beke\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8889cf00cef9570a8f82e7510ed97205ccb7a1a0d2c7e0968a07e1885386f198?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8889cf00cef9570a8f82e7510ed97205ccb7a1a0d2c7e0968a07e1885386f198?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8889cf00cef9570a8f82e7510ed97205ccb7a1a0d2c7e0968a07e1885386f198?s=96&d=mm&r=g\",\"caption\":\"Mathias Beke\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"CSS: semi-transparent border on images &#8211; DenBeke","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:\/\/denbeke.be\/blog\/webdevelopment\/css-semi-transparent-border-on-images\/","og_locale":"en_US","og_type":"article","og_title":"CSS: semi-transparent border on images &#8211; DenBeke","og_description":"When you display images on a white background (but also on other colors)\u00a0you&#8217;d want to add a border to the image. But adding a &#8216;normal&#8217; CSS border doesn&#8217;t always look very well. The solution: semi-transparant borders that are not positioned around, but on the images. This subtle design element will make your galleries look way [&hellip;]","og_url":"https:\/\/denbeke.be\/blog\/webdevelopment\/css-semi-transparent-border-on-images\/","og_site_name":"DenBeke","article_published_time":"2015-01-15T16:33:42+00:00","og_image":[{"width":744,"height":265,"url":"https:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/01\/no-border.png","type":"image\/png"}],"author":"Mathias Beke","twitter_card":"summary_large_image","twitter_creator":"@MthsBk","twitter_site":"@MthsBk","twitter_misc":{"Written by":"Mathias Beke","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/denbeke.be\/blog\/webdevelopment\/css-semi-transparent-border-on-images\/#article","isPartOf":{"@id":"https:\/\/denbeke.be\/blog\/webdevelopment\/css-semi-transparent-border-on-images\/"},"author":{"name":"Mathias Beke","@id":"https:\/\/denbeke.be\/blog\/#\/schema\/person\/386878f712fe3fe22227216f087772dc"},"headline":"CSS: semi-transparent border on images","datePublished":"2015-01-15T16:33:42+00:00","mainEntityOfPage":{"@id":"https:\/\/denbeke.be\/blog\/webdevelopment\/css-semi-transparent-border-on-images\/"},"wordCount":246,"commentCount":0,"image":{"@id":"https:\/\/denbeke.be\/blog\/webdevelopment\/css-semi-transparent-border-on-images\/#primaryimage"},"thumbnailUrl":"http:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/01\/no-border.png","keywords":["css","webdesign"],"articleSection":["Webdevelopment"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/denbeke.be\/blog\/webdevelopment\/css-semi-transparent-border-on-images\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/denbeke.be\/blog\/webdevelopment\/css-semi-transparent-border-on-images\/","url":"https:\/\/denbeke.be\/blog\/webdevelopment\/css-semi-transparent-border-on-images\/","name":"CSS: semi-transparent border on images &#8211; DenBeke","isPartOf":{"@id":"https:\/\/denbeke.be\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/denbeke.be\/blog\/webdevelopment\/css-semi-transparent-border-on-images\/#primaryimage"},"image":{"@id":"https:\/\/denbeke.be\/blog\/webdevelopment\/css-semi-transparent-border-on-images\/#primaryimage"},"thumbnailUrl":"http:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/01\/no-border.png","datePublished":"2015-01-15T16:33:42+00:00","author":{"@id":"https:\/\/denbeke.be\/blog\/#\/schema\/person\/386878f712fe3fe22227216f087772dc"},"breadcrumb":{"@id":"https:\/\/denbeke.be\/blog\/webdevelopment\/css-semi-transparent-border-on-images\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/denbeke.be\/blog\/webdevelopment\/css-semi-transparent-border-on-images\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/denbeke.be\/blog\/webdevelopment\/css-semi-transparent-border-on-images\/#primaryimage","url":"https:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/01\/no-border.png","contentUrl":"https:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/01\/no-border.png","width":744,"height":265},{"@type":"BreadcrumbList","@id":"https:\/\/denbeke.be\/blog\/webdevelopment\/css-semi-transparent-border-on-images\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/denbeke.be\/blog\/"},{"@type":"ListItem","position":2,"name":"CSS: semi-transparent border on images"}]},{"@type":"WebSite","@id":"https:\/\/denbeke.be\/blog\/#website","url":"https:\/\/denbeke.be\/blog\/","name":"DenBeke","description":"Mathias Beke","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/denbeke.be\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/denbeke.be\/blog\/#\/schema\/person\/386878f712fe3fe22227216f087772dc","name":"Mathias Beke","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/8889cf00cef9570a8f82e7510ed97205ccb7a1a0d2c7e0968a07e1885386f198?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/8889cf00cef9570a8f82e7510ed97205ccb7a1a0d2c7e0968a07e1885386f198?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8889cf00cef9570a8f82e7510ed97205ccb7a1a0d2c7e0968a07e1885386f198?s=96&d=mm&r=g","caption":"Mathias Beke"}}]}},"_links":{"self":[{"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/posts\/1753","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/comments?post=1753"}],"version-history":[{"count":8,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/posts\/1753\/revisions"}],"predecessor-version":[{"id":1763,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/posts\/1753\/revisions\/1763"}],"wp:attachment":[{"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/media?parent=1753"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/categories?post=1753"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/tags?post=1753"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}