<ul> <li>上的水平滚动

时间:2018-03-28 13:42:06

标签: html css css3

我想在Facebook Messenger中创建快速回复。您可以在下图中看到结果:
enter image description here

这是我使用的.css和HTML:

&#13;
&#13;
.quick_replies {
  display: inline;
  clear: both;
  padding: 10px;
  border-radius: 30px;
  margin-bottom: 2px;
  font-family: Helvetica, Arial, sans-serif;
  border: solid 2px #86BB71;
}
&#13;
<ul style="white-space:nowrap;margin-bottom: 10px;">
  <li class="quick_replies">Réponse 1</li>
  <li class="quick_replies">Réponse 2</li>
  <li class="quick_replies">Réponse 3</li>
  <li class="quick_replies">Réponse 4</li>
  <li class="quick_replies">Réponse 5</li>
  <li class="quick_replies">Réponse 6</li>
  <li class="quick_replies">Réponse 3</li>
  <li class="quick_replies">Réponse 7</li>
  <li class="quick_replies">Réponse 8</li>
</ul>
&#13;
&#13;
&#13;

如何使用这些快速回复创建水平滚动并且不要让它们放大容器div?

1 个答案:

答案 0 :(得分:3)

您需要为overflow:auto添加宽度overflow:scroll(或ul}:

&#13;
&#13;
ul {
  width: 100%;
  overflow: auto;
}

.quick_replies {
  display: inline-block;
  clear: both;
  padding: 10px;
  border-radius: 30px;
  margin-bottom: 2px;
  font-family: Helvetica, Arial, sans-serif;
  border: solid 2px #86BB71;
}
&#13;
<ul style="white-space:nowrap;margin-bottom: 10px;">
  <li class="quick_replies">Réponse 1</li>
  <li class="quick_replies">Réponse 2</li>
  <li class="quick_replies">Réponse 3</li>
  <li class="quick_replies">Réponse 4</li>
  <li class="quick_replies">Réponse 5</li>
  <li class="quick_replies">Réponse 6</li>
  <li class="quick_replies">Réponse 3</li>
  <li class="quick_replies">Réponse 7</li>
  <li class="quick_replies">Réponse 8</li>
</ul>
&#13;
&#13;
&#13;