我有这个代码,但奇怪的是max-width和属性不起作用: HTML: body img src="imgs/topBar.png" div id ="wrapper" /div/body CSS: body { padding: 0; margin: 0;}body img:first-child{ width: 100%; height: 5px; margin:0; display: b
HTML:
<body> <img src="imgs/topBar.png"> <div id ="wrapper"> </div> </body>
CSS:
body { padding: 0; margin: 0; } body img:first-child{ width: 100%; height: 5px; margin:0; display: block; } #wrapper { width: 100%; max-width: 1200px; height: 100px; margin: 0 auto; border: 4px solid; }
我做了一个http://jsfiddle.net/vkdbq/
你可以设置:#wrapper { -webkit-box-sizing: border-box; /* Safari, other WebKit */ -moz-box-sizing: border-box; /* Firefox, other Gecko */ box-sizing: border-box; /* Opera/IE 8+ */ width: 100%; max-width: 1200px; height: 100px; margin: 0 auto; border: 4px solid; }