{"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\" 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=\"(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\" 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=\"(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":[],"categories":[112],"tags":[58,244],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v15.6.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>CSS: semi-transparent border on images &ndash; 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 &ndash; 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=\"article:modified_time\" content=\"2015-01-15T07:34:28+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/01\/no-border.png\" \/>\n<meta name=\"twitter:card\" content=\"summary\" \/>\n<meta name=\"twitter:creator\" content=\"@MthsBk\" \/>\n<meta name=\"twitter:site\" content=\"@MthsBk\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\">\n\t<meta name=\"twitter:data1\" content=\"1 minute\">\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/denbeke.be\/blog\/#website\",\"url\":\"https:\/\/denbeke.be\/blog\/\",\"name\":\"DenBeke\",\"description\":\"Mathias Beke\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/denbeke.be\/blog\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/denbeke.be\/blog\/webdevelopment\/css-semi-transparent-border-on-images\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"http:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/01\/no-border.png\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/denbeke.be\/blog\/webdevelopment\/css-semi-transparent-border-on-images\/#webpage\",\"url\":\"https:\/\/denbeke.be\/blog\/webdevelopment\/css-semi-transparent-border-on-images\/\",\"name\":\"CSS: semi-transparent border on images &ndash; DenBeke\",\"isPartOf\":{\"@id\":\"https:\/\/denbeke.be\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/denbeke.be\/blog\/webdevelopment\/css-semi-transparent-border-on-images\/#primaryimage\"},\"datePublished\":\"2015-01-15T16:33:42+00:00\",\"dateModified\":\"2015-01-15T07:34:28+00:00\",\"author\":{\"@id\":\"https:\/\/denbeke.be\/blog\/#\/schema\/person\/386878f712fe3fe22227216f087772dc\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/denbeke.be\/blog\/webdevelopment\/css-semi-transparent-border-on-images\/\"]}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/denbeke.be\/blog\/#\/schema\/person\/386878f712fe3fe22227216f087772dc\",\"name\":\"Mathias Beke\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/denbeke.be\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/015ba35e6ce4f5859e3888ca99807575?s=96&d=mm&r=g\",\"caption\":\"Mathias Beke\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/posts\/1753"}],"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}]}}