我正在尋找檔案和整個下面的文章約how to center a div within a div,這裏的解決方案是以下樣式應用於內部的div來到內中心一個div功能回答說,margin:auto
是導致居中的原因。這是如何工作的?保證金:</p> <pre><code>#inner { width: 50%; margin: auto; } </code></pre> <p>的:汽車在一個div
2
A
回答
1
margin:auto;
專門設計用於自動設置邊距,通常用於居中元素的目的。它實際上只適用於左右邊距。使用margin:auto;
以下簡寫:
{ margin:0px auto 0px auto; }
爲了進一步闡明瞭這一點:
{ margin-top:0px; margin-right:auto; margin-bottom:0px; margin-left:auto; }
退房的CSS2 spec。
0
它基本上解決方程margin = ("outer-width" - "inner-width")/2
並將結果設置爲邊距值。
結果是,您的內部div的邊距在兩側都是相同的,並且其整體寬度(寬度+ 2×邊框+ 2×邊距)完全填充您的外部div。所以它的身體居中。
相關問題
- 1. 汽車中心<div><div></div></div>
- 2. 使用margin時使用float:0 auto;使用</p> <pre><code>margin:0 auto; </code></pre> <p>在一個div</p> <p>內部的事業部
- 3. git「<<<<<<< HEAD」
- 4. 「<<<<<<< HEAD」模板
- 5. Heredoc <<<或<<?
- 6. 鉻</p> <pre><code><div id="wrapper"> <div id="content"> </div> </div> </code></pre> <p>的包裝DIV嵌套的div失靈在Chrome
- 7. github增加<<<<<<< HEAD
- 8. operator <<:std :: cout << i <<(i << 1);
- 9. <div><a /></div> instead of <button />?
- 10. << <<超載
- 11. 什麼意思的符號在java中「<<<」「<< =」「<<」
- 12. 怎麼了SVN把「<<<<<<<.mine」遍佈整個地方?
- 13. 浮動元素<br /><br /><br /><br /><br /\><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
- 14. 如何使文本去下一行,當即將在<code>index.html</code>文件</p> <pre><code><div id = "quote"> quote text </div> <div id = "text"> text </div> </code></pre> <p>重疊元素
- 15. 的Rails搞亂我的代碼以「<<<<<<< HEAD」
- 16. 什麼是我的檔案中的「<<<<<<< head」?
- 17. 如何阻止滾動條移動我的頁面?</p> <pre><code>#wrapper { width: 960px; margin-left: auto; margin-right: auto; } </code></pre> <p>的問題是:每當含量的增加和垂直滾動條出現,它取代
- 18. 使用>>,>,> |,||,| <,<,<<,<<
- 19. 'std :: operator <<'operator <<'不匹配'std :: operator <<
- 20. std :: cout << x;和std :: cout << x << std :: endl;?
- 21. 如何刪除</p> <pre><code><div id="invoice"></div> <div id="claim"></div> <div id="draft"></div> </code></pre> <p>通過隱藏層
- 22. 在<和<=
- 23. 確實<textarea> auto-encode inner html?
- 24. THREE.Camera.prototype.lookAt</ <() -</ <是什麼意思?
- 25. <%$,<%@,<%=,<%#...這是怎麼回事?
- 26. 分層<div></div>
- 27. ASP.NET <%#與<%
- 28. 做一個<br>而不是<div></div>按Enter鍵在CONTENTEDITABLE
- 29. 引導旋轉木馬類暢飲,內動態添加</p> <pre><code><div class = "active item"><img ..></div> <div class = "item"><img ..></div> <div class = "item"><img..</div> </code></pre> <p>,而不是初始化
- 30. 使<b></b><i></i><u>在文本框</u>和<br>