[英]How to make list item overflow scroll horizontally after 6 list item?
I am trying since long to make these list items scroll horizontal, but failed can someone please help me to make these list items scrolled. 我很努力地让这些列表项滚动水平,但失败可以有人请帮助我滚动这些列表项。
I need to keep 6 items here & after 6 any amount of list item will be scrolled horizontally. 我需要在这里保留6个项目,在6之后,任何数量的列表项都将水平滚动。 i tried to find solution via google but cant solve my problem.
我试图通过谷歌找到解决方案,但无法解决我的问题。 So please help me guys to solve me this.
所以请帮助我们解决这个问题。
.level ul { padding-top: 20px; position: relative; transition: all 0.5s; -webkit-transition: all 0.5s; -moz-transition: all 0.5s; } .level li { float: left; text-align: center; list-style-type: none; position: relative; padding: 20px 5px 0 5px; transition: all 0.5s; -webkit-transition: all 0.5s; -moz-transition: all 0.5s; } .level li::before, .level li::after{ content: ''; position: absolute; top: 0; right: 50%; border-top: 5px solid #84c225; width: 50%; height: 20px; } .level li::after{ right: auto; left: 50%; border-left: 5px solid #84c225; } .level li:only-child::after, .level li:only-child::before { display: none; } .level li:only-child{ padding-top: 0;} .level li:first-child::before, .level li:last-child::after{ border: 0 none; } .level li:last-child::before{ border-right: 5px solid #84c225; border-radius: 0 5px 0 0; -webkit-border-radius: 0 5px 0 0; -moz-border-radius: 0 5px 0 0; } .level li:first-child::after{ border-radius: 5px 0 0 0; -webkit-border-radius: 5px 0 0 0; -moz-border-radius: 5px 0 0 0; } .level ul ul::before{ content: ''; position: absolute; top: 0; left: 50%; border-left: 5px solid #84c225; width: 0; height: 20px; } .level li div{ border: 1px solid #ccc; padding: 5px 10px; text-decoration: none; color: #666; font-family: arial, verdana, tahoma; font-size: 11px; display: inline-block; border-radius: 5px; -webkit-border-radius: 5px; -moz-border-radius: 5px; transition: all 0.5s; -webkit-transition: all 0.5s; -moz-transition: all 0.5s; } .level li div:hover, .level li div:hover+ul li div { background: #c8e4f8; color: #000; border: 1px solid #94a0b4; } .level li div:hover+ul li::after, .level li div:hover+ul li::before, .level li div:hover+ul::before, .level li div:hover+ul ul::before{ border-color: #94a0b4; } .main-img{ width: 150px; } .sub-img{ width: 50px; }
<div class="level"> <ul> <li> <a href="#"> <div> <img src="<?php echo "img_avatar.png" ?>" class="img-responsive img-circle main-img"> </div> </a> <ul class="sub-level"> <li> <a href="#"> <div> <img src="<?php echo "img_avatar.png" ?>" class="img-responsive img-circle sub-img"> </div> </a> </li> <li> <a href="#"> <div> <img src="<?php echo "img_avatar.png" ?>" class="img-responsive img-circle sub-img"> </div> </a> </li> <li> <a href="#"> <div> <img src="<?php echo "img_avatar.png" ?>" class="img-responsive img-circle sub-img"> </div> </a> </li> <li> <a href="#"> <div> <img src="<?php echo "img_avatar.png" ?>" class="img-responsive img-circle sub-img"> </div> </a> </li> <li> <a href="#"> <div> <img src="<?php echo "img_avatar.png" ?>" class="img-responsive img-circle sub-img"> </div> </a> </li> <li> <a href="#"> <div> <img src="<?php echo "img_avatar.png" ?>" class="img-responsive img-circle sub-img"> </div> </a> </li> <li> <a href="#"> <div> <img src="<?php echo "img_avatar.png" ?>" class="img-responsive img-circle sub-img"> </div> </a> </li> </ul> </li> </ul> </div>
Add display: flex
to .level ul
(a flex container is non-wrapping by default) - see demo below: 添加
display: flex
to .level ul
(默认情况下, flex容器 是非换行的) - 请参阅下面的演示:
.level ul { display: flex; /* added */ padding-top: 20px; position: relative; transition: all 0.5s; -webkit-transition: all 0.5s; -moz-transition: all 0.5s; } .level li { float: left; text-align: center; list-style-type: none; position: relative; padding: 20px 5px 0 5px; transition: all 0.5s; -webkit-transition: all 0.5s; -moz-transition: all 0.5s; } .level li::before, .level li::after { content: ''; position: absolute; top: 0; right: 50%; border-top: 5px solid #84c225; width: 50%; height: 20px; } .level li::after { right: auto; left: 50%; border-left: 5px solid #84c225; } .level li:only-child::after, .level li:only-child::before { display: none; } .level li:only-child { padding-top: 0; } .level li:first-child::before, .level li:last-child::after { border: 0 none; } .level li:last-child::before { border-right: 5px solid #84c225; border-radius: 0 5px 0 0; -webkit-border-radius: 0 5px 0 0; -moz-border-radius: 0 5px 0 0; } .level li:first-child::after { border-radius: 5px 0 0 0; -webkit-border-radius: 5px 0 0 0; -moz-border-radius: 5px 0 0 0; } .level ul ul::before { content: ''; position: absolute; top: 0; left: 50%; border-left: 5px solid #84c225; width: 0; height: 20px; } .level li div { border: 1px solid #ccc; padding: 5px 10px; text-decoration: none; color: #666; font-family: arial, verdana, tahoma; font-size: 11px; display: inline-block; border-radius: 5px; -webkit-border-radius: 5px; -moz-border-radius: 5px; transition: all 0.5s; -webkit-transition: all 0.5s; -moz-transition: all 0.5s; } .level li div:hover, .level li div:hover+ul li div { background: #c8e4f8; color: #000; border: 1px solid #94a0b4; } .level li div:hover+ul li::after, .level li div:hover+ul li::before, .level li div:hover+ul::before, .level li div:hover+ul ul::before { border-color: #94a0b4; } .main-img { width: 150px; } .sub-img { width: 50px; }
<div class="level"> <ul> <li> <a href="#"> <div> <img src="https://via.placeholder.com/400" class="img-responsive img-circle main-img"> </div> </a> <ul class="sub-level"> <li> <a href="#"> <div> <img src="https://via.placeholder.com/400" class="img-responsive img-circle sub-img"> </div> </a> </li> <li> <a href="#"> <div> <img src="https://via.placeholder.com/400" class="img-responsive img-circle sub-img"> </div> </a> </li> <li> <a href="#"> <div> <img src="https://via.placeholder.com/400" class="img-responsive img-circle sub-img"> </div> </a> </li> <li> <a href="#"> <div> <img src="https://via.placeholder.com/400" class="img-responsive img-circle sub-img"> </div> </a> </li> <li> <a href="#"> <div> <img src="https://via.placeholder.com/400" class="img-responsive img-circle sub-img"> </div> </a> </li> <li> <a href="#"> <div> <img src="https://via.placeholder.com/400" class="img-responsive img-circle sub-img"> </div> </a> </li> <li> <a href="#"> <div> <img src="https://via.placeholder.com/400" class="img-responsive img-circle sub-img"> </div> </a> </li> </ul> </li> </ul> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.