Html 将DIV拉伸到页面宽度
我需要一个div来扩展到HTML文档的整个页面宽度,这取决于它的内容 以下是场景:Html 将DIV拉伸到页面宽度,html,css,internet-explorer,internet-explorer-7,Html,Css,Internet Explorer,Internet Explorer 7,我需要一个div来扩展到HTML文档的整个页面宽度,这取决于它的内容 以下是场景: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Traditional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>testing</title> <style type="tex
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Traditional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>testing</title>
<style type="text/css">
body
{
background-color:pink;
padding:0;
margin:0;
}
#testDiv
{
background-color:red;
}
</style>
</head>
<body>
<div id="testDiv">
<table width="2000px">
<tr>
<td>
test
</td>
</tr>
</table>
</div>
</body>
</html>
测试
身体
{
背景颜色:粉红色;
填充:0;
保证金:0;
}
#testDiv
{
背景色:红色;
}
测试
testDiv将只扩展到浏览器窗口的大小,而不是整个页面本身。我将这种行为用于表格布局,但我更希望有人能提供CSS解决方案。我还需要为IE 7工作的解决方案。试试这个。:)
要扩展到
内部内容的大小,只需将显示
规则设置为内联块
,对于IE7,您还必须包括一些黑客
测试
身体
{
背景颜色:粉红色;
填充:0;
保证金:0;
}
#testDiv
{
背景色:红色;
显示:内联块;
/*IE 7-黑客*/
缩放:1;
*显示:内联;
}
测试
您的HTML缺少一个,您用internet-explorer-7
标记了该问题。你想要一个HTML或IE7的解决方案吗?你是对的;我编辑了这个问题,不幸的是,这个问题不起作用:(.#testDiv仍然只延伸到窗口的宽度。
html {width: 100%; height: 100%; padding: 0; margin: 0;}
body {width: 100%; height: 100%; position: relative; padding: 0; margin: 0;}
#testDiv {width: 100%; height: 100%; position: absolute; top: 0; left: 0;}
<!DOCTYPE html>
<html>
<head>
<title>testing</title>
<style type="text/css">
body
{
background-color:pink;
padding:0;
margin:0;
}
#testDiv
{
background-color:red;
display: inline-block;
/* IE 7- hacks */
zoom: 1;
*display: inline;
}
</style>
</head>
<body>
<div id="testDiv">
test
<div style="width: 2000px"></div>
</div>
</body>
</html>