css - 尽管内部 div 宽度大于 100%,但将内部 div 保持在同一行

标签 css

我正在玩一个幻灯片菜单。我需要内容 div 的宽度为 100%,菜单的宽度为 16%(说来话长)。当然,这会导致内容 div 被推到下一行。有没有一种方法可以使内部 div 保持在同一行,即使总百分比大于 100%,并且内容的右侧部分 div 不在屏幕上?这是 jsfiddle

最佳答案

给一个white-space: nowrap;#container 元素,然后覆盖其子元素上的声明:

EXAMPLE HERE

#container {
    overflow: hidden;
    white-space: nowrap;
}

#container > div {
    vertical-align: top;
    white-space: normal;
}

此外,您可能需要使用 vertical-align: top; 将内联 block 元素(在本例中为列)垂直对齐到 #container.

16.6 White space: the 'white-space' property

This property declares how white space inside the element is handled. Values have the following meanings:

nowrap value
This value collapses white space as for 'normal', but suppresses line breaks within text.

还介意the gap between inline block element . HTML 中的制表符和新行算作一个空格。

关于css - 尽管内部 div 宽度大于 100%,但将内部 div 保持在同一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25621482/

相关文章:

html - 如何 Angular2 @Component 添加 css 和更少?

html - float 未正确 float

html - 具有奇数个元素和固定边距的 flex 网格

javascript - move.js javascript:以设定的间隔重复动画

html - 大屏幕的@media 查询用于小屏幕

html - CSS/HTML 按钮动画不正确

css - 在 React 中设置正文背景颜色

html - 将特定列表元素置于斜体的 CSS 代码(不更改 html 代码)

html - 调整大小后 UIWebView 加载/排序错误

javascript - 使用 jquery 时下拉 selectedindex 不触发