Skip to content

Instantly share code, notes, and snippets.

@ryanjames
Last active August 29, 2015 14:10
Show Gist options
  • Save ryanjames/3f7668a0a85aeac48f19 to your computer and use it in GitHub Desktop.
Save ryanjames/3f7668a0a85aeac48f19 to your computer and use it in GitHub Desktop.
Pull an image outside of a grid container and to the edge of the browser using calc()
/*
Pull an image outside of a grid container and to the edge of the browser
while maintaining its left or right edge position on the grid.
Requires a calc() polyfill for unsupported browsers.
Recommended polyfill: https://github.com/closingtag/calc-polyfill
Current browser support: http://caniuse.com/#feat=calc
*/
$grid-width: 1100px;
$grid-columns: 12;
@mixin image-pull($span-columns, $position: left, $grid-columns: $grid-columns, $grid-width: $grid-width) {
// Calculate the percent width of the span of columns the element will occupy
$percent: ($span-columns/$grid-columns)*$grid-width;
position: absolute;
#{$position}: 0;
width: calc(#{$percent} + ((100% - #{$grid-width})/2));
}
img.pull-left {
@include image-pull(7)
}
img.pull-right {
@include image-pull(7, right)
}
/*
<div class="grid-container">
<img src="image.jpg" class="pull-left" />
</div>
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment