CSS实例:图片导航块

 

  1. 认识CSS的 盒子模型。
  2. CSS选择器的灵活使用。
  3. 图片文字用div等元素布局形成HTML文件。
  4. 新建相应CSS文件,并link到html文件中。
  5. CSS文件中定义样式
    1. div.img:border,margin,width,float
    2. div.img img:width,height
    3. div.desc:text-align,padding
    4. div.img:hover:border
    5. div.clearfloat:clear

html代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>图片导航</title>
    <link rel="stylesheet" type="text/css" href="../static/css/test1.css">
</head>
<body>
<h2>用户导航</h2>
<hr>
<div class="daohang">

    <div class="img">
        <a href="http://www.gzcc.cn/html/xueyuanrongyu/">
            <img src="http://www.gzcc.cn/2016/images/yhdh/01.jpg"></a>
        <div class="desc">
            <a href="http://www.gzcc.cn/html/xueyuanrongyu/">学校荣誉</a>
        </div>
    </div>


    <div class="img">
        <a href="http://www.gzcc.cn/html/banxuechengguo/">
            <img src="http://www.gzcc.cn/2016/images/yhdh/02.jpg"></a>
        <div class="desc">
            <a href="http://www.gzcc.cn/html/banxuechengguo/">师生获奖</a>
        </div>
    </div>

    <div class="img">
        <a href="http://www.gzcc.cn/html/xygk/ldgh/">
            <img src="http://www.gzcc.cn/2016/images/yhdh/03.jpg"></a>
        <div class="desc">
            <a href="http://www.gzcc.cn/html/xygk/ldgh/">领导关怀</a>
        </div>
    </div>


    <div class="img">
        <a href="http://i.gzcc.cn" target="_blank">
            <img src="http://www.gzcc.cn/2016/images/yhdh/08.jpg"></a>
        <div class="desc">
            <a href="http://i.gzcc.cn" target="_blank">数字广商</a>
        </div>
    </div>

    <div class="img">
        <a href="http://www.gzcc.cn/html/xygk/xiaoyuanfengguang/">
            <img src="http://www.gzcc.cn/2016/images/yhdh/05.jpg"></a>
        <div class="desc">
            <a href="http://www.gzcc.cn/html/xygk/xiaoyuanfengguang/">画说校园</a>
        </div>
    </div>

    <div class="img">
        <a href="http://www.gzcc.cn/html/shipinxiaoyuan/">
            <img src="http://www.gzcc.cn/2016/images/yhdh/06.jpg"></a>
        <div class="desc">
            <a href="http://www.gzcc.cn/html/shipinxiaoyuan/">视频广商</a>
        </div>
    </div>

    <div class="img">
        <a href="http://www.gzcc.cn/quanjingxiaoyuan/tour.html">
            <img src="http://www.gzcc.cn/2016/images/yhdh/07.jpg"></a>
        <div class="desc">
            <a href="http://www.gzcc.cn/quanjingxiaoyuan/tour.html">全景校园</a>
        </div>
    </div>

    <div class="img">
        <a href="http://www.gzcc.cn/html/xiaoyoufengcai/">
            <img src="http://www.gzcc.cn/2016/images/yhdh/04.jpg"></a>
        <div class="desc">
            <a href="http://www.gzcc.cn/html/xiaoyoufengcai/">校友风采</a>
        </div>
    </div>

</div>

<div class="clearfolat">
    <div class="img">
        <a href="http://www.gzcc.cn/html/xueyuanrongyu/">
            <img src="http://www.gzcc.cn/2016/images/yhdh/01.jpg"></a>
    </div>
    <div class="img">
        <a href="http://www.gzcc.cn/html/banxuechengguo/">
            <img src="http://www.gzcc.cn/2016/images/yhdh/02.jpg"></a>
    </div>
    <div class="img">
        <a href="http://www.gzcc.cn/html/xygk/ldgh/">
            <img src="http://www.gzcc.cn/2016/images/yhdh/03.jpg"></a>
    </div>
    <div class="img">
        <a href="http://i.gzcc.cn" target="_blank">
            <img src="http://www.gzcc.cn/2016/images/yhdh/08.jpg"></a>

    </div>
    <div class="img">
        <a href="http://www.gzcc.cn/html/xygk/xiaoyuanfengguang/">
            <img src="http://www.gzcc.cn/2016/images/yhdh/05.jpg"></a>
    </div>
    <div class="img">
        <a href="http://www.gzcc.cn/html/shipinxiaoyuan/">
            <img src="http://www.gzcc.cn/2016/images/yhdh/06.jpg"></a>
    </div>
    <div class="img">
        <a href="http://www.gzcc.cn/quanjingxiaoyuan/tour.html">
            <img src="http://www.gzcc.cn/2016/images/yhdh/07.jpg"></a>
    </div>
    <div class="img">
        <a href="http://www.gzcc.cn/html/xiaoyoufengcai/">
            <img src="http://www.gzcc.cn/2016/images/yhdh/04.jpg"></a>
    </div>

</div>
</body>
</html>

 

css代码如下:

.daohang{
    align-content: center;
    padding: 20px;
}
img {
    width: 400px;
}

div.img {
    border: 1px solid #cccccc;
    float: left;
    margin: 30px;
    width: 260px;
}

div.img img {
    width: 100%;
    height: auto;
}

div.desc {
    background-color:cadetblue;
    text-align: center;
    padding: 5px;
}

div.img:hover {
    border: 1px solid #000000;
}

div.desc:hover {
    border: 1px solid #000000;
}

div.clearfolat {
    clear: both;
}

 

转载于:https://www.cnblogs.com/1257-/p/7699365.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值