0
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-02-23 20:54:22 +01:00
Bootstrap/scss/_buttons.scss

226 lines
8.5 KiB
SCSS
Raw Normal View History

2024-07-29 22:04:11 -07:00
@use "functions";
@use "mixins/border-radius";
@use "mixins/box-shadow";
@use "mixins/buttons";
@use "mixins/gradients";
@use "mixins/transition";
@use "variables";
@use "vendor/rfs";
2015-04-18 11:15:40 -07:00
//
// Base styles
2015-04-18 11:15:40 -07:00
//
2012-12-19 22:25:56 -08:00
.btn {
// scss-docs-start btn-css-vars
2024-07-29 22:04:11 -07:00
--#{variables.$prefix}btn-padding-x: #{variables.$btn-padding-x};
--#{variables.$prefix}btn-padding-y: #{variables.$btn-padding-y};
--#{variables.$prefix}btn-font-family: #{variables.$btn-font-family};
@include rfs.rfs(variables.$btn-font-size, --#{variables.$prefix}btn-font-size);
--#{variables.$prefix}btn-font-weight: #{variables.$btn-font-weight};
--#{variables.$prefix}btn-line-height: #{variables.$btn-line-height};
--#{variables.$prefix}btn-color: #{variables.$btn-color};
--#{variables.$prefix}btn-bg: transparent;
--#{variables.$prefix}btn-border-width: #{variables.$btn-border-width};
--#{variables.$prefix}btn-border-color: transparent;
--#{variables.$prefix}btn-border-radius: #{variables.$btn-border-radius};
--#{variables.$prefix}btn-hover-border-color: transparent;
--#{variables.$prefix}btn-box-shadow: #{variables.$btn-box-shadow};
--#{variables.$prefix}btn-disabled-opacity: #{variables.$btn-disabled-opacity};
--#{variables.$prefix}btn-focus-box-shadow: 0 0 0 #{variables.$btn-focus-width} rgba(var(--#{variables.$prefix}btn-focus-shadow-rgb), .5);
// scss-docs-end btn-css-vars
2012-12-19 22:25:56 -08:00
display: inline-block;
2024-07-29 22:04:11 -07:00
padding: var(--#{variables.$prefix}btn-padding-y) var(--#{variables.$prefix}btn-padding-x);
font-family: var(--#{variables.$prefix}btn-font-family);
@include rfs.font-size(var(--#{variables.$prefix}btn-font-size));
font-weight: var(--#{variables.$prefix}btn-font-weight);
line-height: var(--#{variables.$prefix}btn-line-height);
color: var(--#{variables.$prefix}btn-color);
2012-12-19 22:54:04 -08:00
text-align: center;
2024-07-29 22:04:11 -07:00
text-decoration: if(variables.$link-decoration == none, null, none);
white-space: variables.$btn-white-space;
2012-12-19 22:25:56 -08:00
vertical-align: middle;
2024-07-29 22:04:11 -07:00
cursor: if(variables.$enable-button-pointers, pointer, null);
user-select: none;
2024-07-29 22:04:11 -07:00
border: var(--#{variables.$prefix}btn-border-width) solid var(--#{variables.$prefix}btn-border-color);
@include border-radius.border-radius(var(--#{variables.$prefix}btn-border-radius));
@include gradients.gradient-bg(var(--#{variables.$prefix}btn-bg));
@include box-shadow.box-shadow(var(--#{variables.$prefix}btn-box-shadow));
@include transition.transition(variables.$btn-transition);
2012-12-19 22:25:56 -08:00
&:hover {
2024-07-29 22:04:11 -07:00
color: var(--#{variables.$prefix}btn-hover-color);
text-decoration: if(variables.$link-hover-decoration == underline, none, null);
background-color: var(--#{variables.$prefix}btn-hover-bg);
border-color: var(--#{variables.$prefix}btn-hover-border-color);
}
2017-12-27 16:42:59 -08:00
.btn-check + &:hover {
// override for the checkbox/radio buttons
2024-07-29 22:04:11 -07:00
color: var(--#{variables.$prefix}btn-color);
background-color: var(--#{variables.$prefix}btn-bg);
border-color: var(--#{variables.$prefix}btn-border-color);
}
&:focus-visible {
2024-07-29 22:04:11 -07:00
color: var(--#{variables.$prefix}btn-hover-color);
@include gradients.gradient-bg(var(--#{variables.$prefix}btn-hover-bg));
border-color: var(--#{variables.$prefix}btn-hover-border-color);
outline: 0;
// Avoid using mixin so we can pass custom focus shadow properly
2024-07-29 22:04:11 -07:00
@if variables.$enable-shadows {
box-shadow: var(--#{variables.$prefix}btn-box-shadow), var(--#{variables.$prefix}btn-focus-box-shadow);
} @else {
2024-07-29 22:04:11 -07:00
box-shadow: var(--#{variables.$prefix}btn-focus-box-shadow);
}
2013-12-18 14:29:33 -08:00
}
.btn-check:focus-visible + & {
2024-07-29 22:04:11 -07:00
border-color: var(--#{variables.$prefix}btn-hover-border-color);
outline: 0;
// Avoid using mixin so we can pass custom focus shadow properly
2024-07-29 22:04:11 -07:00
@if variables.$enable-shadows {
box-shadow: var(--#{variables.$prefix}btn-box-shadow), var(--#{variables.$prefix}btn-focus-box-shadow);
} @else {
2024-07-29 22:04:11 -07:00
box-shadow: var(--#{variables.$prefix}btn-focus-box-shadow);
}
}
2020-06-04 15:59:24 +02:00
.btn-check:checked + &,
:not(.btn-check) + &:active,
&:first-child:active,
&.active,
&.show {
2024-07-29 22:04:11 -07:00
color: var(--#{variables.$prefix}btn-active-color);
background-color: var(--#{variables.$prefix}btn-active-bg);
// Remove CSS gradients if they're enabled
2024-07-29 22:04:11 -07:00
background-image: if(variables.$enable-gradients, none, null);
border-color: var(--#{variables.$prefix}btn-active-border-color);
@include box-shadow.box-shadow(var(--#{variables.$prefix}btn-active-shadow));
&:focus-visible {
// Avoid using mixin so we can pass custom focus shadow properly
2024-07-29 22:04:11 -07:00
@if variables.$enable-shadows {
box-shadow: var(--#{variables.$prefix}btn-active-shadow), var(--#{variables.$prefix}btn-focus-box-shadow);
} @else {
2024-07-29 22:04:11 -07:00
box-shadow: var(--#{variables.$prefix}btn-focus-box-shadow);
}
}
}
.btn-check:checked:focus-visible + & {
// Avoid using mixin so we can pass custom focus shadow properly
2024-07-29 22:04:11 -07:00
@if variables.$enable-shadows {
box-shadow: var(--#{variables.$prefix}btn-active-shadow), var(--#{variables.$prefix}btn-focus-box-shadow);
} @else {
2024-07-29 22:04:11 -07:00
box-shadow: var(--#{variables.$prefix}btn-focus-box-shadow);
}
}
&:disabled,
&.disabled,
fieldset:disabled & {
2024-07-29 22:04:11 -07:00
color: var(--#{variables.$prefix}btn-disabled-color);
pointer-events: none;
2024-07-29 22:04:11 -07:00
background-color: var(--#{variables.$prefix}btn-disabled-bg);
background-image: if(variables.$enable-gradients, none, null);
border-color: var(--#{variables.$prefix}btn-disabled-border-color);
opacity: var(--#{variables.$prefix}btn-disabled-opacity);
@include box-shadow.box-shadow(none);
}
2012-12-19 22:25:56 -08:00
}
2012-01-30 20:50:51 -08:00
2015-04-18 11:15:40 -07:00
//
2012-01-30 20:50:51 -08:00
// Alternate buttons
2015-04-18 11:15:40 -07:00
//
2012-01-30 20:50:51 -08:00
// scss-docs-start btn-variant-loops
2024-07-29 22:04:11 -07:00
@each $color, $value in variables.$theme-colors {
.btn-#{$color} {
@if $color == "light" {
2024-07-29 22:04:11 -07:00
@include buttons.button-variant(
$value,
$value,
2024-07-29 22:04:11 -07:00
$hover-background: functions.shade-color($value, variables.$btn-hover-bg-shade-amount),
$hover-border: functions.shade-color($value, variables.$btn-hover-border-shade-amount),
$active-background: functions.shade-color($value, variables.$btn-active-bg-shade-amount),
$active-border: functions.shade-color($value, variables.$btn-active-border-shade-amount)
);
} @else if $color == "dark" {
2024-07-29 22:04:11 -07:00
@include buttons.button-variant(
$value,
$value,
2024-07-29 22:04:11 -07:00
$hover-background: functions.tint-color($value, variables.$btn-hover-bg-tint-amount),
$hover-border: functions.tint-color($value, variables.$btn-hover-border-tint-amount),
$active-background: functions.tint-color($value, variables.$btn-active-bg-tint-amount),
$active-border: functions.tint-color($value, variables.$btn-active-border-tint-amount)
);
} @else {
2024-07-29 22:04:11 -07:00
@include buttons.button-variant($value, $value);
}
}
2012-01-30 20:50:51 -08:00
}
2024-07-29 22:04:11 -07:00
@each $color, $value in variables.$theme-colors {
.btn-outline-#{$color} {
2024-07-29 22:04:11 -07:00
@include buttons.button-outline-variant($value);
}
2015-08-09 22:48:48 -07:00
}
// scss-docs-end btn-variant-loops
2015-08-09 22:48:48 -07:00
2015-04-18 11:15:40 -07:00
//
// Link buttons
2015-04-18 11:15:40 -07:00
//
// Make a button look and behave like a link
.btn-link {
2024-07-29 22:04:11 -07:00
--#{variables.$prefix}btn-font-weight: #{variables.$font-weight-normal};
--#{variables.$prefix}btn-color: #{variables.$btn-link-color};
--#{variables.$prefix}btn-bg: transparent;
--#{variables.$prefix}btn-border-color: transparent;
--#{variables.$prefix}btn-hover-color: #{variables.$btn-link-hover-color};
--#{variables.$prefix}btn-hover-border-color: transparent;
--#{variables.$prefix}btn-active-color: #{variables.$btn-link-hover-color};
--#{variables.$prefix}btn-active-border-color: transparent;
--#{variables.$prefix}btn-disabled-color: #{variables.$btn-link-disabled-color};
--#{variables.$prefix}btn-disabled-border-color: transparent;
--#{variables.$prefix}btn-box-shadow: 0 0 0 #000; // Can't use `none` as keyword negates all values when used with multiple shadows
--#{variables.$prefix}btn-focus-shadow-rgb: #{variables.$btn-link-focus-shadow-rgb};
text-decoration: variables.$link-decoration;
@if variables.$enable-gradients {
2022-09-02 15:48:48 -07:00
background-image: none;
}
&:hover,
&:focus-visible {
2024-07-29 22:04:11 -07:00
text-decoration: variables.$link-hover-decoration;
2013-07-06 22:13:37 -07:00
}
&:focus-visible {
2024-07-29 22:04:11 -07:00
color: var(--#{variables.$prefix}btn-color);
}
&:hover {
2024-07-29 22:04:11 -07:00
color: var(--#{variables.$prefix}btn-hover-color);
}
// No need for an active state here
2012-08-31 14:02:18 -07:00
}
2015-04-18 11:15:40 -07:00
//
// Button Sizes
2015-04-18 11:15:40 -07:00
//
.btn-lg {
2024-07-29 22:04:11 -07:00
@include buttons.button-size(variables.$btn-padding-y-lg, variables.$btn-padding-x-lg, variables.$btn-font-size-lg, variables.$btn-border-radius-lg);
}
2013-12-03 18:03:04 -08:00
.btn-sm {
2024-07-29 22:04:11 -07:00
@include buttons.button-size(variables.$btn-padding-y-sm, variables.$btn-padding-x-sm, variables.$btn-font-size-sm, variables.$btn-border-radius-sm);
2013-07-29 17:08:04 -07:00
}