CSS 没有文本换行

请参阅代码 http://jsbin.com/eveqe3/edit,也引用如下。

我需要显示文本内的项目 div 在这样的方式,文本出现在绿色框指定的宽度休息行需要隐藏。有什么建议吗。

<style>
#container{
width : 220px;
}
.item{
float:left;
border: 1px solid #0a0;
width: 100px;
height: 12px;
padding 2px;
margin: 0px 2px;
}
.clearfix{
clear: both;
}
</style>
</head>
<body>
<div id="container">
<div class="item"> A very loooooooooooooooooooooong text </div>
<div class="item"> Another looooooooooooooooooooong text </div>
<div class="clearfix">  </div>
</div>
</body>
</html>​
162836 次浏览

Just use:

overflow: hidden;
white-space: nowrap;

In your item's divs

Use the css property overflow . For example:

  .item{
width : 100px;
overflow:hidden;
}

The overflow property can have one of many values like ( hidden , scroll , visible ) .. you can als control the overflow in one direction only using overflow-x or overflow-y.

I hope this helps.

Additionally to overflow:hidden, use

white-space:nowrap;