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

260 lines
9.4 KiB
SCSS
Raw Normal View History

2024-07-29 22:04:11 -07:00
@use "sass:map";
@use "mixins/border-radius";
@use "mixins/box-shadow";
@use "mixins/breakpoints";
@use "mixins/caret";
@use "mixins/gradients";
@use "variables";
@use "vendor/rfs";
// The dropdown wrapper (`<div>`)
.dropup,
.dropend,
.dropdown,
.dropstart,
.dropup-center,
.dropdown-center {
2013-08-01 20:07:34 +02:00
position: relative;
}
.dropdown-toggle {
white-space: nowrap;
// Generate the caret automatically
2024-07-29 22:04:11 -07:00
@include caret.caret();
}
// The dropdown menu
.dropdown-menu {
2021-11-28 00:56:37 -10:00
// scss-docs-start dropdown-css-vars
2024-07-29 22:04:11 -07:00
--#{variables.$prefix}dropdown-zindex: #{variables.$zindex-dropdown};
--#{variables.$prefix}dropdown-min-width: #{variables.$dropdown-min-width};
--#{variables.$prefix}dropdown-padding-x: #{variables.$dropdown-padding-x};
--#{variables.$prefix}dropdown-padding-y: #{variables.$dropdown-padding-y};
--#{variables.$prefix}dropdown-spacer: #{variables.$dropdown-spacer};
@include rfs.rfs(variables.$dropdown-font-size, --#{variables.$prefix}dropdown-font-size);
--#{variables.$prefix}dropdown-color: #{variables.$dropdown-color};
--#{variables.$prefix}dropdown-bg: #{variables.$dropdown-bg};
--#{variables.$prefix}dropdown-border-color: #{variables.$dropdown-border-color};
--#{variables.$prefix}dropdown-border-radius: #{variables.$dropdown-border-radius};
--#{variables.$prefix}dropdown-border-width: #{variables.$dropdown-border-width};
--#{variables.$prefix}dropdown-inner-border-radius: #{variables.$dropdown-inner-border-radius};
--#{variables.$prefix}dropdown-divider-bg: #{variables.$dropdown-divider-bg};
--#{variables.$prefix}dropdown-divider-margin-y: #{variables.$dropdown-divider-margin-y};
--#{variables.$prefix}dropdown-box-shadow: #{variables.$dropdown-box-shadow};
--#{variables.$prefix}dropdown-link-color: #{variables.$dropdown-link-color};
--#{variables.$prefix}dropdown-link-hover-color: #{variables.$dropdown-link-hover-color};
--#{variables.$prefix}dropdown-link-hover-bg: #{variables.$dropdown-link-hover-bg};
--#{variables.$prefix}dropdown-link-active-color: #{variables.$dropdown-link-active-color};
--#{variables.$prefix}dropdown-link-active-bg: #{variables.$dropdown-link-active-bg};
--#{variables.$prefix}dropdown-link-disabled-color: #{variables.$dropdown-link-disabled-color};
--#{variables.$prefix}dropdown-item-padding-x: #{variables.$dropdown-item-padding-x};
--#{variables.$prefix}dropdown-item-padding-y: #{variables.$dropdown-item-padding-y};
--#{variables.$prefix}dropdown-header-color: #{variables.$dropdown-header-color};
--#{variables.$prefix}dropdown-header-padding-x: #{variables.$dropdown-header-padding-x};
--#{variables.$prefix}dropdown-header-padding-y: #{variables.$dropdown-header-padding-y};
2021-11-28 00:56:37 -10:00
// scss-docs-end dropdown-css-vars
position: absolute;
2024-07-29 22:04:11 -07:00
z-index: var(--#{variables.$prefix}dropdown-zindex);
display: none; // none by default, but block on "open" of the menu
2024-07-29 22:04:11 -07:00
min-width: var(--#{variables.$prefix}dropdown-min-width);
padding: var(--#{variables.$prefix}dropdown-padding-y) var(--#{variables.$prefix}dropdown-padding-x);
margin: 0; // Override default margin of ul
2024-07-29 22:04:11 -07:00
@include rfs.font-size(var(--#{variables.$prefix}dropdown-font-size));
color: var(--#{variables.$prefix}dropdown-color);
text-align: left; // Ensures proper alignment if parent has it changed (e.g., modal footer)
list-style: none;
2024-07-29 22:04:11 -07:00
background-color: var(--#{variables.$prefix}dropdown-bg);
background-clip: padding-box;
2024-07-29 22:04:11 -07:00
border: var(--#{variables.$prefix}dropdown-border-width) solid var(--#{variables.$prefix}dropdown-border-color);
@include border-radius.border-radius(var(--#{variables.$prefix}dropdown-border-radius));
@include box-shadow.box-shadow(var(--#{variables.$prefix}dropdown-box-shadow));
&[data-bs-popper] {
top: 100%;
left: 0;
2024-07-29 22:04:11 -07:00
margin-top: var(--#{variables.$prefix}dropdown-spacer);
}
2024-07-29 22:04:11 -07:00
@if variables.$dropdown-padding-y == 0 {
> .dropdown-item:first-child,
> li:first-child .dropdown-item {
2024-07-29 22:04:11 -07:00
@include border-radius.border-top-radius(var(--#{variables.$prefix}dropdown-inner-border-radius));
}
> .dropdown-item:last-child,
> li:last-child .dropdown-item {
2024-07-29 22:04:11 -07:00
@include border-radius.border-bottom-radius(var(--#{variables.$prefix}dropdown-inner-border-radius));
}
}
2015-08-17 11:21:10 -07:00
}
// scss-docs-start responsive-breakpoints
2020-11-25 22:12:32 +02:00
// We deliberately hardcode the `bs-` prefix because we check
// this custom property in JS to determine Popper's positioning
2024-07-29 22:04:11 -07:00
@each $breakpoint in map.keys(variables.$grid-breakpoints) {
@include breakpoints.media-breakpoint-up($breakpoint) {
$infix: breakpoints.breakpoint-infix($breakpoint, variables.$grid-breakpoints);
.dropdown-menu#{$infix}-start {
2020-11-25 22:12:32 +02:00
--bs-position: start;
&[data-bs-popper] {
right: auto;
left: 0;
}
}
.dropdown-menu#{$infix}-end {
2020-11-25 22:12:32 +02:00
--bs-position: end;
&[data-bs-popper] {
right: 0;
left: auto;
}
}
}
}
// scss-docs-end responsive-breakpoints
// Allow for dropdowns to go bottom up (aka, dropup-menu)
// Just add .dropup after the standard .dropdown class and you're set.
.dropup {
.dropdown-menu[data-bs-popper] {
top: auto;
bottom: 100%;
margin-top: 0;
2024-07-29 22:04:11 -07:00
margin-bottom: var(--#{variables.$prefix}dropdown-spacer);
}
.dropdown-toggle {
2024-07-29 22:04:11 -07:00
@include caret.caret(up);
}
}
.dropend {
.dropdown-menu[data-bs-popper] {
top: 0;
right: auto;
left: 100%;
margin-top: 0;
2024-07-29 22:04:11 -07:00
margin-left: var(--#{variables.$prefix}dropdown-spacer);
}
.dropdown-toggle {
2024-07-29 22:04:11 -07:00
@include caret.caret(end);
&::after {
vertical-align: 0;
}
}
}
.dropstart {
.dropdown-menu[data-bs-popper] {
top: 0;
right: 100%;
left: auto;
margin-top: 0;
2024-07-29 22:04:11 -07:00
margin-right: var(--#{variables.$prefix}dropdown-spacer);
}
.dropdown-toggle {
2024-07-29 22:04:11 -07:00
@include caret.caret(start);
&::before {
vertical-align: 0;
}
}
}
// Dividers (basically an `<hr>`) within the dropdown
2015-08-17 11:21:10 -07:00
.dropdown-divider {
2019-08-21 10:33:26 +02:00
height: 0;
2024-07-29 22:04:11 -07:00
margin: var(--#{variables.$prefix}dropdown-divider-margin-y) 0;
2019-08-21 10:33:26 +02:00
overflow: hidden;
2024-07-29 22:04:11 -07:00
border-top: 1px solid var(--#{variables.$prefix}dropdown-divider-bg);
opacity: 1; // Revisit in v6 to de-dupe styles that conflict with <hr> element
}
2012-01-08 00:49:38 -08:00
// Links, buttons, and more within the dropdown menu
2015-08-23 01:12:00 -07:00
//
// `<button>`-specific styles are denoted with `// For <button>s`
.dropdown-item {
display: block;
2015-08-23 01:12:00 -07:00
width: 100%; // For `<button>`s
2024-07-29 22:04:11 -07:00
padding: var(--#{variables.$prefix}dropdown-item-padding-y) var(--#{variables.$prefix}dropdown-item-padding-x);
clear: both;
2024-07-29 22:04:11 -07:00
font-weight: variables.$font-weight-normal;
color: var(--#{variables.$prefix}dropdown-link-color);
2015-08-23 01:12:00 -07:00
text-align: inherit; // For `<button>`s
2024-07-29 22:04:11 -07:00
text-decoration: if(variables.$link-decoration == none, null, none);
white-space: nowrap; // prevent links from randomly breaking onto new lines
background-color: transparent; // For `<button>`s
2015-08-23 01:12:00 -07:00
border: 0; // For `<button>`s
2024-07-29 22:04:11 -07:00
@include border-radius.border-radius(var(--#{variables.$prefix}dropdown-item-border-radius, 0));
&:hover,
&:focus {
2024-07-29 22:04:11 -07:00
color: var(--#{variables.$prefix}dropdown-link-hover-color);
text-decoration: if(variables.$link-hover-decoration == underline, none, null);
@include gradients.gradient-bg(var(--#{variables.$prefix}dropdown-link-hover-bg));
}
&.active,
&:active {
2024-07-29 22:04:11 -07:00
color: var(--#{variables.$prefix}dropdown-link-active-color);
text-decoration: none;
2024-07-29 22:04:11 -07:00
@include gradients.gradient-bg(var(--#{variables.$prefix}dropdown-link-active-bg));
}
&.disabled,
&:disabled {
2024-07-29 22:04:11 -07:00
color: var(--#{variables.$prefix}dropdown-link-disabled-color);
pointer-events: none;
background-color: transparent;
// Remove CSS gradients if they're enabled
2024-07-29 22:04:11 -07:00
background-image: if(variables.$enable-gradients, none, null);
}
}
2017-04-14 11:25:53 +02:00
.dropdown-menu.show {
display: block;
}
// Dropdown section headers
.dropdown-header {
display: block;
2024-07-29 22:04:11 -07:00
padding: var(--#{variables.$prefix}dropdown-header-padding-y) var(--#{variables.$prefix}dropdown-header-padding-x);
margin-bottom: 0; // for use with heading elements
2024-07-29 22:04:11 -07:00
@include rfs.font-size(variables.$font-size-sm);
color: var(--#{variables.$prefix}dropdown-header-color);
white-space: nowrap; // as with > li > a
}
// Dropdown text
.dropdown-item-text {
display: block;
2024-07-29 22:04:11 -07:00
padding: var(--#{variables.$prefix}dropdown-item-padding-y) var(--#{variables.$prefix}dropdown-item-padding-x);
color: var(--#{variables.$prefix}dropdown-link-color);
}
// Dark dropdowns
.dropdown-menu-dark {
2021-11-28 00:56:37 -10:00
// scss-docs-start dropdown-dark-css-vars
2024-07-29 22:04:11 -07:00
--#{variables.$prefix}dropdown-color: #{variables.$dropdown-dark-color};
--#{variables.$prefix}dropdown-bg: #{variables.$dropdown-dark-bg};
--#{variables.$prefix}dropdown-border-color: #{variables.$dropdown-dark-border-color};
--#{variables.$prefix}dropdown-box-shadow: #{variables.$dropdown-dark-box-shadow};
--#{variables.$prefix}dropdown-link-color: #{variables.$dropdown-dark-link-color};
--#{variables.$prefix}dropdown-link-hover-color: #{variables.$dropdown-dark-link-hover-color};
--#{variables.$prefix}dropdown-divider-bg: #{variables.$dropdown-dark-divider-bg};
--#{variables.$prefix}dropdown-link-hover-bg: #{variables.$dropdown-dark-link-hover-bg};
--#{variables.$prefix}dropdown-link-active-color: #{variables.$dropdown-dark-link-active-color};
--#{variables.$prefix}dropdown-link-active-bg: #{variables.$dropdown-dark-link-active-bg};
--#{variables.$prefix}dropdown-link-disabled-color: #{variables.$dropdown-dark-link-disabled-color};
--#{variables.$prefix}dropdown-header-color: #{variables.$dropdown-dark-header-color};
2021-11-28 00:56:37 -10:00
// scss-docs-end dropdown-dark-css-vars
}