• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
渴爱网のWebMaster 's Blog【Welcome to my website : KIIK.TOP 】
Go ahead man ! I just wanna achieve what i wanted man.
Tips:1.Do a excellent programmer who can hacking and build awesome program
     2.Became a designer who can make everything which nearby me looks like so charming.
博客园    首页    新随笔    联系   管理    订阅  订阅

如何实现区域内横向滚动条?

//css

body{
  background-color: #333;
}
.area{
  width: 300px;
  height: 100px;
  margin: 40px auto;
  background-color: rgba(250,250,250,0.4);
  /*2.再添加white-space:nowrap [会让内联元素]*/
  white-space: nowrap;
  overflow: scroll;
}
.area .item{
  /*1.首先将子元素修改为内联元素*/
  display: inline-block;
  width: 46px;
  height: 96px;
  background-color: rgba(230,230,120,0.8);
  margin: 2px;
}

/html
<div class="area">
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></div>
</div>

 

总结:将子元素变成inline-block元素 父元素设置white-space:no-wrap【子元素会被当成文字一样不会换行,再设置一个overflow:scroll就可以了】

posted @ 2020-09-24 20:31  kiik  阅读(514)  评论(1)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3