简体   繁体   English

如何使列表项溢出后6列表项水平滚动?

[英]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. 所以请帮助我们解决这个问题。

Problem Img link 问题Img链接

 .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.

相关问题 反应:在水平滚动后添加 className=&quot;active&quot; 到列表项(css: overflow-x: scroll;) - React: add className="active" to list item after horizontal scroll (css: overflow-x: scroll;) 当只有特定列表具有溢出属性但父溢出被隐藏时,如何滚动到特定的活动项目? - How to scroll to a particular active item in react when only that particular list is having overflow property but the parent overflow is hidden? 如何在行内阻止列表项目中将第一个项目水平居中 - How to horizontally center the first item in a inline-block list item 如何使此列表项“缩放” - How to make this list item “zoom” 如何使列表的第一项始终位于顶部,而列表的其余部分将独立于它滚动 - How to make the first item of the list always be at the top and the rest of the list will scroll independently of it 滚动到列表中的特定项目,然后滚动到列表中的下一个特定项目 - Scroll to specific item in the list and then scroll to next specific item in the list 滚动无序列表到最新项目 - Scroll Unordered List to the latest item 离子滚动到特定列表项 - Ionic Scroll To Specific List Item 列表项位置不变滚动 - List Item Position Not Change On Scroll 离子列表项文本溢出,无法调整列表项的高度 - Ionic list item text overflow not adjusting the height of the list item
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM