我有一個類似的問題,其中容器在佈局中使用,罰款大多數頁面,但我想在該容器內奇怪的全寬元素。
從Bootstrap 3開始,您可以使用.container-fluid
類來獲得100%寬度的內容。但是,在.container
內使用此功能不會產生任何效果,因爲它受限於寬度.container
。這裏有幾個選項/解決方法我遇到:
使用部分
如果寬度爲100%的內容將在容器內容的開頭或結尾總是習慣,你可以在頁面佈局定義部分,並在其中插入100%寬度的元素。
佈局:
<div class="container-fluid">
@RenderSection("containerFluid", required: false)
</div>
<div class="container">
@RenderBody()
</div>
查看:
@section containerFluid
{
<div>Full width content.</div>
}
<div>Other content</div>
在你的情況,如果你有這樣的一個頁面上沒有其他的內容,你可以只是把在整個頁面部分。
使用另一張頁面佈局
如果它是一整頁,需要有全寬,你可以只得到它使用不同的佈局。使用部分通用代碼並將.container
元素更改爲.container-fluid
。
正常佈局:
<!DOCTYPE html>
<html lang="en">
@Html.Partial("_LayoutHead")
<body>
@Html.Partial("_Navbar")
<div class="container">
@RenderBody()
</div>
@Html.Partial("Footer")
</body>
</html>
替代佈局
<!DOCTYPE html>
<html lang="en">
@Html.Partial("_LayoutHead")
<body>
@Html.Partial("_Navbar")
<div class="container-fluid">
@RenderBody()
</div>
@Html.Partial("Footer")
</body>
</html>
手動關閉容器並重新打開後
我真的不會推薦這一個,因爲它是非常哈克,並會出現錯誤,但它確實編譯和工作。如果您在內容中間的某個元素出於某種原因想要成爲全寬,則可以使用此選項。
查看:
<div>Some normal content here.</div>
</div> <!--This shows an error for missing a starting tag. The actual starting tag is on the layout page.-->
<div class="container-fluid">
<div>Full width div</div>
</div>
<div class="container"> <!--This shows an error for missing an ending tag. It actually gets closed using the end tag in the layout page-->
<div>Back to normal</div>
是否所有其他網頁的共享相同的.container DIV? – cantera
是的。所有頁面都呈現在@RenderBody()的位置。 .container的widht根據當前的窗口大小通過bootstrap進行動態維護。 –
http://stackoverflow.com/questions/15204976/bootstrap-100-width-full-width 檢查這個帖子... –