css文字过长显示的几种方案

html-css015

css文字过长显示的几种方案,第1张

1、默认情况,它是自动换行的;

2、设置文字不换行white-space:nowrap,强行撑开;

3、如果不希望容器被撑开,那就给文字加省略号:

<style type="text/css">

.divbox{ width:150px white-space:nowrap overflow:hidden text-overflow:ellipsis}

</style>

</head>

<body>

<div class="divbox">文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字</div>

</body>

这个是可以的,将div的宽和高固定然后使用overflow:hidden 可以把溢出的字符影藏

例:

<div style="width:20pxheight:20pxoverflow:hidden">

111111111111111111111111111111111111111111111111111111111111111111111111111

</div>