gpt4 book ai didi

html - 如何在 Bootstrap 中为 lg 和 xs 屏幕尺寸创建自定义网格类?

转载 作者:行者123 更新时间:2023-11-27 23:27:11 25 4
gpt4 key购买 nike

Here's the link to the page, check the columns.我已经在 CSS 上工作了一段时间,并且感到迫切需要自定义大小的 Bootstrap 列。请考虑这种情况,我的网站正文有两栏设计。

<body style="background-color : grey" style="padding-right : 2% ; padding-left : 2%">
<div class="row">
<div id="col1" class="col-lg-9 style="background-color : white">
<p> Some content here</p>
</div>
<div id="col2" class="col-lg-1" style="background-color : grey"></div>
<div id="col3" class="col-lg-2" style="background-color : white">
<p>Some content here for the right column</p>
</div>
</div>
</body>

尽管我想要在左侧主列和右侧主列之间留出一些空间(由 col2 完成),但空间太大了。如果我使用自定义宽度设置 col2 的样式,则右列会从 2% 的右侧打破标准边距,这由于我的页脚而清晰可见。因此我需要更改 col2 和 col3 的宽度。

我打算为 lg 屏幕尺寸使用自定义列类,以便设计在移动屏幕上也能保持完整。我如何创建一个?一个简短的例子将不胜感激谢谢

最佳答案

如何在两个 Bootstrap 列之间留出空间(仅限大屏幕)

  1. 只保留两列。
  2. 增加右列的 margin-left
  3. 将右列的宽度减少相同的值。
  4. 使用@media(最小宽度:1200px)

请检查结果:

/* heart of the matter */
@media (min-width: 1200px) {
#col2 {
margin-left: 4%;
width: 21%; /* = 25% (width of .col-lg-3) - 4% (margin-left) */
}
}

/* decorations */
* {
font-size: 1.2em;
font-weight: bold;
}
#col1, #col2, #header, #footer {
margin-top: 15px;
min-height: 100px;
}
#col1, #col2 { background-color: #ccc; }
#header, #footer { background-color: #999; }
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">

<div class="container">
<div class="row">
<div id="header" class="col-lg-12"> Header </div>
</div>
<div class="row">
<div id="col1" class="col-lg-9"> Main content </div>
<div id="col2" class="col-lg-3"> Right column </div>
</div>
<div class="row">
<div id="footer" class="col-lg-12"> Footer </div>
</div>
</div>

关于html - 如何在 Bootstrap 中为 lg 和 xs 屏幕尺寸创建自定义网格类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37827033/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com