CSS实例:图片导航块

  1. 认识CSS的 盒子模型。
  2. CSS选择器的灵活使用。
  3. 实例:
    1. 图片文字用div等元素布局形成HTML文件。
    2. 新建相应CSS文件,并link到html文件中。
    3. 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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>哈利波特</title>
    <base target="_blank">
    <link rel="stylesheet"type="text/css"href="text.css">
</head>
<body>
<div>
    <div class="pic">
        <a href="http://www.iqiyi.com/v_19rrifgoyw.html?vfm=2008_aldbd&fc=828fb30b722f3164&fv=p_02_01">
            <img src="http://img21.mtime.cn/CMS/Gallery/2011/07/01/173936.86736747_900.jpg"></a>
        <div class="aa"><a href="http://www.iqiyi.com/v_19rrifgoyw.html?vfm=2008_aldbd&fc=828fb30b722f3164&fv=p_02_01">哈利波特与魔法石</a></div>
    </div>
    <div class="pic">
        <a href="http://www.iqiyi.com/v_19rrifgpcx.html?vfm=2008_aldbd&fc=828fb30b722f3164&fv=p_02_01">
            <img src="http://img.bimg.126.net/photo/O9NvIsLiLVEe6Qm6zQjG_Q==/5702401553182072153.jpg"></a>
        <div class="aa"><a href="http://www.iqiyi.com/v_19rrifgpcx.html?vfm=2008_aldbd&fc=828fb30b722f3164&fv=p_02_01">哈利波特与密室</a></div>
    </div>
    <div class="pic">
        <a href="http://www.iqiyi.com/v_19rrifgplc.html?vfm=2008_aldbd&fc=828fb30b722f3164&fv=p_02_01">
            <img src="https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=4073698086,1900035317&fm=27&gp=0.jpg"></a>
        <div class="aa"><a href="http://www.iqiyi.com/v_19rrifgplc.html?vfm=2008_aldbd&fc=828fb30b722f3164&fv=p_02_01">哈利波特与阿兹卡班的囚徒</a></div>
    </div>
    <div class="pic">
        <a href="http://www.iqiyi.com/v_19rrifgpdf.html?vfm=2008_aldbd&fc=828fb30b722f3164&fv=p_02_01">
            <img src="https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2448077391,705824826&fm=27&gp=0.jpg"></a>
        <div class="aa"><a href="http://www.iqiyi.com/v_19rrifgpdf.html?vfm=2008_aldbd&fc=828fb30b722f3164&fv=p_02_01">哈利波特与火焰杯</a></div>
    </div>

<div class="clearfloat">
    <img src="http://img21.mtime.cn/CMS/Gallery/2011/07/01/173936.86736747_900.jpg">
    <img src="http://img.bimg.126.net/photo/O9NvIsLiLVEe6Qm6zQjG_Q==/5702401553182072153.jpg">
    <img src="https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=4073698086,1900035317&fm=27&gp=0.jpg">
    <img src="https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2448077391,705824826&fm=27&gp=0.jpg">
</div>
</div>
</body>
</html>

css

img{
width:300px;
height:200px;
}
.pic{
border:1px solid black;
width:200px;
float:left;
margin:5px;
}
.pic img{
width:100%;
height:120px;
}
.aa{
text-align:center;
padding:4px;
}
.pic:hover{
    border:1px solid blue;
}
.clearfloat{
    clear: both;

 

posted @ 2017-10-20 17:20  011赖颖璇  阅读(189)  评论(0编辑  收藏  举报