Html CSS 没有文字换行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3308365/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CSS no text wrap
提问by Mithun Sreedharan
Please see see code http://jsbin.com/eveqe3/edit, also quoted below.
请参阅代码http://jsbin.com/eveqe3/edit,也在下面引用。
I need to show text inside the item divs in such a way the the text appear only in the green box with specified width rest of the line need to be hidden. Any suggestions please...
我需要以这样的方式在项目 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>?
回答by xor_eq
Additionally to overflow:hidden, use
除了溢出:隐藏,使用
white-space:nowrap;
回答by Macmade
Just use:
只需使用:
overflow: hidden;
white-space: nowrap;
In your item's divs
在您的项目的 div 中
回答by Ahmed Aman
Use the css property overflow . For example:
使用 css 属性 overflow 。例如:
.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-xor overflow-y.
溢出属性可以具有许多值之一,例如 ( hidden, scroll, visible) .. 您还可以仅使用overflow-x或overflow-y控制一个方向的溢出。
I hope this helps.
我希望这有帮助。