为了账号安全,请及时绑定邮箱和手机立即绑定

在某个断点 CSS 后使溢出滚动

在某个断点 CSS 后使溢出滚动

慕盖茨4494581 2023-10-30 20:05:39
我有以下代码,其中容器中有(可变)数量的按钮,调整屏幕大小时按钮的位置正确调整为容器的宽度,但我想要实现的是在某个断点处,按钮应该停止重新定位自己,而是让容器滚动overflow-y,并将按钮保持在其位置。.container {  max-width: 800px;  background-color: beige;}.btn {  width: 80px;}.btn span{  white-space: nowrap;  overflow: hidden;  text-overflow: ellipsis;  display: block;}<div class="container">  <button class="btn"><span>test</span></button>  <button class="btn"><span>test123</span></button>  <button class="btn"><span>test450354053</span></button>  <button class="btn"><span>test23R02020202</span></button>  <button class="btn"><span>test33030494</span></button>  <button class="btn"><span>test403930390</span></button>  <button class="btn"><span>test</span></button>  <button class="btn"><span>test23423049</span></button>  <button class="btn"><span>testé</span></button>  <button class="btn"><span>test2340</span></button>  <button class="btn"><span>test234234</span></button>  <button class="btn"><span>test2342</span></button>  <button class="btn"><span>test2342020</span></button>  <button class="btn"><span>test2202349</span></button>  <button class="btn"><span>testé</span></button>  <button class="btn"><span>test234029</span></button>  <button class="btn"><span>test20203030</span></button>  <button class="btn"><span>test340</span></button>  <button class="btn"><span>test234240</span></button>  <button class="btn"><span>test2342340</span></button>  <button class="btn"><span>test23420420</span></button></div>
查看完整描述

1 回答

?
泛舟湖上清波郎朗

TA贡献1818条经验 获得超3个赞

在这个特定的例子中,min-width带有给定断点(例如400px)并overflow: auto设置在.container将工作正常


.container {

  max-width: 800px;

  min-width: 400px;

  overflow: auto;

  background-color: beige;

}


.btn {

  width: 80px;

}

.btn span{

  white-space: nowrap;

  overflow: hidden;

  text-overflow: ellipsis;

  display: block;

}

<div class="container">

  <button class="btn"><span>test</span></button>

  <button class="btn"><span>test123</span></button>

  <button class="btn"><span>test450354053</span></button>

  <button class="btn"><span>test23R02020202</span></button>

  <button class="btn"><span>test33030494</span></button>

  <button class="btn"><span>test403930390</span></button>

  <button class="btn"><span>test</span></button>

  <button class="btn"><span>test23423049</span></button>

  <button class="btn"><span>testé</span></button>

  <button class="btn"><span>test2340</span></button>

  <button class="btn"><span>test234234</span></button>

  <button class="btn"><span>test2342</span></button>

  <button class="btn"><span>test2342020</span></button>

  <button class="btn"><span>test2202349</span></button>

  <button class="btn"><span>testé</span></button>

  <button class="btn"><span>test234029</span></button>

  <button class="btn"><span>test20203030</span></button>

  <button class="btn"><span>test340</span></button>

  <button class="btn"><span>test234240</span></button>

  <button class="btn"><span>test2342340</span></button>

  <button class="btn"><span>test23420420</span></button>


</div>


查看完整回答
反对 回复 2023-10-30
  • 1 回答
  • 0 关注
  • 91 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信