2017-01-17 69 views
15

在引導3我用這個:使用媒體斷點引導4-α

.something { 
    padding: 5px; 
    @media screen and (min-width: $screen-sm-min) { 
     padding: 20px; 
    } 
    @media screen and (min-width: $screen-md-min) { 
     padding: 40px; 
    } 
} 

我怎樣才能做到同樣的事情在自舉4-α?我無法在他們的文檔中找到示例。 這是variables.scss

$grid-breakpoints: (
    xs: 0, 
    sm: 576px, 
    md: 768px, 
    lg: 992px, 
    xl: 1200px 
) !default; 
@include _assert-ascending($grid-breakpoints, "$grid-breakpoints"); 
@include _assert-starts-at-zero($grid-breakpoints); 

回答

27

使用斷點混入這樣的:

.something { 
    padding: 5px; 
    @include media-breakpoint-up(sm) { 
     padding: 20px; 
    } 
    @include media-breakpoint-up(md) { 
     padding: 40px; 
    } 
} 

v4 breakpoints reference

v4 alpha6 breakpoints reference


下面充分的選擇和價值。

斷點&(導通值切換及以上):

@include media-breakpoint-up(xs) { ... } 
@include media-breakpoint-up(sm) { ... } 
@include media-breakpoint-up(md) { ... } 
@include media-breakpoint-up(lg) { ... } 
@include media-breakpoint-up(xl) { ... } 

斷點&向上值:

// Extra small devices (portrait phones, less than 576px) 
// No media query since this is the default in Bootstrap 

// Small devices (landscape phones, 576px and up) 
@media (min-width: 576px) { ... } 

// Medium devices (tablets, 768px and up) 
@media (min-width: 768px) { ... } 

// Large devices (desktops, 992px and up) 
@media (min-width: 992px) { ... } 

// Extra large devices (large desktops, 1200px and up) 
@media (min-width: 1200px) { ... } 

斷點&向下(在值肘節和下):

@include media-breakpoint-down(xs) { ... } 
@include media-breakpoint-down(sm) { ... } 
@include media-breakpoint-down(md) { ... } 
@include media-breakpoint-down(lg) { ... } 

breakpoi NT &下值:只有

// Extra small devices (portrait phones, less than 576px) 
@media (max-width: 575px) { ... } 

// Small devices (landscape phones, less than 768px) 
@media (max-width: 767px) { ... } 

// Medium devices (tablets, less than 992px) 
@media (max-width: 991px) { ... } 

// Large devices (desktops, less than 1200px) 
@media (max-width: 1199px) { ... } 

// Extra large devices (large desktops) 
// No media query since the extra-large breakpoint has no upper bound on its width 

斷點:

@include media-breakpoint-only(xs) { ... } 
@include media-breakpoint-only(sm) { ... } 
@include media-breakpoint-only(md) { ... } 
@include media-breakpoint-only(lg) { ... } 
@include media-breakpoint-only(xl) { ... } 

斷點只值(僅切換在值之間):

// Extra small devices (portrait phones, less than 576px) 
@media (max-width: 575px) { ... } 

// Small devices (landscape phones, 576px and up) 
@media (min-width: 576px) and (max-width: 767px) { ... } 

// Medium devices (tablets, 768px and up) 
@media (min-width: 768px) and (max-width: 991px) { ... } 

// Large devices (desktops, 992px and up) 
@media (min-width: 992px) and (max-width: 1199px) { ... } 

// Extra large devices (large desktops, 1200px and up) 
@media (min-width: 1200px) { ... } 
2

我回答了similar question here

正如@ Syden說,mixin將起作用。另一種選擇是使用SASS map-get這樣的..

@media (min-width: map-get($grid-breakpoints, sm)){ 
    .something { 
    padding: 10px; 
    } 
} 

@media (min-width: map-get($grid-breakpoints, md)){ 
    .something { 
    padding: 20px; 
    } 
} 

http://www.codeply.com/go/0TU586QNlV