我在使用Susy响应式网格时遇到了一些问题。我试图建立一个两行,三列的布局。这是我正在使用的代码。
$susy: (
columns: 12,
gutters: 1/2,
math: fluid,
output: float,
gutter-position: inside,
);
$desktop:960px;
@include breakpoint($desktop){
body{
@include container(95%);
background: $faintgray;
}
.container {
position: absolute;
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
}
h2 {
margin: 0 auto 13px auto
}
section {
@include span(4);
text-align: center;
}
section:not(:first-of-type) {
border-left: 1px dashed $lightgray;
}
}
这是HTML:
<div class="container">
<section id="frost">
<h2>Frost Bank</h2>
<p>Frost Bank founded in 1868 is based in San Antonio with over 110 financial centers across the state.</p>
<a href="#" class="myButton"><i class="fa fa-search"></i> View</a>
</section>
<section id="shiner">
<h2>Shiner</h2>
<p>Spoetzl Brewery was founded in 1909 in Shiner, Texas. It's the oldest brewery in our Lone Star State.</p>
<a href="#" class="myButton"><i class="fa fa-search"></i> View</a>
</section>
<section id="whataburger">
<h2>Whataburger</h2>
<p>Their first burger stand opened in 1950. They serve fresh food made daily, just like you like it.</p>
<a href="#" class="myButton"><i class="fa fa-search"></i> View</a>
</section>
<section id="costadelmar">
<h2>Costa Del Mar</h2>
<p>Daytona Beach based Costa, specializes in polarized sunglasses for fishing, sailing, and surfing.</p>
<a href="#" class="myButton"><i class="fa fa-search"></i> View</a>
</section>
<section id="honeysucklewhite">
<h2>Costa Del Mar</h2>
<p>Daytona Beach based Costa, specializes in polarized sunglasses for fishing, sailing, and surfing.</p>
<a href="#" class="myButton"><i class="fa fa-search"></i> View</a>
</section>
<section id="morestuff">
<h2>More Stuff</h2>
<p>Take a peek at all the other projects I've worked on. There's a some cool stuff here. Check it out!</p>
<a href="#" class="myButton"><i class="fa fa-search"></i> View</a>
</section>
</div>
这里有两个问题。
问题#1 在浏览器宽度的某些点,布局变得不稳定,我的行未对齐。在大约960px它是不正确的,然后在1000px它是正确的,然后它再次发生在1020px,而不是再次纠正。见照片: 问题#2 当我向容器添加垂直对齐时,容器垂直正确居中,但容器向右移动约10px,因此它不会水平居中。见照片。非常感谢任何帮助。
答案 0 :(得分:0)
.container {position:absolute;对于响应式网格?这对我来说似乎不对,但我不是很好的专家,我没有将你的HTML转移到我自己的编辑。
答案 1 :(得分:0)
Susy正在使用花车布置您的网格。在某些宽度处,网格中的第3个项目比其他项目短,项目#4在其下方浮动。您需要将clear: left;
添加到第4个项目,或者使用Susy的@include break;
mixin来明确显示该预期的换行符。或者,您可能最好用@include span(4)
替换@include gallery(4)
。 gallery mixin用于自动处理这种类型的布局。
这可能是绝对定位引起的。绝对定位可以消除流量中的所有内容,并定位离最近的定位祖先。在这种情况下,没有定位的祖先,所以它相对于文档的根。我不确定最终是如何工作的,但这不是你想要的。您想要关闭body
容器,因此您应该在其中添加position: relative;
。但是这个容器正在围绕你现在绝对定位的内容进行折叠,所以它的高度为0,并且你不再是垂直居中的。您必须在html
和body
:
html, body {
height: 100%;
}
body {
position: relative;
}