Skip to content

Commit 3e2a65d

Browse files
committed
Added img-fluid mixin
1 parent 10f6c78 commit 3e2a65d

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ You can make your own custom build of Bootstrap by downloading the source, makin
5050
Here is how you can accomplish what I have done here:
5151

5252
1. Download and extract the Bootstrap [source files](http://v4-alpha.getbootstrap.com/getting-started/download/)
53-
2. Modify the SCSS files as desired. For example, to generate this build I added the `.bootstrap-wrapper` class to `scss/bootstrap-grid.scss` (lines 55 and 72), included the responsive utilities (line 63), and manually added the `.img-fluid` class (lines 66-71). In `scss/_variables.scss` I also enabled flex support on line 46.
53+
2. Modify the SCSS files as desired. For example, to generate this build I added the `.bootstrap-wrapper` class to `scss/bootstrap-grid.scss` (lines 55 and 69), included the responsive utilities (line 64) and `.img-fluid` class (lines 67-68). I also enabled flex support in `scss/_variables.scss` on line 46.
5454
3. Once you are done making your changes, use a program like [Koala](http://koala-app.com/) or Scout to compile the SCSS files into usable CSS files.
5555

5656
As you can see, it is a very easy process to create your own customized Bootstrap build.

scss/bootstrap-grid.scss

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,13 @@ $grid-gutter-width: 1.875rem !default; // 30px
5757

5858
@import "mixins/clearfix";
5959
@import "mixins/breakpoints";
60+
@import "mixins/image";
6061
@import "mixins/grid-framework";
6162
@import "mixins/grid";
6263

6364
@import "utilities-responsive";
6465
@import "grid";
6566

66-
// Manually adding .img-fluid (formerly known as .img-responsive in Bootstrap 3) because it is so useful
67-
.img-fluid {
68-
display: block;
69-
max-width: 100%;
70-
height: auto;
71-
}
67+
// Manually adding .img-fluid (formerly known as .img-responsive in Bootstrap 3)
68+
.img-fluid { @include img-fluid(); }
7269
}

scss/mixins/_image.scss

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Image Mixins
2+
// - Responsive image
3+
// - Retina image
4+
5+
6+
// Responsive image
7+
//
8+
// Keep images from scaling beyond the width of their parents.
9+
10+
@mixin img-fluid($display: block) {
11+
display: $display;
12+
max-width: 100%; // Part 1: Set a maximum relative to the parent
13+
height: auto; // Part 2: Scale the height according to the width, otherwise you get stretching
14+
}
15+
16+
17+
// Retina image
18+
//
19+
// Short retina mixin for setting background-image and -size.
20+
21+
@mixin img-retina($file-1x, $file-2x, $width-1x, $height-1x) {
22+
background-image: url($file-1x);
23+
24+
// Autoprefixer takes care of adding -webkit-min-device-pixel-ratio and -o-min-device-pixel-ratio,
25+
// but doesn't convert dppx=>dpi.
26+
// There's no such thing as unprefixed min-device-pixel-ratio since it's nonstandard.
27+
// Compatibility info: http://caniuse.com/#feat=css-media-resolution
28+
@media
29+
only screen and (min-resolution: 192dpi), // IE9-11 don't support dppx
30+
only screen and (min-resolution: 2dppx) { // Standardized
31+
background-image: url($file-2x);
32+
background-size: $width-1x $height-1x;
33+
}
34+
}

0 commit comments

Comments
 (0)