简体   繁体   English

Susy列断裂

[英]Susy columns are breaking

I'm having some problems using Susy responsive grids. 我在使用Susy响应式网格时遇到一些问题。 I'm trying to set up a two row, three column layout. 我正在尝试设置两行三列的布局。 Here is the code I'm using. 这是我正在使用的代码。

$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;
}

}

And here is the HTML: 这是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>&nbsp;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>&nbsp;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>&nbsp;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>&nbsp;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>&nbsp;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>&nbsp;View</a>
</section>   
</div>

There's two problems going in here. 这里有两个问题。

Problem #1 At certain points in the browser width, the layout gets wonky and my rows are misaligned. 问题#1在浏览器宽度的某些点上,布局变了,我的行未对齐。 At about 960px it's incorrect, then at 1000px it is corrent, then it happens again at 1020px, than corrects again. 大约960像素是不正确的,然后是1000像素是正确的,然后以1020像素再次发生,然后再次纠正。 See photos: 查看照片:

Incorrect 不正确的

Problem #2 When I add the vertical alignment to the container, The container centers vertically correctly, but the container shifts to the right about 10px so it's not centered horizontally. 问题#2当我向容器添加垂直对齐方式时,容器正确地垂直居中,但是容器向右移动了约10像素,因此它没有水平居中。 See photo. 见照片。

Not Centered 不居中

Any help is greatly appreciated. 任何帮助是极大的赞赏。

.container {position: absolute; .container {位置:绝对; for a responsive grid? 对于响应式网格? That doesn't seem quite right to me, but I'm no great expert and I haven't transferred your html to my own editor. 这对我来说似乎不太对劲,但是我不是专家,而且还没有将您的html转移到我自己的编辑器中。

  1. Susy is using floats to lay out your grid. Susy正在使用浮动对象对网格进行布局。 At certain widths the 3rd item in your grid is shorter than the others, and item #4 floats up underneath it. 在某些宽度下,网格中的第三个项目比其他项目短,项目#4漂浮在其下方。 You need to add clear: left; 您需要添加clear: left; to that 4th item, or use Susy's @include break; 到第四项,或使用Susy的@include break; mixin to make that intended line-break explicit. mixin使该预期的换行符明确。 Or, you might be best off replacing @include span(4) with @include gallery(4) . 或者,最好将@include span(4)替换为@include gallery(4) The gallery mixin is built to handle this type of layout automatically. Gallery mixin可以自动处理这种布局。

  2. This is probably being caused by absolute positioning. 这可能是由于绝对定位引起的。 Absolute positioning removes everything from the flow, and positions off the nearest positioned ancestor. 绝对定位可从流程中删除所有内容,并定位在距离最近的祖先位置之外的位置。 In this case there is no positioned ancestor, so it's relative to the root of the document. 在这种情况下,没有定位的祖先,因此它相对于文档的根。 I'm not sure exactly how that ends up working, but it's not what you want. 我不确定到底该如何工作,但这不是您想要的。 You want to position off your body container, so you should add position: relative; 您希望将其放置在您的body容器之外,因此应添加position: relative; there. 那里。 But that container is collapsing around your now-absolutely-positioned content, so it has 0 height, and you are no longer vertically-centered. 但是该容器正在折叠,现在位于您绝对定位的内容周围,因此它的高度为0,并且您不再垂直居中。 You'll have to fix that with explicit heights on both html and body : 您必须在htmlbody上使用显式的高度来修复该问题:

     html, body { height: 100%; } body { position: relative; } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM