I was recently playing around with my family photo blog, trying to give the photos a bit more pizzazz.
I found some interesting tutorials for making CSS borders here at mandarindesign.com and a very nice looking drop shadow like this one from 1976design.com. The problem is that they either require nesting <img> tags within <div> tags or are a bit bland. Nesting tags would have required me to go through all my old blog posts and wrap every <img> with a <div>.
After some experiments I came up with a very cheap pseudo drop shadow that is quite effective using nothing but simple CSS style.
All I’ve done is center the image and add padding of 8 pixels surrounded by a border. The trick is that the top and left edges of the border are only 1 pixel wide, while the right and bottom are 2 pixels. Also, the top and left sides of the border are a slightly lighter colour than the bottom and right.
Since it is intended for all thumbnail images in my WordPress blog posts, the following is what I added to my theme style. It is applied to all <img> tags within <a> tags within a <div> of the class “post”.
.post a img {
/* This centers the image */
display: block;
margin-left: auto;
margin-right: auto;
/* This adds the border */
padding:8px;
border:solid;
border-color: #dddddd #aaaaaa #aaaaaa #dddddd;
border-width: 1px 2px 2px 1px;
background-color:white;
}
It is really just a bevel but the width and colour differences trick the eye into seeing something that more closely resembles a drop shadow.
Above is a stand alone example page and sample image.
Hey… this is a nice trick.. thanks for sharing.. π
Great. I’m in the process of making a small cms. Let’s see if I can work this in. Thanks
Thanks for this. I’ve been looking for a nice style to add to the header images of my posts. I modified this to have its own class so that I could apply it to only the images I wanted it on.
It’s just been implemented on my website at http://www.gluglu.co.uk
Thanks again!
Just wanted to say ta for this, just what I was looking for π
Thank you for the tip. I have already applied the border to the pics on my blog. Thanks again!
Thanks for the great tip. Cool one.
Hi,
I’m impressed! Trying it out on travelblog.com.
Thanks, Brian
I really like this dropshadow effect but could you please write out the whole code for me I am somewhat new to this
thanks
It is hard to just “write it all” without knowing exactly what you need.
For example, you can apply a style to any object in your page, like I have done on my page to show the example image.
If you view the source of this page you will find the following.
<img src="http://notions.okuda.ca/wp-conten/uploads/2006/10/matthew-pumpkin-original.jpg" style="display: block; margin-left: auto; margin-right: auto; padding:8px; border:solid; border-color: #dddddd #aaaaaa #aaaaaa #dddddd; border-width: 1px 2px 2px 1px;" />
That is the img tag showing the image and the inline style of how it should look (using the same rules shown above).
If you want it to affect all the images on your web site then you should use a style sheet or a style element. The source provided above is what I use on a different wordpress blog to apply the style to all images within an <a> anchor that are part of a post. The appropriate style will depend on the contents of the web site and how you want it to apply.
Here are some references that may help.
http://www.w3.org/TR/REC-html40/present/styles.html
http://www.w3schools.com/Css/css_intro.asp
Thank you Poco. This will be useful for my website. It looks great.
I get the border but not the padding. I cut-n-pasted your sample code above the download (below the example)… I use Max HTML Beauty which renders a sample of the page using IE 7.0.
Any help would be appreciated!
Jonathan
Thanks a lot for sharing the information.. Its too cool
Thank you very much, I’m using this on my site and it really has a nice look!
Thank-you! This is a very simple and effective image border!
thamk you very much for this information. it’s a vety nice border indeed π
Thanks!..i was looking all over the place for something simple, yet efficient like this solution.
Hi,
Thanks for share, i have use this trick in my blog.
Pingback: CTN 161 Web Production 2 » Blog Archive » Exercise 11: Styling Images with CSS - Fall 2009
very cool! thank you so much for sharing! i am using this!
Thanks a ton. I really like the way that style will work on my Family site. Great tip.
cool trick man. Thanks for that.
PS:Your wife is hot!!!
Pingback: Cool CSS Image Border Style | Interactive I.T. Designs
thanks for giving this trick.
completely and totally awesome code snippet
Very nice! I’ve just added this style to my blog’s images. Thanks π
Thanks so much for this – saved me a load of time!
Thanks so much – it was getting to me casue I wanted to keep the ready made template but i just wanted add a simple but effective photo borders for my blog. π
very nice. How can i add caption at the bottom of an image ?
nice trick, that’s exactly what I need. Thanks a lot!
nice trick, thatβs exactly what I need. Thanks a lot!
Thanks!
I tweaked this a bit to fit my WordPress install. I added this to three different divs including one that holds photos in the body of the website and has a hyperlink, one without the hyperlink (not sure if I could do that with one code) and any images that appear in a widget:
#container a img {/* This adds the border */ padding:8px; border:solid; border-color: #dddddd #aaaaaa #aaaaaa #dddddd; border-width: 1px 2px 2px 1px; background-color:white; }
#container img { /* This adds the border */ padding:8px; border:solid; border-color: #dddddd #aaaaaa #aaaaaa #dddddd; border-width: 1px 2px 2px 1px; background-color:white; }
#sidebar img { /* This adds the border */ padding:8px; border:solid; border-color: #dddddd #aaaaaa #aaaaaa #dddddd; border-width: 1px 2px 2px 1px; background-color:white; }
New website up in a week.
Thanks again!
I really do like the border trick. It does look like a drop shadow.
One thing you should know is that it looks like your wordpress blog has been hacked. There are some hidden links in it.
If you go to google and search for:
“very cheap pseudo drop shadow that is quite effective using nothing but simple CSS style.”
You will see your site listed as number 1, but with a title that says to buy a prescription drug.
Alternatively, you could use this link:
https://www.google.com/search?q=After+some+experiments+I+came+up+with+a+very+cheap+pseudo+drop+shadow+that+is+quite+effective+using+nothing+but+simple+CSS+style.&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a
And you can see what google sees when they come to your site.
so most likely you will have to ask your web host to help you clean up your files, and you will need to upgrade to the latest install of wordpress.
Hope this helps, and thanks again for the cool border image trick.
Looks like you fixed the hack. Good Job!
Thanks again for the tutorial.
Thanks for sharing. I discovered that by adding “border-radius: 10px;” you will get rounded corners.
5 years later (or more) and this still an awesome trick. Thanks!!!
Good Job! Thanks!!!
I searched and searched for a simple little trick like this…. LOVE it! (and yes it is a number of years later and shows the simple things are often the best)
Looks Great π
Works well, thanks.
cool work
thank you for the code.
Looks Great
Thanks again for the tutorial.
Amazing trick, just inplemented on my site, thank you thank you!
Isto Γ© um teste para ver se consigo descobrir o meu texto no pedido HTTP POST………..
Thank you for these instructions. It will be really helpful for my website. I will make borders like this or something similar on all my flight search options banners π