这篇文章主要介绍了css3怎么实现响应式手风琴效果,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。效果如下:全屏时:屏幕宽度小于960px时:下面来看一下页面的基本结构(ind
这篇文章主要介绍了css3怎么实现响应式手风琴效果,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
效果如下:
全屏时:
屏幕宽度小于960px时:
下面来看一下页面的基本结构(index.html):
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <link rel="stylesheet" href="style.CSS"></head><body> <div class="container"> <!--标题--> <header> <h2>Follow me on social media</h2> </header> <!--手风琴部分--> <ul class="accordion"> <li class="tab"> <div class="social youtube"> <a href="#">YouTube</a> </div> <div class="content"> <h2>YouTube</h2> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit.Culpa, consectetur.</p> </div> </li> <li class="tab"> <div class="social facebook"> <a href="#">Facebook</a> </div> <div class="content"> <h2>Facebook</h2> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit.Culpa, consectetur.</p> </div> </li> <li class="tab"> <div class="social twitter"> <a href="#">Twitter</a> </div> <div class="content"> <h2>Twitter</h2> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit.Culpa, consectetur.</p> </div> </li> <li class="tab"> <div class="social instagram"> <a href="#">Instagram</a> </div> <div class="content"> <h2>Instagram</h2> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit.Culpa, consectetur.</p> </div> </li> <li class="tab"> <div class="social linkedin"> <a href="#">Linkedin</a> </div> <div class="content"> <h2>Linkedin</h2> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit.Culpa, consectetur.</p> </div> </li> <li class="tab"> <div class="social GitHub"> <a href="#">github</a> </div> <div class="content"> <h2>Github</h2> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit.Culpa, consectetur.</p> </div> </li> </ul> </div></body></html>
样式(style.css):
*{ margin: 0; padding: 0; border: none;}body{ font-family: Arial, Helvetica, sans-serif; background-color: #222; color: #fff;}@font-face { font-family: 'Genericons'; src: url('font/genericons-regular-WEBfont.woff') fORMat('woff'), url('font/genericons-regular-webfont.eot') format('truetype');}.container{ width: 80%; margin: 20px auto;}header h2{ font-size: 2rem; padding: 1rem; text-align: center;}.accordion{ width: 100%; min-width: 800px; height: 200px; background-color: #333; list-style: none; display: block; overflow: hidden; font-size: 0;}.tab{ width: 80px; height: 100%; display: inline-block; position: relative; margin: 0; background-color: #444; border: 1px solid #333; overflow: hidden; transition: all .5s ease .1s;}.tab:hover{ width: 450px;}.tab:hover .social a:after{ transform: translateX(-80px);}.tab:hover .social a:before{ transform: translateX(-100px);}.tab .content{ position: relative; width: 360px; height: 100%; background-color: #fff; color: #333; margin-left: 80px; padding: 50px 0 0 15px;}.tab .content h2{ font-size: 2.5rem; margin-top: 20px;}.tab .content p{ font-size: .85rem; line-height: 1.6;}/设置为元素的宽高及字体为Genericons,不然图标无法显现,只会显示白色的空框框/.social a:before,.social a:after{ position: absolute; width: 80px; height: 200px; display: block; text-indent: 0; padding-top: 90px; padding-left: 25px; font:normal 30px Genericons; color: #fff; transition: all .5s ease;}.social a:after{ font-size: 48px; padding-top: 80px; padding-left: 20px; margin-left: 80px;}.youtube a:before,.youtube a:after{ content: '\f213';}.youtube a:after{ background-color: #fc0000;}.twitter a:before,.twitter a:after{ content: '\f202';}.twitter a:after{ background-color: #6dc5dd;}.facebook a:before,.facebook a:after{ content: '\f204';}.facebook a:after{ background-color: #3b5998;}.linkedin a:before,.linkedin a:after{ content: '\f208';}.linkedin a:after{ background-color: #00a9cd;}.instagram a:before,.instagram a:after{ content: '\f215';}.instagram a:after{ background-color: #6dc993;}.github a:before,.github a:after{ content: '\f200';}.github a:after{ background-color: #6e5494;}@media(max-width:960px){ .container{ width: 70%; } .accordion{ min-width: 450px; height: auto; } .tab{ width: 100%; display: block; border-bottom: 1px solid #333; } .tab:hover{ width: 100%; } .tab .content{ width: 85%; } .social a:before{ padding-top: 60px; padding-left: 25px; } .social a:after{ padding-top: 50px; padding-left: 20px; }}
感谢你能够认真阅读完这篇文章,希望小编分享的“CSS3怎么实现响应式手风琴效果”这篇文章对大家有帮助,同时也希望大家多多支持编程网,关注编程网精选频道,更多相关知识等着你来学习!
--结束END--
本文标题: CSS3怎么实现响应式手风琴效果
本文链接: https://lsjlt.com/news/251519.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0