如何在第六个列表项后使列表项水平滚动?

3

我已经尝试了很长时间使这些列表项水平滚动,但是失败了,有人可以帮助我使这些列表项滚动吗?

我需要在这里保留6个项目,在第6个项目之后,任意数量的列表项将水平滚动。我尝试通过谷歌找到解决方案,但无法解决我的问题。因此,请大家帮助我解决这个问题。

问题图片链接

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

1个回答

1
.level ul添加display: flexflex容器默认情况下是非换行的)- 请参见下面的演示:

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


谢谢您的帮助,我在我的代码中添加了这个,但它让我的列表项变得更小了。 - Rashed Raj
在上面的代码片段中添加了一些占位图像... sub-img 元素上有 width: 50px,也许这就是问题所在? - kukkuz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接