2013-03-27 69 views
1

我正在与中心包装(以margin 0 auto为中心)战斗。现在我想从左边开始一个容器,直到中间包装器开始。根据这个给定的保证金规格,这是否可能?有没有一种方法可以覆盖保证金余额,尽管有保证金:0与CSS自动?

我真的很感激一些提示!

也看到了小提琴: http://jsfiddle.net/TQhEa/1/

我现在拥有的一切: enter image description here

我想拥有什么:

enter image description here

我的代码:

<body> 
    <div id="page-wrapper"> 
     <p><---- how can i cover the left side only with red without javascript but keeping the "0 auto margin?" 

    </div> 
</body> 

我的CSS:

body, html{ 
     width:100%; 
     height:100%; 
     top:0; 
     margin:0; 
     background-image: url('http://www.art-wallpaper.net/Full-Size-HD-Wallpaper29/images/HD%20Widescreen%20Wallpaper%2059.jpg'); 
     background-repeat:no-repeat; 
     -webkit-background-size: cover; 
     -moz-background-size: cover; 
     -o-background-size: cover; 
     background-size: cover; 

} 
#page-wrapper{ 
    background-color:red; 
    margin: 0 auto; 
    width: 400px; 
    top:0; 
    margin-top:0; 
    height:100%; 
} 
p { 
    padding:0; 
    margin:0; 
    font-size:30px; 
} 
} 
+1

您可以将第二个框放在左侧50%宽。 – gaynorvader 2013-03-27 09:59:26

回答

1

最简单的方法是设置background-colorbackground-image的位置。退房this piece of codeHTML

<div id="page-wrapper">content</div> 

CSS

body { 
    margin: 0; 
    background: #c11 url(http://placekitten.com/1000/1000) 100% 0 no-repeat; 
} 
#page-wrapper { 
    width: 400px; 
    height: 1000px; 
    background: #ccc; 
    margin: 0 auto; 
} 
+0

这是一个非常有趣的方法...你知道,如果这是为7-10? – Jurudocs 2013-03-27 10:09:08

+0

它应该。这里没有什么IE浏览器不明白。 ;) – 2013-03-27 10:18:07

+0

只是一点点:当调整窗口的大小时,背景不调整... – Jurudocs 2013-03-27 10:44:21

1

添加1更多的DIV与下面的CSS:

#left_div { 
    position: absolute; 
    left: 0; 
    top: 0; 
    width: 50%; 
    height: 100%; 
    background-color: #F00; 
    display: table; /* note IE5-7 does not support this */ 
    z-index: 1; 
} 

和修改当前的中心DIV $('#page-wrapper')有较高z-index