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

时间:2019-04-06 11:06:12

标签: javascript html css

很久以来我一直在尝试使这些列表项水平滚动,但是有人可以帮我使这些列表项滚动而失败。

我需要在此处保留6个项目,在6个项目之后,任何数量的列表项目都将水平滚动。我试图通过谷歌找到解决方案,但不能解决我的问题。所以请帮助我解决这个问题。

Problem Img link

let hondas = realm.objects('Car').max('id');
.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;
}

1 个答案:

答案 0 :(得分:0)

display: flex添加到.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>