父div随着子div的增高而增高

建安 2012-02-24 05:16:18
我有父div的样式如下:
.parent {
margin:auto;
width:800px;
border:1px solid #ccc;

}
子div的样式:
.a {
width:220px;
border-style:none;
float:left;
margin:20px;
padding-top:5px;
background-color:#99CCFF;
}
代码:
<div class="parent">
<div class="a">asdfadsfasdfadf</div>
</div>为什么当我随着子div里的内容越来越多的时候,父div不会随着增高呢?
...全文
408 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
建安 2012-02-27
  • 打赏
  • 举报
回复
<br style="clear:both;" />
这句代码果然有用,谢谢了,非常感谢
[Quote=引用 7 楼 luo_w_j 的回复:]
你要清除浮动:
<div class="parent">
<div class="a">asdfadsfasdfadf</div>
<br style="clear:both;" />
</div>
[/Quote]
四叶草颖 2012-02-25
  • 打赏
  • 举报
回复
你要清除浮动:
<div class="parent">
<div class="a">asdfadsfasdfadf</div>
<br style="clear:both;" />
</div>
建安 2012-02-25
  • 打赏
  • 举报
回复
这个我试过,不行,问题的关键是在当我不在parent里加float:left里,有一个margin:auto 能让它居中,但在页面上看不到 子div是在父div里面的,[Quote=引用 2 楼 imtns59521 的回复:]

CSS code

.parent {
margin:auto;
width:800px;
border:1px solid #ccc;
height:auto; //把高度设置成自动 ???
}
[/Quote]
色拉油 2012-02-24
  • 打赏
  • 举报
回复
你给限定高度了,用width:100%
完全用子div撑开
hellNo 2012-02-24
  • 打赏
  • 举报
回复

<div class="parent">
<div class="a">asdfadsfasdfadf</div>
<div class="clear"></div>
</div>


.clear{
height:1px;
overflow:hidden;
clear:both;
}
ddcatlee 2012-02-24
  • 打赏
  • 举报
回复
google 闭合浮动元素
hellNo 2012-02-24
  • 打赏
  • 举报
回复

.parent {
margin:auto;
width:800px;
border:1px solid #ccc;
height:auto; //把高度设置成自动 ???
}
建安 2012-02-24
  • 打赏
  • 举报
回复
补充:当我在parent里加了float:left;后,整个页面又不是居中了。所以不知道怎么解决,还请各位大侠帮帮忙。
在线编辑器 <script language="javascript"> var txt = ""; var t = ""; window.onload = function(){ editconfig(); EditArea.document.body.contentEditable="true"; EditArea.focus(); edit(); } function $(id){ return document.getElementById(id); } function code(){ if(t == "c") return; txt = EditArea.document.body.innerHTML; EditArea.document.body.innerText = txt; tag.innerHTML = "当前为代码模式"; EditArea.focus(); t = "c"; } function edit(){ if(t == "e") return; txt = EditArea.document.body.innerText; EditArea.document.body.innerHTML = txt; tag.innerHTML = "当前为设计模式"; EditArea.focus(); t = "e"; } function adding(){ var i = parseInt($("EditArea").style.height) + 100; $("EditArea").style.height = i; try{ parent.document.getElementById("xF").style.height = parseInt(parent.document.getElementById("xF").style.height)+100; } catch(e) { //alert(e.message); } } function subtract(){ var i = parseInt($("EditArea").style.height) - 100; if(i <= 0) return; $("EditArea").style.height = i; try{ parent.document.getElementById("xF").style.height = parseInt(parent.document.getElementById("xF").style.height)-100; } catch(e) { //alert(e.message); } } function editconfig(){ try{ var x = parseInt(parent.document.getElementById("xF").style.width); var y = parseInt(parent.document.getElementById("xF").style.height); $("EditArea").style.width = x-5; $("EditArea").style.height = y-30; } catch(e) { //alert(e.message); } }
<div style="position:absolute; top:5px; left:0px; width:160px;">设计模式 代码模式div> <div id="tag" style="position:absolute; top:7px; left:130px; color:red; font-size:12px;">div> <div style="position:absolute; top:5px; right:0px;"> div>
test.html『测试页面,访问这个页面看效果』 test my documents <script language="javascript"> function chk(){ xF.document.getElementById("btnHtml").click(); var str = xF.EditArea.document.body.innerHTML; form1.x.value = str; if(form1.x.value == ""){ alert("请输入内容"); xF.EditArea.focus(); return false; } }

chk.asp『处理页面,接收传过来的值』 test <%=Request.Form("x")%> body.html 『模拟多行文本域的页』 无标题文档

61,112

社区成员

发帖
与我相关
我的任务
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
  • HTML(CSS)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧