Question

I have built the following in Singularity one third two third image raster

A 1/3 broad image next to a 2/3 broad image and in the next line the other way around. The images are served with picturefill. But my problem is when i narrow the viewport down from the containers max-width towards the breakpoint (750px) where the images switch from a two "column" layout to a one column it differ in height even the source files have the exact same physical height in pixel. They differ sometimes a few pixel, sometimes only one.

differing height

the reduced setup behind is the following (left out retina markup and 2 breakpoints inbetween):

<section class="pro-main" role="main">
    <section class="pro-thirds">
        <article class="pro-samples imgparent">
            <a class="p-ov-liner" href="#">
                <span data-picture data-alt="onethird">
                    <span data-src="/img/projekte-gpfinestsolution-zweidrittel-659x324.jpg"></span>
                    <span data-src="/img/projekte-gpfinestsolution-eindrittel-341x347.jpg" data-media="(min-width: 750px)"></span>
                    <noscript><img src="/img/projekte-gpfinestsolution-zweidrittel-659x324.jpg" alt="img1"></noscript>
                </span>
                <div class="bottombox"></div>
            </a>
        </article>
        <article class="pro-samples imgparent">
            <a class="p-ov-liner" href="#">
                <span data-picture data-alt="twothird">
                    <span data-src="/img/projekte-gplab-zweidrittel-659x324.jpg"></span>
                    <span data-src="/img/projekte-gplab-zweidrittel-704x347.jpg" data-media="(min-width: 750px)"></span>
                    <noscript><img src="/img/projekte-gplab-zweidrittel-659x324.jpg" alt="twothird"></noscript>
                </span>
                <div class="bottombox"></div>
            </a>
        </article>
        <article class="pro-samples imgparent">
            <a class="p-ov-liner" href="#">
                <span data-picture data-alt="twothird">
                    <span data-src="/img/projekte-gplab-zweidrittel-659x324.jpg"></span>
                    <span data-src="/img/projekte-gplab-zweidrittel-704x347.jpg" data-media="(min-width: 750px)"></span>
                    <noscript><img src="/img/projekte-gplab-zweidrittel-659x324.jpg" alt="twothird"></noscript>
                </span>
                <div class="bottombox"></div>
            </a>
        </article>
        <article class="pro-samples imgparent">
            <a class="p-ov-liner" href="#">
                <span data-picture data-alt="onethird">
                    <span data-src="/img/projekte-gpfinestsolution-zweidrittel-659x324.jpg"></span>
                    <span data-src="/img/projekte-gpfinestsolution-eindrittel-341x347.jpg" data-media="(min-width: 750px)"></span>
                    <noscript><img src="/img/projekte-gpfinestsolution-zweidrittel-659x324.jpg" alt="img1"></noscript>
                </span>
                <div class="bottombox"></div>
            </a>
        </article>
    </section>
</section>

breakpoint and singularity settings are as follows:

// Baseline breaks
$baseline675: 675px 849px;
$baseline850: 850px 1074px;
$baseline1075: 1075px 1199px;
$baselineMAX: 1200px;
// Container breaks
$container600: 600px;
$container750: 750px;
$container850: 850px;
$container990: 990px;
$container1100: 1100px;
$container1200: 1200px;
// Singularity
$grids: 6;
$grids: add-grid(9 at 675px);
$grids: add-grid(12 at 850px);
$grids: add-grid(15 at 1075px);
$grids: add-grid(18 at 1200px);

$gutters: 1/3;

$output:'isolation';

the styling:

.pro-main,
.pro-thirds {
    @extend %clearfix;
}

.pro-samples {
    @include trailer(0.5);
        &:last-child {
            @include trailer(2);
        }
    @include switch-baseline(850px 1074px) {
        &:nth-child(4n+1) {
            @include isolation-span(4, 1, 'right', $gutter:.5);
        }
        &:nth-child(4n+4) {
            @include isolation-span(4, 9, 'right', $gutter:0);
        }
        &:nth-child(4n+2) {
            @include isolation-span(8, 5, 'right', $gutter:0);
        }
        &:nth-child(4n+3) {
            @include isolation-span(8, 1, 'right', $gutter:.5);
        }
        &:last-child {
            @include trailer(2);
        }
    }
    @include breakpoint(1075px 1199px) {
        &:nth-child(4n+1) {
            @include isolation-span(5, 1, 'right', $gutter:.5);
        }
        &:nth-child(4n+4) {
            @include isolation-span(5, 11, 'right', $gutter:0);
        }
        &:nth-child(4n+2) {
            @include isolation-span(10, 6, 'right', $gutter:0);
        }
        &:nth-child(4n+3) {
            @include isolation-span(10, 1, 'right', $gutter:.5);
        }
        &:last-child {
            @include trailer(2);
        }
    }
    @include breakpoint(1200px) {
        &:nth-child(4n+1) {
            @include isolation-span(6, 1, 'right', $gutter:.5);
        }
        &:nth-child(4n+4) {
            @include isolation-span(6, 13, 'right', $gutter:0);
        }
        &:nth-child(4n+2) {
            @include isolation-span(12, 7, 'right', $gutter:0);
        }
        &:nth-child(4n+3) {
            @include isolation-span(12, 1, 'right', $gutter:.5);
        }
        &:last-child {
            @include trailer(2);
        }
    }
}

Between the height of the one third and two third images at max width are physically identical also they are aligned at the bottom line. on smaller viewports they differ. and if i remove the gutter with pictures in it the heights still differs. e.g.

    @include breakpoint(1075px 1199px) {
        &:nth-child(4n+1) {
            @include isolation-span(5, 1, 'right', $gutter:0);
        }
        &:nth-child(4n+4) {
            @include isolation-span(5, 11, 'right', $gutter:0);
        }
        &:nth-child(4n+2) {
            @include isolation-span(10, 6, 'right', $gutter:0);
        }
        &:nth-child(4n+3) {
            @include isolation-span(10, 1, 'right', $gutter:0);
        }
        &:last-child {
            @include trailer(2);
        }
    }

If i use, instead of the picturefill markup, just empty article tags and add those two properties to the scss from above the height stays exactly the same on all article elements no matter if they are 1/3 or 2/3.

 background:red
 height:10em; 

with gutter:

red with gutter

and without:

red without gutter

Does anyone have an idea what might cause that varying difference in height over the viewports? Me for myself am completely out of ideas. :(

Best regards Ralf

Était-ce utile?

La solution

The reason for the difference in images' heights

The reason for the difference in images' heights is mathematical.

For simplicity, let's have a look at the following column system:

@include add-grid(4);
@include add-gutter(0.1);

The above definition means: four columns of identical width, and between them three (4 - 1) gutters. Each gutter has the width equal to 0.1 width of any column.

Now, given that the width of the container is 1000 px, what will be the width of every column and every gutter?

Let's say that a column is x px wide. Then a gutter will be 0.1x px wide. We can assemble an equation:

4x + 3*(0.1x) = 1000

Let's solve it:

4x + 0.3x = 1000
4.3x = 1000
x = 1000 / 4.3
x = 232.56

Every column is ~232.56px wide! And every gutter is 232.56 * 0.1 = 23.256px wide.

Now, let's say we've got two images: 250x250 px and 750x250 px, and we put them into these columns.

The first image will occupy one column and zero gutters. It's width and height will both be equal to 232.56 px.

The second image will occupy three columns and two gutters between those columns. It's width will be equal to 232.56 * 3 + 23.256 * 2 = 744.192px. The height of the second image will be equal to 250 * 744.192 / 750 = 248.064px.

As you can see, the images' heights don't match, and this is expected.

A solution for the problem

You could use a compound grid to compensate for the difference in heights. This is way more difficult to calculate.

A simpler solution is to slice your images to match your existing grid!

General recommendations for your grid layout.

  1. You use a lot of grid definitions for different breakpoints but across all of them (except for the mobile view), you have the same layout.

    You don't have to redefine grids for every breakpoint. In fact, your responsive layout can be reduced to this definition:

    +add-grid(3);
    +add-gutter(0.5);
    

    For the mobile layout, don't apply any spans. For the layouts starting with the smallest breakpoint, apply the spans and you're good to go.

    Note that you can still apply multiple breakpoints for other styles, e. g. container width.

  2. For the isolation spanning to work with multiple rows, apply clearing for the first child in every row:

    &:nth-child(3n+1) { clear: both; }
    

    Note: this should be done AFTER applying a Singularity span mixin, e. g.:

    &:nth-child(3n+1) {
      +grid-span(1,1);
      clear: both;
    }
    
  3. You can use the common grid-span mixin instead of the specific isolation-span. Isolation is the default spanning technique for the grid-span mixin.

  4. Don't override direction and gutters for every mixin call unless you're trying to position elements off the declared grid.

  5. Don't use varying gutter sizes for adjacent elements, otherwise it will ruin the math.

  6. Don't apply duplicate styles under every media query. Ideally, every CSS rule should be declared only once. You can create more specific media query rules if necesary instead of duplicating styles.

  7. UPD: Oh, and remember that you can declare columns and guttters in the following format:

    +add-grid(235 235 235 235);
    +add-gutter(20);
    

    This is identical to +add-grid(4); +add-gutter(0.085); but makes comprehending the numbers much easier.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top