css - 是否可以用 css 创建不同的溢出子项?

标签 css

假设我有 div a,其中包含 n div元素 n..b,c;我想要那个div a 将为每个元素 ( overflow: scroll ) 获取滚动条,除了元素 c 应该是 overflow: visible .

我可以只使用 CSS 来实现吗?

为了让您更清楚,这就是我要实现的目标 https://jsfiddle.net/gm6cgyqp/除了 fixed 不响应滚动这一事实。我正在尝试使用引导下拉菜单实现与 native 选择相同的感觉,这就是我遇到此类问题的方式。

最佳答案

是的,这是可以做到的。将 max-height 和 max-width 设置为您想要滚动条的 div。

.wrap {
  width: 100%;
}
.a,
.b,
.c,
.d {
  max-width: 20%;
  overflow: scroll;
  display: inline-block;
  max-height: 100px;
}
.e {
  overflow: visible;
  width: 20%;
}
<div class="wrap">
  <div class="a">
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
    survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing
    software like Aldus PageMaker including versions of Lorem Ipsum.
  </div>
  <div class="b">
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
    survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing
    software like Aldus PageMaker including versions of Lorem Ipsum.
  </div>
  <div class="c">
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
    survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing
    software like Aldus PageMaker including versions of Lorem Ipsum.
  </div>
  <div class="d">
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
    survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing
    software like Aldus PageMaker including versions of Lorem Ipsum.
  </div>
  <div class="e">
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
    survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing
    software like Aldus PageMaker including versions of Lorem Ipsum.
  </div>
</div>

关于css - 是否可以用 css 创建不同的溢出子项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31271384/

相关文章:

javascript - 如何为具有特定类的嵌套和同级 div 设置交替颜色。

css - 如何将 "$"字符串添加到内插值?

javascript - 现代浏览器是否会阻止 <a href="javascript :window. open....?

css - Div容器在另一个容器后面

css - 如何在wordpress中覆盖css样式

html - CSS - 按值隐藏按钮

html - 定义图像的宽度和高度是否违反 Material 设计思想?

html - 如何制作类似 Twitter-Bootstrap 的按钮

html - 什么是 -moz-padding-start 和 html.css ?无法摆脱这种填充

css - 如何使用CSS和webkit制作动画