2013-03-27 70 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