html - CSS 溢出-x : visible; and overflow-y: hidden; causing scrollbar issue

标签 html css overflow

假设你有一些样式和标记:

ul
{
  white-space: nowrap;
  overflow-x: visible;
  overflow-y: hidden;
/* added width so it would work in the snippet */
  width: 100px; 
}
li
{
  display: inline-block;
}
<div>
  <ul>
    <li>1</li> <li>2</li> <li>3</li>
    <li>4</li> <li>5</li> <li>6</li>
    <li>7</li> <li>8</li> <li>9</li>
    <li>1</li> <li>2</li> <li>3</li>
    <li>4</li> <li>5</li> <li>6</li>
    <li>7</li> <li>8</li> <li>9</li>
    <li>1</li> <li>2</li> <li>3</li>
    <li>4</li> <li>5</li> <li>6</li>
    <li>7</li> <li>8</li> <li>9</li>
  </ul>
</div>

当您查看此内容时。 <ul>即使我为溢出 x/y 指定了可见和隐藏值,底部也有一个滚动条。

(在 Chrome 11 和 Opera (?) 上观察到)

我猜肯定有一些 w3c 规范或某些东西告诉我会发生这种情况,但我这辈子都不知道为什么。

JSFiddle

更新:-我找到了一种方法来实现相同的结果,方法是在 ul 周围添加另一个元素。 . Check it out.

最佳答案

经过一番认真的搜索,我似乎找到了问题的答案:

来自:http://www.brunildo.org/test/Overflowxy2.html

In Gecko, Safari, Opera, ‘visible’ becomes ‘auto’ also when combined with ‘hidden’ (in other words: ‘visible’ becomes ‘auto’ when combined with anything else different from ‘visible’). Gecko 1.8, Safari 3, Opera 9.5 are pretty consistent among them.

还有 W3C spec说:

The computed values of ‘overflow-x’ and ‘overflow-y’ are the same as their specified values, except that some combinations with ‘visible’ are not possible: if one is specified as ‘visible’ and the other is ‘scroll’ or ‘auto’, then ‘visible’ is set to ‘auto’. The computed value of ‘overflow’ is equal to the computed value of ‘overflow-x’ if ‘overflow-y’ is the same; otherwise it is the pair of computed values of ‘overflow-x’ and ‘overflow-y’.

短版:

如果您将 visible 用于 overflow-xoverflow-y 以及 visible 以外的其他内容另一方面,visible 值被解释为 auto

关于html - CSS 溢出-x : visible; and overflow-y: hidden; causing scrollbar issue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6421966/

相关文章:

html - 更改了通用兄弟组合器以切换伪元素 : what is valid

Javascript 使用 localStorage 获取表单元素值返回 null

html - iPad 上的 iOS UIWebView 窗口宽度和高度

c - 如果存在明显的溢出可能性,我是否应该手动类型转换为更高的类型?

javascript - Angular 5 document.querySelector ('ClassName' ).innerHTML 不包含内联的 css

php - 如何使导航栏跨多个页面保持不变?

css - css Sprite 问题

javascript - 授权 header 行为的说明

html - Box-Shadow 如果表格单元格溢出

javascript - 如何限制可拖动区域?它在顶部和左侧起作用,但在右侧和底部不起作用