aboutsummaryrefslogtreecommitdiff
path: root/scss
diff options
context:
space:
mode:
authorMark Otto <[email protected]>2016-12-05 23:31:14 -0800
committerGitHub <[email protected]>2016-12-05 23:31:14 -0800
commitede925d79bf92d5983a4508c6ed6fda9310e1e8b (patch)
tree2106dc9b4f97d109f91c06a31234802c8d1890b6 /scss
parent306f75216d2b66bfe8e6e4b587939491e637b8da (diff)
parente0edea0d1a69d51990cb8d8de41183e94331b3a2 (diff)
downloadbootstrap-ede925d79bf92d5983a4508c6ed6fda9310e1e8b.tar.xz
bootstrap-ede925d79bf92d5983a4508c6ed6fda9310e1e8b.zip
Merge pull request #21298 from twbs/carousel
Refactor carousel
Diffstat (limited to 'scss')
-rw-r--r--scss/_carousel.scss262
-rw-r--r--scss/_variables.scss17
2 files changed, 101 insertions, 178 deletions
diff --git a/scss/_carousel.scss b/scss/_carousel.scss
index 09f6ea73e..8a077f083 100644
--- a/scss/_carousel.scss
+++ b/scss/_carousel.scss
@@ -7,77 +7,47 @@
position: relative;
width: 100%;
overflow: hidden;
+}
- > .carousel-item {
- position: relative;
- display: none;
- @include transition(left .6s ease-in-out);
-
- // Account for jankitude on images
- > img,
- > a > img {
- @extend .img-fluid;
- line-height: 1;
- }
+.carousel-item {
+ position: relative;
+ display: none;
+ width: 100%;
- // CSS3 transforms when supported by the browser
- @include if-supports-3d-transforms() {
- @include transition(transform .6s ease-in-out);
- backface-visibility: hidden;
- perspective: 1000px;
-
- &.next,
- &.active.right {
- left: 0;
- transform: translate3d(100%, 0, 0);
- }
- &.prev,
- &.active.left {
- left: 0;
- transform: translate3d(-100%, 0, 0);
- }
- &.next.left,
- &.prev.right,
- &.active {
- left: 0;
- transform: translate3d(0, 0, 0);
- }
- }
+ @include if-supports-3d-transforms() {
+ @include transition(transform .6s ease-in-out);
+ backface-visibility: hidden;
+ perspective: 1000px;
}
+}
- > .active,
- > .next,
- > .prev {
- display: block;
- }
+.carousel-item.active,
+.carousel-item-next,
+.carousel-item-prev {
+ display: block;
+}
- > .active {
- left: 0;
- }
+.carousel-item-next,
+.carousel-item-prev {
+ position: absolute;
+ top: 0;
+}
- > .next,
- > .prev {
- position: absolute;
- top: 0;
- width: 100%;
+// CSS3 transforms when supported by the browser
+@include if-supports-3d-transforms() {
+ .carousel-item-next.carousel-item-left,
+ .carousel-item-prev.carousel-item-right {
+ transform: translate3d(0, 0, 0);
}
- > .next {
- left: 100%;
- }
- > .prev {
- left: -100%;
- }
- > .next.left,
- > .prev.right {
- left: 0;
+ .carousel-item-next,
+ .active.carousel-item-right {
+ transform: translate3d(100%, 0, 0);
}
- > .active.left {
- left: -100%;
- }
- > .active.right {
- left: 100%;
+ .carousel-item-prev,
+ .active.carousel-item-left {
+ transform: translate3d(-100%, 0, 0);
}
}
@@ -86,30 +56,18 @@
// Left/right controls for nav
//
-.carousel-control {
+.carousel-control-prev,
+.carousel-control-next {
position: absolute;
top: 0;
bottom: 0;
- left: 0;
width: $carousel-control-width;
- font-size: $carousel-control-font-size;
color: $carousel-control-color;
text-align: center;
- text-shadow: $carousel-text-shadow;
opacity: $carousel-control-opacity;
- // We can't have this transition here because WebKit cancels the carousel
+ // We can't have a transition here because WebKit cancels the carousel
// animation if you trip this while in the middle of another animation.
- // Set gradients for backgrounds
- &.left {
- @include gradient-x($start-color: rgba(0,0,0,.5), $end-color: rgba(0,0,0,.0001));
- }
- &.right {
- right: 0;
- left: auto;
- @include gradient-x($start-color: rgba(0,0,0,.0001), $end-color: rgba(0,0,0,.5));
- }
-
// Hover/focus state
@include hover-focus {
color: $carousel-control-color;
@@ -117,39 +75,38 @@
outline: 0;
opacity: .9;
}
+}
+.carousel-control-prev {
+ left: 0;
+}
+.carousel-control-next {
+ right: 0;
+}
- // Toggles
- .icon-prev,
- .icon-next {
- position: absolute;
- top: 50%;
- z-index: 5;
- display: inline-block;
- width: $carousel-icon-width;
- height: $carousel-icon-width;
- margin-top: -($carousel-icon-width / 2);
- font-family: serif;
- line-height: 1;
- }
- .icon-prev {
- left: 50%;
- margin-left: -($carousel-icon-width / 2);
- }
- .icon-next {
- right: 50%;
- margin-right: -($carousel-icon-width / 2);
- }
-
- .icon-prev {
- &::before {
- content: "\2039";// SINGLE LEFT-POINTING ANGLE QUOTATION MARK (U+2039)
- }
- }
- .icon-next {
- &::before {
- content: "\203a";// SINGLE RIGHT-POINTING ANGLE QUOTATION MARK (U+203A)
- }
- }
+// Icons for within
+.carousel-control-prev-icon,
+.carousel-control-next-icon {
+ position: absolute;
+ top: 50%;
+ z-index: 5;
+ display: inline-block;
+ width: $carousel-control-icon-width;
+ height: $carousel-control-icon-width;
+ margin-top: -($carousel-control-icon-width / 2);
+ font-family: serif;
+ line-height: 1;
+ background: transparent no-repeat center center;
+ background-size: 100% 100%;
+}
+.carousel-control-prev-icon {
+ left: 50%;
+ margin-left: -($carousel-control-icon-width / 2);
+ background-image: $carousel-control-prev-icon-bg;
+}
+.carousel-control-next-icon {
+ right: 50%;
+ margin-right: -($carousel-control-icon-width / 2);
+ background-image: $carousel-control-next-icon-bg;
}
@@ -160,36 +117,48 @@
.carousel-indicators {
position: absolute;
+ right: 0;
bottom: 10px;
- left: 50%;
+ left: 0;
z-index: 15;
- width: $carousel-indicators-width;
- padding-left: 0;
- margin-left: -($carousel-indicators-width / 2);
+ padding-left: 0; // override <ul> default
+ // Use the .carousel-control's width as margin so we don't overlay those
+ margin-right: $carousel-control-width;
+ margin-left: $carousel-control-width;
text-align: center;
list-style: none;
li {
+ position: relative;
display: inline-block;
- width: $carousel-indicator-size;
- height: $carousel-indicator-size;
- margin: 1px;
+ width: $carousel-indicator-width;
+ height: $carousel-indicator-height;
text-indent: -999px;
cursor: pointer;
- // IE9 hack for event handling
- //
- // Internet Explorer 9 does not properly handle clicks on elements with a `background-color` of `transparent`,
- // so we use `rgba(0,0,0,0)` instead since it's a non-buggy equivalent.
- // See https://developer.mozilla.org/en-US/docs/Web/Events/click#Internet_Explorer
- background-color: rgba(0,0,0,0); // IE9
- border: 1px solid $carousel-indicator-border-color;
- border-radius: $carousel-indicator-size;
+ background-color: rgba($carousel-indicator-active-bg, .5);
+
+ // Use pseudo classes to increase the hit area by 10px on top and bottom.
+ &::before {
+ position: absolute;
+ top: -10px;
+ left: 0;
+ display: inline-block;
+ width: 100%;
+ height: 10px;
+ content: "";
+ }
+ &::after {
+ position: absolute;
+ bottom: -10px;
+ left: 0;
+ display: inline-block;
+ width: 100%;
+ height: 10px;
+ content: "";
+ }
}
.active {
- width: $carousel-indicator-active-size;
- height: $carousel-indicator-active-size;
- margin: 0;
background-color: $carousel-indicator-active-bg;
}
}
@@ -209,45 +178,4 @@
padding-bottom: 20px;
color: $carousel-caption-color;
text-align: center;
- text-shadow: $carousel-text-shadow;
-
- .btn {
- text-shadow: none; // No shadow for button elements in carousel-caption
- }
-}
-
-
-//
-// Responsive variations
-//
-
-@include media-breakpoint-up(sm) {
- // Scale up the controls a smidge
- .carousel-control {
- .icon-prev,
- .icon-next {
- width: $carousel-control-sm-up-size;
- height: $carousel-control-sm-up-size;
- margin-top: -($carousel-control-sm-up-size / 2);
- font-size: $carousel-control-sm-up-size;
- }
- .icon-prev {
- margin-left: -($carousel-control-sm-up-size / 2);
- }
- .icon-next {
- margin-right: -($carousel-control-sm-up-size / 2);
- }
- }
-
- // Show and left align the captions
- .carousel-caption {
- right: ((100% - $carousel-caption-sm-up-width) / 2);
- left: ((100% - $carousel-caption-sm-up-width) / 2);
- padding-bottom: 30px;
- }
-
- // Move up the indicators
- .carousel-indicators {
- bottom: 20px;
- }
}
diff --git a/scss/_variables.scss b/scss/_variables.scss
index d57e59575..50803fc3f 100644
--- a/scss/_variables.scss
+++ b/scss/_variables.scss
@@ -882,26 +882,21 @@ $media-alignment-padding-x: 10px !default;
// 33. Carousel
-$carousel-text-shadow: 0 1px 2px rgba(0,0,0,.6) !default;
-
$carousel-control-color: #fff !default;
$carousel-control-width: 15% !default;
-$carousel-control-sm-up-size: 30px !default;
$carousel-control-opacity: .5 !default;
-$carousel-control-font-size: 20px !default;
-
-$carousel-indicators-width: 60% !default;
-$carousel-indicator-size: 10px !default;
-$carousel-indicator-active-size: 12px !default;
+$carousel-indicator-width: 30px !default;
+$carousel-indicator-height: 3px !default;
$carousel-indicator-active-bg: #fff !default;
-$carousel-indicator-border-color: #fff !default;
$carousel-caption-width: 70% !default;
-$carousel-caption-sm-up-width: 60% !default;
$carousel-caption-color: #fff !default;
-$carousel-icon-width: 20px !default;
+$carousel-control-icon-width: 20px !default;
+
+$carousel-control-prev-icon-bg: str-replace(url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='#{$carousel-control-color}' viewBox='0 0 8 8'%3E%3Cpath d='M4 0l-4 4 4 4 1.5-1.5-2.5-2.5 2.5-2.5-1.5-1.5z'/%3E%3C/svg%3E"), "#", "%23") !default;
+$carousel-control-next-icon-bg: str-replace(url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='#{$carousel-control-color}' viewBox='0 0 8 8'%3E%3Cpath d='M1.5 0l-1.5 1.5 2.5 2.5-2.5 2.5 1.5 1.5 4-4-4-4z'/%3E%3C/svg%3E"), "#", "%23") !default;
// 34. Close