响应式图片相册

废话少说,直接上代码,然后再详细介绍构造过程。

代码

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>响应式图片相册</title> 
<style>

* {/*设置全局格式*/
    box-sizing: border-box;/*并排放置两个带边框的框*/
}

div.img {
    border: 2px solid purple;/*设置图片外边框格式*/
}

div.img:hover {/*定义鼠标点击图片时的效果*/
    border: 3px solid red;
}

div.img img {/*设置图片大小*/
    width: 100%;
    height: auto;
}

div.desc {/*设置描述文本格式*/
    padding: 15px;
    text-align: center;
}

.responsive {/*设置默认格式下图片的尺寸*/
    padding: 0 6px;
    float: left;
    width: 24.99999%;/*修改图片的宽度,可并排放置四张图片*/
}

@media only screen and (max-width: 700px){/*若屏幕小于等于700px时的响应式设置*/
    .responsive {
        width: 49.99999%;/*并排放置两张图片*/
        margin: 6px 0;
    }
}

@media only screen and (max-width: 500px){/*若屏幕小于等于500px时的响应式设置*/
    .responsive {
        width: 100%;/*并排放置一张图片*/
    }
}

.clearfix:after {
    content: "";
    display: table;
    clear: both;
}

</style>
</head>
<body>

<h2 style="text-align:center">响应式图片相册</h2>

<div class="responsive">
  <div class="img">
    <a target="_blank" href="210320104505-1.jpg">
      <img src="http://pic.jj20.com/up/allimg/1114/032021104505/210320104505-1.jpg" alt="Trolltunga Norway" width="300" height="200">
    </a>
    <div class="desc">Add a description of the image here</div>
  </div>
</div>


<div class="responsive">
  <div class="img">
    <a target="_blank" href="210320104505-3.jpg">
      <img src="http://pic.jj20.com/up/allimg/1114/032021104505/210320104505-3.jpg" alt="Forest" width="600" height="400">
    </a>
    <div class="desc">Add a description of the image here</div>
  </div>
</div>

<div class="responsive">
  <div class="img">
    <a target="_blank" href="210320104505-7.jpg">
      <img src="http://pic.jj20.com/up/allimg/1114/032021104505/210320104505-7.jpg" alt="Northern Lights" width="600" height="400">
    </a>
    <div class="desc">Add a description of the image here</div>
  </div>
</div>

<div class="responsive">
  <div class="img">
    <a target="_blank" href="210320104505-6.jpg">
      <img src="http://pic.jj20.com/up/allimg/1114/032021104505/210320104505-6.jpg" alt="Mountains" width="600" height="400">
    </a>
    <div class="desc">Add a description of the image here</div>
  </div>
</div>

<div class="clearfix"></div>

<div style="padding:6px;">
  
  <h4>重置浏览器大小查看效果</h4>
</div>

</body>
</html>

在这里插入图片描述

响应式设置

若屏幕小于等于700px

代码

@media only screen and (max-width: 700px){/*若屏幕小于等于700px时的响应式设置*/
    .responsive {
        width: 49.99999%;/*并排放置两张图片*/
        margin: 6px 0;
    }
}

在这里插入图片描述

若屏幕小于等于500px

代码

@media only screen and (max-width: 500px){/*若屏幕小于等于500px时的响应式设置*/
    .responsive {
        width: 100%;/*并排放置一张图片*/
    }
}

在这里插入图片描述
至此所有的步骤都已完成。
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值