white-space: pre-wrap!important
word-wrap: break-word!important
*white-space:normal!important
}
一般需要用到JQuery来控制pre的文字字体大小:
<!DOCTYPE html><html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<script src="
<script type="text/javascript">
$(function(){
var domH = $('.msg').height()
//外框的高度
var fsize = domH/3
//要改变的文字尺寸
$('.donH').html('外框高度为:'+domH+'px'+','+'文字大小为:'+fsize+'px')
$('.word').css('font-size',fsize)//改变文字的size
})
</script>
<style type="text/css">
* {
margin: 0
padding: 0
}
.demo{
margin: 0 0 0 100px
}
.msg {
width: 300px
text-align: center
box-sizing: border-box
border: 1px solid #000000
}
</style>
<body>
<div class="demo">
<div class="donH">
</div>
<div class="msg">
示例文字<br> 随外框高度改变的文字:
<strong class="word" style="color: red">9999元</strong>
</div>
</div>
</body>
</html>
css pre加了 强制换行怎么不可以比如,指定宽度为200px换行代码:
overflow: visible
width:200px
word-wrap:break-word
white-space:-moz-pre-wrap
针对IE7的强制换行代码:
word-wrap:break-word
针对火狐的强制换行代码:
white-space:-moz-pre-wrap
<script>
function toBreakWord(intLen){
var obj=document.getElementById("ff")
var strContent=obj.innerHTML
var strTemp=""
while(strContent.length>intLen){
strTemp+=strContent.substr(0,intLen)+"<br>"
strContent=strContent.substr(intLen,strContent.length)
}
strTemp+="<br>"+strContent
obj.innerHTML=strTemp
}
if(document.getElementById &&!document.all) toBreakWord(37)
</script>