开发者

CSS Fix container and overflow elements

Iam wondering if it is a way开发者_开发百科 to force overflow elements of an fixed container to be on the same line instead of going on a new line.

http://jsfiddle.net/vrSRE/3/

Thank you.


Yes, there's a way.

You have to replace, float: left with display: inline-block, and add white-space: nowrap to the parent element:

See: http://jsfiddle.net/vrSRE/4/

ul {
    width: 300px;
    height: 30px;
    background: red;
    white-space: nowrap
}
li {
    display: inline-block
}

If you don't want any space between the elements, the easiest way to fix this new problem is to remove the whitespace in the HTML, like this:

  • http://jsfiddle.net/vrSRE/6/

For other options that you probably don't care about to remove the space, see:

  • How to remove the space between inline-block elements?

And lastly, if you care about IE7 support, use this:

  • http://jsfiddle.net/vrSRE/7/


See: http://jsfiddle.net/keBFd/

You can use white-space: nowrap and display: inline - you might not want display: inline, though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜