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中实现响应式图片库怎样做,方法是什么”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业技术相关的知识可以关注恒创科技网站,小编每天都会为大家更新不同的知识。