CSS为图片添加相框各种效果。

下载

I’m using the same trick to show you how to decorate your images and photo galleries without editing the source images. The trick is very simple. All you need is an extra <span> tag and apply a background image to create the overlaying effect. It is very easy and flexible — see my demos with over 20 styles, from a simple image icon to a rounded corner to a masked layer (both decorative and complex).

 

Basic Concept (see demo)

You need to insert an extra <span> tag within the <div> tag, with which we’ll apply a background http://www.chenbincb.com.cn/cnblogs/demo44/images/ to create the overlaying effect. If you don’t like to have an empty span tag, you can append the span tag by Javascript (I’ll show you how later in this tutorial). Here is how it works:

Basic Concept

Then in the CSS, the key point you have to remember is: specify the div element to position:relative and the span element to position:absolute. You can position the span element anywhere you want by using the top and left property.

IE PNG Hack

To make the transparent PNG http://www.chenbincb.com.cn/cnblogs/demo44/images/ work on IE6, I use this wonderful iepngfix.htc hack. Download a copy of iepngfix.htc and insert the following code in between the <head> tag:

<!--[if lt IE 7]>
<style type="text/css">
.photo span { behavior: url(iepngfix.htc); }
</style>
<![endif]-->
Look and Feel

To change the look and feel, simply edit the CSS specifications of the span element. Click the http://www.chenbincb.com.cn/cnblogs/demo44/images/ below to see the demos I have. To show you how flexible it is, I’ve created 15 different styles (notice the HTML markup is same).

Demo screenshot

The jQuery Solution (see demo)

I know some of you (particularly the web accessibility fans) don’t like to have an empty span tag in the markup. Well, I’ve solved this issue by using jQuery to append the span tag to the source code. Insert the following code in between the <head> tag:

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
//prepend span tag
$(".photo a").prepend("<span></span>");
});
</script>

#1. Simple Gallery (see demo)

Let’s take the technique from the previous step and apply it to create a photo gallery.

Demo 1

#1b. Mini Icons (see demo)

This example shows you how to position different icons on top of each photo (note: an extra CSS class name is required in the span tag).

Demo 1b

#2. Photo With Text (see demo)

This example shows you how to create a gallery with linking text (em tag).

photo with text

#2b. Popup Text (see demo)

popup text

#3. Mini Paper Clip (see demo)

Mini paper clip demo

#4. Cork Board Gallery (see demo, IE6 version)

cork board gallery

sIFR Version (Flash Text Replacement) (see sIFR demo)

This example uses sIFR to replace the em text with a handwritten font (notes: in this demo, the span tag is appended by jQuery)

sIFR demo

#4b. Cork Board With Masking Tape (see demo, IE6 version)

Demo 2b

#5. Art Gallery - Black Frame (see demo)

black picture frame

#5b. Art Gallery - Gold Frame (see demo)

gold art frame

#6. Grungy Watercolor (see demo)

grungy watercolor

sIFR Version (see sIFR demo)

sIFR demo

#7. Glossy Style (see demo)

glossy style

#8. Wood Panel Gallery (see demo)

Finally, this example demonstrates how you can apply the background http://www.chenbincb.com.cn/cnblogs/demo44/images/ to all elements to create a wood panel gallery: ul, li, and em.

wood panel

Final Remarks

As you can see, this CSS trick is very flexible. So, be creative! Feel free to incorporate the graphic http://www.chenbincb.com.cn/cnblogs/demo44/images/s and CSS styles in this tutorial to create your own.

转载于:https://www.cnblogs.com/CB/archive/2008/05/31/1211142.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值