CSS:Parent-Div不与它的孩子一起成长(水平)

vyd*_*_st 15 css parent width

我希望parent-div(红色)与绿色的child-div一起成长.现在它只停在视口处.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="de" xmlns="http://www.w3.org/1999/xhtml" xml:lang="de">
<head>
<title>simple document</title>
<style type="text/css">
 * {
  font-family: verdana;
  margin: 0px;
  padding: 0px;
 }
</style>
</head>
<body>
<div style="margin: 30px; background: red; padding: 10px;">
 <div style="background: green; width: 2000px;">dxyf</div>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我不想使用display:table; 因为它在IE中不能很好地工作.

有任何想法吗?

Jos*_*ola 28

display: inline-block;在父级上使用<div>它将按预期工作

  • Quirksmode(http://www.quirksmode.org/css/display.html)表示你不能在IE 6和7中默认使用`display:inline`的元素上使用`inline-block`显示你在那些测试过吗? (3认同)