意见箱
恒创运营部门将仔细参阅您的意见和建议,必要时将通过预留邮箱与您保持联络。感谢您的支持!
意见/建议
提交建议

CSS中实现响应式图片库怎样做,方法是什么

来源:恒创科技 编辑:恒创科技编辑部
2024-01-19 15:51:59
这篇文章给大家分享的是“CSS中实现响应式图片库怎样做,方法是什么”,对大家学习和理解有一定的参考价值和帮助,有这方面学习需要的朋友,接下来就跟随小编一起学习一下吧。
   


 


CSS中实现响应式图片库怎样做,方法是什么

CSS如果想要实现响应式图片库_图片列表页面自适应,则必须载不同屏幕尺寸下,按照不同的百分比定义图片库或则图片列表,下面是代码:

<!DOCTYPEhtml>
<html>
<head>
<style>
div.gallery{
border:1pxsolid#ccc;
}

div.gallery:hover{
border:1pxsolid#777;
}

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

div.desc{
padding:15px;
text-align:center;
}

*{
box-sizing:border-box;
}

//正常屏幕,则按照1/4屏幕显示图片,表示最多显示4张图片
.responsive{
padding:06px;
float:left;
width:24.99999%;
}

//屏幕低于700像素,高于500像素,则按照屏幕50%显示比例
@mediaonlyscreenand(max-width:700px){
.responsive{
width:49.99999%;
margin:6px0;
}
}

//屏幕宽度低于500像素,则按照屏幕100%显示图片
@mediaonlyscreenand(max-width:500px){
.responsive{
width:100%;
}
}

.clearfix:after{
content:"";
display:table;
clear:both;
}
</style>
</head>
<body>

<h2>ResponsiveImageGallery</h2>

<h4>Resizethebrowserwindowtoseetheeffect.</h4>

<divclass="responsive">
<divclass="gallery">
<atarget="_blank"href="img_5terre.jpg">
<imgsrc="img_5terre.jpg"alt="CinqueTerre"width="600"height="400">
</a>
<divclass="desc">Addadescriptionoftheimagehere</div>
</div>
</div>


<divclass="responsive">
<divclass="gallery">
<atarget="_blank"href="img_forest.jpg">
<imgsrc="img_forest.jpg"alt="Forest"width="600"height="400">
</a>
<divclass="desc">Addadescriptionoftheimagehere</div>
</div>
</div>

<divclass="responsive">
<divclass="gallery">
<atarget="_blank"href="img_lights.jpg">
<imgsrc="img_lights.jpg"alt="NorthernLights"width="600"height="400">
</a>
<divclass="desc">Addadescriptionoftheimagehere</div>
</div>
</div>

<divclass="responsive">
<divclass="gallery">
<atarget="_blank"href="img_mountains.jpg">
<imgsrc="img_mountains.jpg"alt="Mountains"width="600"height="400">
</a>
<divclass="desc">Addadescriptionoftheimagehere</div>
</div>
</div>

<divclass="clearfix"></div>

<divstyle="padding:6px;">
<p>Thisexampleusemediaqueriestore-arrangetheimagesondifferentscreensizes:forscreenslargerthan700pxwide,itwillshowfourimagessidebyside,forscreenssmallerthan700px,itwillshowtwoimagessidebyside.Forscreenssmallerthan500px,theimageswillstackvertically(100%).</p>
<p>YouwilllearnmoreaboutmediaqueriesandresponsivewebdesignlaterinourCSSTutorial.</p>
</div>

</body>
</html>

上述备注部分为关键代码!

效果如图:



“CSS中实现响应式图片库怎样做,方法是什么”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业技术相关的知识可以关注恒创科技网站,小编每天都会为大家更新不同的知识。
上一篇: 详解CSS padding属性的详细用法是什么 下一篇: 手机怎么远程登录云服务器?