如何用css限制字数?

html-css012

如何用css限制字数?,第1张

你好,CSS是设置样式的,css不能限制字数,只能多出了隐藏。overflow:hidden

一行可以实现省略号:

overflow: hidden

white-space: nowrap

text-overflow: ellipsis

案例

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Document</title>

<style>

.box {

width: 900px

background-color: #eee

border: 1px dashed #ccc

margin: 0 auto

}

.top {

height: 80px

}

.banner {

height: 120px

/*margin: 0 auto*/

margin: 5px auto

}

.main {

height: 500px

}

.footer {

height: 100px

/*margin: 0 auto

margin-top:5px*/

margin: 5px auto 0

}

</style>

</head>

<body>

<div class="top box">top</div>

<div class="banner box">banner</div>

<div class="main box"></div>

<div class="footer box"></div>

</body>

</html>