2016-08-14 106 views
-3

我正在使用w3.css,我想製作一個寬度爲100%的彩色背景,
並在其中放置另一個寬度爲80%的盒子,其中包含文本,所以就用以下:W3.CSS如何使容器居中在另一個容器內

<div class="w3-container w3-light-green"> 
<div class="w3-container w3-sand w3-center" style="width:80%"> 
test 
</div> 
</div> 

的問題是,與80%的寬度的第二容器中的頁面不居中雖然我用W3-中心。 我注意到w3-centre只是文本的中心,但是容器本身沒有居中,所以我怎樣才能將容器塊居中呢?

+0

您能否提供至少一項來自您的工作,以便我們可以幫助您解決代碼中的問題? –

+0

我現在編輯我的帖子 –

+0

添加小提琴或代碼段代碼,所以我們可以幫助你出來.. – Abhishek

回答

0

我認爲這應該工作..試試看..

<div class="w3-container w3-light-green"> 
<div class="w3-container w3-sand w3-center" style="width:80%;margin:auto;"> 
test 
</div> 
</div> 
+0

它的確如此,非常感謝你 –

-1

我不知道很多關於w3.css有可能是原生解決這一點,但如果你喜歡有哈克事情是這樣的:

<!DOCTYPE html> 
<html> 
<meta name="viewport" content="width=device-width, initial-scale=1"> 
<link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css"> 
<body> 
<div class="w3-container w3-light-green" style="text-align: center"> 
<div class="w3-container w3-sand w3-center" style="width:80%; display: inline-block;"> 
test 
</div> 
</div> 
</body> 
</html> 

https://jsfiddle.net/k2j676ba/

+0

仇恨者會討厭。尊重答案如果你覺得沒有用,那麼解釋一下爲什麼在你downvote –

+0

感謝所有的幫助,這是我第一次在這裏在stackoverflow,所以我不知道這裏很多,但我沒有downvote任何人,我只是一個答案因爲它解決了我的問題。 –

+0

我沒有提到你或任何人。我很高興你解決了你的問題。祝你有美好的一天。 –

0

W3.CSS沒有類定心塊元素。唯一具有其他效果的類也是如此。

您需要設置左右頁邊空白才能自動運行。

相關問題