Last active
August 29, 2015 14:10
-
-
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()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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