在css中,可以使用white-space属性来强制文字不换行;通常我们使用white-space:nowrap来强制文本文字内容不换行,文本会在在同一行上显示,直到遇到 <br> 标签为止。
white-space属性设置或检索对象内文本显示方式。
语法:
white-space : normal | nowrap;
属性值:
normal:默认。空白会被浏览器忽略。
nowrap:文本不会换行,文本会在在同一行上继续,直到遇到 <br> 标签为止。
示例1:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <style type="text/css"> div { width: 120px; height: 60px; line-height: 20px; border: 1px dashed #ccc; margin: 10px; } .demo { white-space: nowrap } </style> </head> <body> <div>内容将会不被换行显示</div> <div class="demo">内容将在一行内强制显示完整</div> </body> </html>
效果图:
以上就是css如何让中文不换行?的详细内容,更多请关注0133技术站其它相关文章!