{"id":16,"date":"2008-02-04T19:29:04","date_gmt":"2008-02-05T01:29:04","guid":{"rendered":"http:\/\/cssnewbie.com\/css-rules\/5-cssriffic-treatments-images\/"},"modified":"2008-02-04T19:29:04","modified_gmt":"2008-02-05T01:29:04","slug":"5-cssriffic-treatments-images","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/5-cssriffic-treatments-images\/","title":{"rendered":"5 CSSriffic Treatments to Make Your Images Stand Out"},"content":{"rendered":"<p><img src='https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2008\/02\/image-treatments-example.jpg' alt='image-treatments-example.jpg' \/><\/p>\n<p>No web presence these days is complete without a little pixel lovin\u2019 in the form of images. If you have a blog or website out there somewhere without a single image anywhere on the site, well&#8230; 1997 called. They said they\u2019re sorry you fought and they want you to come back home.<\/p>\n<p class=\"pullquote\">Sometimes we need a little help to make our outstanding images <em>truly<\/em> stand out.<\/em><\/p>\n<p>But sometimes just having images isn\u2019t enough. Sometimes we need a little help to make our outstanding images <em>truly<\/em> stand out. And that\u2019s where CSS can help. Here are five things you can do, using CSS, to make the most of your images.<\/p>\n<h3>The Wraparound Treatment<\/h3>\n<p>One of the easiest ways to add visual interest to your page (and your images at the same time) is to have your text wrap around your images. It\u2019s very easy to do:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">img.wrap {\n\tfloat: right;\n\tmargin: 0 0 .5em 1em; \n}<\/pre>\n<p>The \u201cfloat\u201d property causes the image to literally float to the right side of whatever container it\u2019s in, and causes the rest of the content inside that container to wrap around it. Then we just added a bit of a margin to the bottom and left sides of the image to prevent the text from butting right up against its edges. And you\u2019ll note we used a \u201cwrap\u201d class on this rule, meaning we can choose which images get this treatment. You can <a href=\"\/example\/5-image-treatments\/#wrap\">see this in action here<\/a>.<\/p>\n<h3>The Photo Treatment<\/h3>\n<p>This option gives your image a bit of a white border around the edges, just like photos in real life often have. Try this:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">img.photo {\n\tborder: 1px solid #999;\n\tbackground-color: #fcfcfc;\n\tpadding: 4px; \n}<\/pre>\n<p>You can <a href=\"\/example\/5-image-treatments\/#photo\">see the results here.<\/a> What we\u2019ve done is added a gray border to all four sides, changed the background color of the image to a very pale gray (almost white), and then added a bit of padding to all four sides between the background and the image itself, so the background color could show through. And you\u2019ll note we used a class of \u201cphoto\u201d here: this way, we can pick and choose in our code which images get this treatment.<\/p>\n<h3>The Depth Treatment<\/h3>\n<p>We can also expand on the Photo treatment above and use the borders to create a sense of depth:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\"> img.deep {\n\tborder-left: 1px solid #ccc;\n\tborder-top: 1px solid #ccc;\n\tborder-right: 1px solid #888;\n\tborder-bottom: 1px solid #888;\n\tbackground-color: #fcfcfc;\n\tpadding: 4px;\n}<\/pre>\n<p>As you can see above and <a href=\"\/example\/5-image-treatments\/#depth\">on the example page<\/a>, we\u2019ve changed the border colors slightly. We\u2019ve made the top and left borders a slightly lighter shade than the bottom and right borders. This creates a subtle illusion of depth: the lighter border on the top and left suggests light is hitting those sides and the darker border on the bottom and right suggests a hint of a shadow created by a three-dimensional object.<\/p>\n<h3>The Shadow Treatment<\/h3>\n<p>And to expand further on the Depth treatment, we can use a bit of CSS magic and slightly modified HTML to <em>really<\/em> make the photo jump up off the page. We\u2019ll start with this HTML:<\/p>\n<pre lang=\"html4strict\" escaped=\"true\" line=\"1\">&lt;div class=\"shadow\"&gt;&lt;img src=\"photo.jpg\" \/&gt;&lt;\/div&gt;<\/pre>\n<p>As you can see, we\u2019ve wrapped our image in a div. Then we just apply these styles:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">.shadow {\n\tfloat: left;\n\tbackground-color: #aaa;\n}\n.shadow img {\n\tmargin: -4px 4px 4px -4px;\n\tdisplay: block; \n\tposition: relative;\n\tpadding: 4px;\n\tbackground-color: #fcfcfc;\n\tborder-left: 1px solid #ccc;\n\tborder-top: 1px solid #ccc;\n\tborder-right: 1px solid #888;\n\tborder-bottom: 1px solid #888;\n}<\/pre>\n<p>Obviously, this is a more advanced technique than the previous options. We\u2019re applying a background color to the div around our image, and then floating it so that it becomes the same size as the image inside. Then, we\u2019re using <em>negative margins<\/em> to move our image up and to the left of where it was originally, setting a display of \u201cblock\u201d and a position of \u201crelative\u201d to keep the floated div container from moving with our image. The result is that a few pixels of our background color are visible in the bottom right, creating the illusion of a shadow. Of course, <a href=\"\/example\/5-image-treatments\/#shadow1\">as you can see by the example<\/a>, it isn\u2019t a true shadow: nothing shows through.<\/p>\n<h3>The Shadow Treatment, Part Two<\/h3>\n<p>If you want your shadow to behave like a <em>real<\/em> shadow, you\u2019ll need to make use of a transparent PNG image. Image editing is beyond the scope of this article (and as you can probably tell from the site, this author), but if you create a semi-transparent square of black (I used 40% opacity) and save it as a PNG, then you can just replace this line:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">background-color: #aaa;<\/pre>\n<p>With one like this:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">background-image: url(shadow.png);<\/pre>\n<p>And <a href=\"\/example\/5-image-treatments\/#shadow2\">the result is a transparent shadow effect!<\/a> On browsers whose initials don\u2019t spell IE6, anyway. As usual, IE is a party pooper: it doesn\u2019t support transparency in images. But the result is a non-transparent shadow, no worse than what we had in the previous example.<\/p>\n<div class=\"wp-socializer wpsr-share-icons \" data-lg-action=\"show\" data-sm-action=\"show\" data-sm-width=\"768\" ><h3>Share and Enjoy !<\/h3><div class=\"wpsr-si-inner\"><div class=\"wpsr-counter wpsrc-sz-32px\" style=\"color:#000\"><span class=\"scount\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook,twitter,linkedin,pinterest,print,pdf\">0<\/span><\/span><small class=\"stext\">Shares<\/small><\/div><div class=\"socializer sr-popup sr-32px sr-circle sr-opacity sr-pad sr-count-1 sr-count-1\"><span class=\"sr-facebook\"><a rel=\"nofollow\" href=\"https:\/\/www.facebook.com\/share.php?u=\" target=\"_blank\"  title=\"Share this on Facebook\"  style=\"color: #ffffff\" ><i class=\"fab fa-facebook-f\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-twitter\"><a rel=\"nofollow\" href=\"https:\/\/twitter.com\/intent\/tweet?text=%20-%20%20\" target=\"_blank\"  title=\"Tweet this !\"  style=\"color: #ffffff\" ><i class=\"fab fa-twitter\"><\/i><\/a><\/span>\n<span class=\"sr-linkedin\"><a rel=\"nofollow\" href=\"https:\/\/www.linkedin.com\/sharing\/share-offsite\/?url=\" target=\"_blank\"  title=\"Add this to LinkedIn\"  style=\"color: #ffffff\" ><i class=\"fab fa-linkedin-in\"><\/i><\/a><\/span>\n<span class=\"sr-pinterest\"><a rel=\"nofollow\" href=\"https:\/\/www.pinterest.com\/pin\/create\/button\/?url=&amp;media=&amp;description=\" target=\"_blank\"  title=\"Submit this to Pinterest\"  style=\"color: #ffffff\" data-pin-custom=\"true\"><i class=\"fab fa-pinterest\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"pinterest\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-print\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Print this article \"  style=\"color: #ffffff\" ><i class=\"fa fa-print\"><\/i><\/a><\/span>\n<span class=\"sr-pdf\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Convert to PDF\"  style=\"color: #ffffff\" ><i class=\"fa fa-file-pdf\"><\/i><\/a><\/span><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<\/p>\n<p>No web presence these days is complete without a little pixel lovin\u2019 in the form of images. If you have a blog or website out there somewhere without a single image anywhere on the site, well&#8230; 1997 called. They said [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/5-cssriffic-treatments-images\/\" title=\"Click to read '5 CSSriffic Treatments to Make Your Images Stand Out'\">Read Article<\/a><\/p>\n","protected":false},"author":18,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[173,178,183],"tags":[261],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/16"}],"collection":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/comments?post=16"}],"version-history":[{"count":0,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/16\/revisions"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=16"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=16"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=16"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}