HTML5实践-使用css装饰图片画廊的代码分享(二)


当前第2页 返回上一页

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

<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

  css中我添加了两个:before,一个针对<figure>元素,另一个针对<li>元素。遮罩图片overlay.png被用在了figure:before上面,胶带图片用在了 a:before上面。


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

.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属性转变图片。

1

2

3

4

5

6

7

8

.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

  为了让图片旋转的更随机和自然,我使用nth-of-type去筛选图片,为不同图片设置不同的旋转角度。


1

2

3

4

5

6

7

.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装饰图片画廊的代码分享(二)的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

css中width有啥属性?

自定义实现可以播放暂停、进度拖拽、音量控制及全屏的h5播放器

css怎么在图片上加阴影

background-repeat属性怎么用

css样式怎么实现超出隐藏

css与javascript的区别是什么

7个专门为HTML5开发人员打造的web框架

css之简单的响应式的实现

巧用css将背景图像固定在视口

HTML5的集合

更多相关阅读请进入《HTML5》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...