HTML
下面是一个ul列表代表的图片画廊。
<ul class="gallery clip"> <li> <img src="http://webdesignerwall.com/wp-content/uploads/2012/09/sample-1.jpg" alt="image"> </li> <li> <img src="http://webdesignerwall.com/wp-content/uploads/2012/09/sample-2.jpg" alt="image"> </li> <li> <img src="http://webdesignerwall.com/wp-content/uploads/2012/09/sample-1.jpg" alt="image"> </li></ul>
CSS
下面是为.gallery设置的css,这里需要注意的一点是,我们需要为.gallery下面的a标签设置position: relative。
.gallery { margin: 0 0 25px; text-align: center; }.gallery li { display: inline-block; margin: 5px; list-style: none; }.gallery a { position: relative; display: inline-block; }:before元素
.clip a:before { position: absolute; content: ' '; top: -5px; left: -4px; width: 30px; height: 60px; background: url(http://webdesignerwall.com/wp-content/uploads/2012/09/paper-clip.png) no-repeat; }
艺术边框
利用这种技术,你可以再图片上添加任意的遮罩效果。下面的例子,我把图片背景换成了艺术边框。
.frame a:before { position: absolute; content: ' '; top: -22px; left: -23px; width: 216px; height: 166px; background: url(http://webdesignerwall.com/wp-content/uploads/2012/09/frame.png) no-repeat; }
HTML5画廊
我们可以使用html5标签,创造更高级的画廊。下面的例子,我们使用<figure>包装图片,<figcaption>包含图片标题。
<ul class="gallery tape"> <li> <figure> <img src="http://webdesignerwall.com/wp-content/uploads/2012/09/sample-4.jpg" alt="image"> <figcaption>Image Caption</figcaption> </figure> </li> <li> <figure> <img src="http://webdesignerwall.com/wp-content/uploads/2012/09/sample-5.jpg" alt="image"> <figcaption>Image Caption</figcaption> </figure> </li> <li> <figure> <img src="http://webdesignerwall.com/wp-content/uploads/2012/09/sample-6.jpg" alt="image"> <figcaption>Image Caption</figcaption> </figure> </li></ul>
CSS .tape li {
width: 170px;
padding: 5px;
margin: 15px 10px;
border: solid 1px #cac09f;
background: #fdf8e4;
text-align: center;
box-shadow: inset 0 1px rgba(255,255,255,.8), 0 1px 2px rgba(0,0,0,.2);
}.tape figure {
position: relative;
margin: 0;
}.tape a:before {
position: absolute;
content: ' ';
top: 0;
left: 0;
width: 100%;
height: 100%;
background: url(http://webdesignerwall.com/wp-content/uploads/2012/09/overlay.png) no-repeat;
}.tape figcaption {
font: 100%/120% Handlee, Arial, Helvetica, sans-serif;
color: #787568;
}.tape a:before {
position: absolute;
z-index: 2;
content: ' ';
top: -12px;
left: 50%;
width: 115px;
height: 32px;
margin-left: -57px;
background: url(http://webdesignerwall.com/wp-content/uploads/2012/09/tape.png) no-repeat;
}
CSS3 Transform
在这个例子中,我使用了软木纹饰背景,并使用transform属性转变图片。
.transform { background: url(http://webdesignerwall.com/wp-content/uploads/2012/09/cork-bg.png); padding: 25px; border-radius: 10px; box-shadow: inset 0 1px 5px rgba(0,0,0,.4); }.transform li { border: none; }
Nth-of-Type .transform li:nth-of-type(4n+1) {
-webkit-transform: rotate(2deg);
}.transform li:nth-of-type(2n) {
-webkit-transform: rotate(-1deg);
}.transform li:nth-of-type(4n+3) {
-webkit-transform: rotate(2deg);
}
好了,今天的教程到此为止。
以上就是HTML5实践-使用css装饰图片画廊的代码分享(二)的详细内容,更多请关注Gxl网其它相关文章!
查看更多关于HTML5实践-使用css装饰图片画廊的代码分享(二)的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did41411