2010-11-19 68 views
0

如何設置一個背景直到頁面的一半,另一個背景從頁面的一半開始直到結束,而內容div仍然位於頁面的正中間? 請添加一個例子!如何使用CSS設置自定義兩個背景?


<body><div id="right"><div id="content"></div></div></div> 

CSS

body{ background:url("../a.gif") repeat-x scroll left top transparent;height:632px;} 

right{background:url("../r.jpg") repeat-x scroll right top transparent;margin-left:50%;width:100%;} 

content{width:980px;} 

問題 - 背景放置好,但內容DIV是不是在頁面中間....

任何解決辦法?

+1

可以從自己的嘗試粘貼代碼? – drudge 2010-11-19 21:39:41

回答

1

用CSS3:

html{ 

background: url(http://placehold.it/50x50) top left no-repeat, 
url(http://placehold.it/50x50) top right no-repeat; 

} 

http://jsfiddle.net/jfkqd/

中心水平與

.content{ 
margin:0 auto; 
width:200px; 
height:200px; 

}

(需要text-align:center;在IE工作)

水平和垂直中心:

.content{ 
width:300px; 
height:200px; 
position:absolute; 
left:50%; 
top:50%; 
margin:-100px 0 0 -150px; 

}

+0

我需要相同的CSS2 – user513991 2010-11-19 21:44:48

+0

你將不得不發佈一個例子。用css2你最終會需要另一個div和設置寬度等。 – 2010-11-19 21:46:33

+0

@Grillz不,你不需要;看我的帖子。 – zzzzBov 2010-11-19 21:47:13

1

沒有CSS3:

html 
{ 
    background: url(...) x y repeat;//x and y for wherever it needs to start, repeat can be any value, up to you. 
} 

body 
{ 
    background-image: url(...) top left repeat-x; // or no-repeat if you only want it once 
} 
+0

聰明(和15個字符) – Xodarap 2010-11-19 22:00:56