关于Div中内容布局
首先在Div中高度固定 宽度自动 里面添加文字 如图:
如果文字过长就自动扩充宽度达到如下图所示:
希望能给出代码 谢谢
------解决方案--------------------<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>首页</title>
<style>
#d1{ height:300px; border:1px solid red}
</style>
</head>
<body>
<input type="text" id="txt" value="啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦"/> <input type="button" onclick="check()" />
<div id=d1></div>
<script>
function check() {
document.getElementById("d1").innerHTML = document.getElementById("txt").value;
var str = document.getElementById("d1").innerHTML.toString();
if (str.length > 10) {
document.getElementById("d1").style.width = "300px";
}
else {
document.getElementById("d1").style.width = "50px";
}
}
</script>
</body>
</html>
希望对你有帮助
------解决方案--------------------<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>首页</title>
<style>
#d1
{
height: 100px;
width: 50px;
&nbs