【发布时间】:2014-09-14 22:50:13
【问题描述】:
我开始将 Thoughtbot 的 Bourbon Neat 用于响应式网格。总的来说,它很漂亮,我真的很喜欢它,但我被一个小问题挂断了。
我试图让两列在没有边距的情况下彼此相邻,但在尝试复制他们的示例后,我没有得到相同的结果。
这是示例 HTML:
<section>
<p>
This is the main section.
</p>
<div class="container">
<p>
This is the container
</p>
<div class="col1">
<p>
This is the 1st column.
</p>
</div>
<div class="col2">
<p>
This is the 2nd column.
</p>
</div>
</div>
</section>
这是我的 SCSS:
section {
@include outer-container;
text-align: center;
}
.container {
@include span-columns (12);
text-align: center;
margin: 0;
padding: 0;
.col1 {
@include span-columns(6);
background: #ccc;
@include pad(em(15));
}
.col2 {
@include span-columns(6);
background: #ccc;
@include pad(em(15));
}
}
产生这个:
但是当我尝试使用表格方法让两列相互嵌套/对接时,如他们的示例所示,我得到了:
SCSS:
section {
@include outer-container;
text-align: center;
}
.container {
@include span-columns (12);
@include row (table);
text-align: center;
margin: 0;
padding: 0;
.col1 {
@include span-columns(6);
background: #ccc;
@include pad(em(15));
}
.col2 {
@include span-columns(6);
background: #ccc;
@include pad(em(15));
@include reset-display;
}
}
输出:
如果我走@include omega(); 可行的路线,但它不会扩大最后一列的整个宽度:
SCSS:
section {
@include outer-container;
text-align: center;
}
.container {
@include span-columns (12);
text-align: center;
margin: 0;
padding: 0;
.col1 {
@include span-columns(6);
@include omega();
background: #ccc;
@include pad(em(15));
}
.col2 {
@include span-columns(6);
background: #ccc;
@include pad(em(15));
@include omega();
}
}
输出:
基本上,我可以省略容器部分中的内容,这些内容会产生我正在寻找的结果。但是有必要创建一个空的div 来实现吗?:
SCSS
section {
@include outer-container;
text-align: center;
}
.container {
@include span-columns (12);
@include row(table);
text-align: center;
margin: 0;
padding: 0;
.col1 {
@include span-columns(6);
background: #ccc;
@include pad(em(15));
}
.col2 {
@include span-columns(6);
background: #ccc;
@include pad(em(15));
@include reset-display
}
}
HTML(.container 中的内容已被注释掉):
<section>
<p>
This is the main section.
</p>
<div class="container">
<!-- <p>
This is the container
</p> -->
<div class="col1">
<p>
This is the 1st column.
</p>
</div>
<div class="col2">
<p>
This is the 2nd column.
</p>
</div>
</div>
</section>
输出:
无论如何,我不知道实现这一目标的“正确”方式是什么。该文档并没有真正具体解释如何让两列相互嵌套。从我试图在他们的示例中复制的内容来看,并没有产生相同的结果。
除非我需要在最后一列专门添加margin:0;。
【问题讨论】:
标签: html css sass bourbon neat