_navbar.less 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. // Contents
  2. //
  3. // Navbar
  4. // Navbar brand
  5. // Navbar nav
  6. // Navbar text
  7. // Navbar divider
  8. // Responsive navbar
  9. // Navbar position
  10. // Navbar themes
  11. // Navbar
  12. //
  13. // Provide a static navbar from which we expand to create full-width, fixed, and
  14. // other navbar variations.
  15. // LESS PORT: Because of the way `:extend()` works in Less (and the workaround we’re using to
  16. // emulate Sass’ placeholder selectors) we need to include the selectors that extend the
  17. // placeholders at the root. Then `&:extend(<placeholder> all)` will attach the selectors to every
  18. // instance of the placeholder.
  19. .container,
  20. .container-fluid {
  21. &:extend(\%container-flex-properties all);
  22. }
  23. .navbar {
  24. position: relative;
  25. display: flex;
  26. flex-wrap: wrap; // allow us to do the line break for collapsing content
  27. align-items: center;
  28. justify-content: space-between; // space out brand from logo
  29. padding: @navbar-padding-y @navbar-padding-x;
  30. // Because flex properties aren't inherited, we need to redeclare these first
  31. // few properties so that content nested within behave properly.
  32. // LESS PORT: Unfortunately we have to use an actual selector here in order to be able to
  33. // `:extend()` it later. This means that the selector is output in the compiled CSS, creating a
  34. // small disparity between the Less and Sass versions.
  35. // LESS PORT: The `-@{breakpoint}` suffix is omitted from the selector here since it’s not needed
  36. // with the `:extend()` workaround we’re using.
  37. \%container-flex-properties {
  38. display: flex;
  39. flex-wrap: wrap;
  40. align-items: center;
  41. justify-content: space-between;
  42. }
  43. // LESS PORT: Because of the way `:extend()` works in Less (and the workaround we’re using to
  44. // emulate Sass’ placeholder selectors) we include this selector at the root, instead. (We also
  45. // omit the `-@{breakpoint}` suffix since it’s not needed.)
  46. // .container,
  47. // .container-fluid {
  48. // &:extend(\%container-flex-properties);
  49. // }
  50. // LESS PORT: Since we `&:extend(.container-fluid all)` in `_grid.less` we don’t need to output
  51. // the container-max-width selectors here. Using the `all` means the container-max-width
  52. // selectors will already be attached to all instances of `.container-fluid`.
  53. // each(@container-max-widths, #(@container-max-width, @breakpoint) {
  54. // // LESS PORT: A variable is required here to do the selector interpolation, since an
  55. // // expression cannot be interpolated like in the Sass version.
  56. // @infix: breakpoint-infix(@breakpoint, @container-max-widths);
  57. // // LESS PORT: The Sass version actually uses `> .container` here but that doesn’t seem to
  58. // // match the output CSS, so we‘re omitting it.
  59. // .container@{infix} {
  60. // &:extend(.navbar \%container-flex-properties);
  61. // }
  62. // });
  63. }
  64. // Navbar brand
  65. //
  66. // Used for brand, project, or site names.
  67. .navbar-brand {
  68. display: inline-block;
  69. padding-top: @navbar-brand-padding-y;
  70. padding-bottom: @navbar-brand-padding-y;
  71. margin-right: @navbar-padding-x;
  72. #font-size(@navbar-brand-font-size);
  73. line-height: inherit;
  74. white-space: nowrap;
  75. #hover-focus({
  76. text-decoration: none;
  77. });
  78. }
  79. // Navbar nav
  80. //
  81. // Custom navbar navigation (doesn't require `.nav`, but does make use of `.nav-link`).
  82. .navbar-nav {
  83. display: flex;
  84. flex-direction: column; // cannot use `inherit` to get the `.navbar`s value
  85. padding-left: 0;
  86. margin-bottom: 0;
  87. list-style: none;
  88. .nav-link {
  89. padding-right: 0;
  90. padding-left: 0;
  91. }
  92. .dropdown-menu {
  93. position: static;
  94. float: none;
  95. }
  96. }
  97. // Navbar text
  98. //
  99. //
  100. .navbar-text {
  101. display: inline-block;
  102. padding-top: @nav-link-padding-y;
  103. padding-bottom: @nav-link-padding-y;
  104. }
  105. // Responsive navbar
  106. //
  107. // Custom styles for responsive collapsing and toggling of navbar contents.
  108. // Powered by the collapse Bootstrap JavaScript plugin.
  109. // When collapsed, prevent the toggleable navbar contents from appearing in
  110. // the default flexbox row orientation. Requires the use of `flex-wrap: wrap`
  111. // on the `.navbar` parent.
  112. .navbar-collapse {
  113. flex-basis: 100%;
  114. flex-grow: 1;
  115. // For always expanded or extra full navbars, ensure content aligns itself
  116. // properly vertically. Can be easily overridden with flex utilities.
  117. align-items: center;
  118. }
  119. // Button for toggling the navbar when in its collapsed state
  120. .navbar-toggler {
  121. padding: @navbar-toggler-padding-y @navbar-toggler-padding-x;
  122. #font-size(@navbar-toggler-font-size);
  123. line-height: 1;
  124. background-color: transparent; // remove default button style
  125. border: @border-width solid transparent; // remove default button style
  126. #border-radius(@navbar-toggler-border-radius);
  127. #hover-focus({
  128. text-decoration: none;
  129. });
  130. }
  131. // Keep as a separate element so folks can easily override it with another icon
  132. // or image file as needed.
  133. .navbar-toggler-icon {
  134. display: inline-block;
  135. width: 1.5em;
  136. height: 1.5em;
  137. vertical-align: middle;
  138. content: "";
  139. background: no-repeat center center;
  140. background-size: 100% 100%;
  141. }
  142. // Generate series of `.navbar-expand-*` responsive classes for configuring
  143. // where your navbar collapses.
  144. //.navbar-expand {
  145. // @each $breakpoint in map-keys($grid-breakpoints) {
  146. // $next: breakpoint-next($breakpoint, $grid-breakpoints);
  147. // $infix: breakpoint-infix($next, $grid-breakpoints);
  148. //
  149. // &#{$infix} {
  150. // @include media-breakpoint-down($breakpoint) {
  151. // %container-navbar-expand-#{$breakpoint} {
  152. // padding-right: 0;
  153. // padding-left: 0;
  154. // }
  155. //
  156. // > .container,
  157. // > .container-fluid {
  158. // @extend %container-navbar-expand-#{$breakpoint};
  159. // }
  160. //
  161. // @each $size, $container-max-width in $container-max-widths {
  162. // > .container#{breakpoint-infix($size, $container-max-widths)} {
  163. // @extend %container-navbar-expand-#{$breakpoint};
  164. // }
  165. // }
  166. // }
  167. //
  168. // @include media-breakpoint-up($next) {
  169. // flex-flow: row nowrap;
  170. // justify-content: flex-start;
  171. //
  172. // .navbar-nav {
  173. // flex-direction: row;
  174. //
  175. // .dropdown-menu {
  176. // position: absolute;
  177. // }
  178. //
  179. // .nav-link {
  180. // padding-right: $navbar-nav-link-padding-x;
  181. // padding-left: $navbar-nav-link-padding-x;
  182. // }
  183. // }
  184. //
  185. // // For nesting containers, have to redeclare for alignment purposes
  186. // %container-nesting-#{$breakpoint} {
  187. // flex-wrap: nowrap;
  188. // }
  189. //
  190. // > .container,
  191. // > .container-fluid {
  192. // @extend %container-nesting-#{$breakpoint};
  193. // }
  194. //
  195. // @each $size, $container-max-width in $container-max-widths {
  196. // > .container#{breakpoint-infix($size, $container-max-widths)} {
  197. // @extend %container-nesting-#{$breakpoint};
  198. // }
  199. // }
  200. //
  201. // .navbar-collapse {
  202. // display: flex !important; // stylelint-disable-line declaration-no-important
  203. //
  204. // // Changes flex-bases to auto because of an IE10 bug
  205. // flex-basis: auto;
  206. // }
  207. //
  208. // .navbar-toggler {
  209. // display: none;
  210. // }
  211. // }
  212. // }
  213. // }
  214. //}
  215. // LESS PORT: Because of the way `:extend()` works in Less (and the workaround we’re using to
  216. // emulate Sass’ placeholder selectors) we need to include the selectors that extend the
  217. // placeholders at the root. Then `&:extend(<placeholder> all)` will attach the selectors to every
  218. // instance of the placeholder.
  219. > .container,
  220. > .container-fluid {
  221. &:extend(\%container-navbar-expand all);
  222. &:extend(\%container-nesting all);
  223. }
  224. each(map-keys(@grid-breakpoints), #(@breakpoint) {
  225. .navbar-expand {
  226. @next: breakpoint-next(@breakpoint, @grid-breakpoints);
  227. @infix: breakpoint-infix(@next, @grid-breakpoints);
  228. &@{infix} {
  229. #media-breakpoint-down(@breakpoint, {
  230. // LESS PORT: Unfortunately we have to use an actual selector here in order to be able
  231. // to `:extend()` it later. This means that the selector is output in the compiled CSS,
  232. // creating a small disparity between the Less and Sass versions.
  233. // LESS PORT: The `-@{breakpoint}` suffix is omitted from the selector here since it’s
  234. // not needed with the `:extend()` workaround we’re using.
  235. > \%container-navbar-expand {
  236. padding-right: 0;
  237. padding-left: 0;
  238. }
  239. // LESS PORT: Because of the way `:extend()` works in Less (and the workaround we’re
  240. // using to emulate Sass’ placeholder selectors) we include this selector at the root,
  241. // instead. (We also omit the `-@{breakpoint}` suffix since it’s not needed.)
  242. // > .container,
  243. // > .container-fluid {
  244. // &:extend(\%container-navbar-expand-@{breakpoint});
  245. // }
  246. // LESS PORT: Since we `&:extend(.container-fluid all)` in `_grid.less` we don’t need to
  247. // output the container-max-width selectors here. Using the `all` means the
  248. // container-max-width selectors will already be attached to all instances of
  249. // `.container-fluid`.
  250. // each(@container-max-widths, #(@container-max-width, @size) {
  251. // // LESS PORT: A variable is required here to do the selector interpolation, since an
  252. // // expression cannot be interpolated like in the Sass version.
  253. // @infix: breakpoint-infix(@size, @container-max-widths);
  254. // > .container@{infix} {
  255. // &:extend(\%container-navbar-expand-@{breakpoint});
  256. // }
  257. // });
  258. });
  259. #media-breakpoint-up(@next, {
  260. flex-flow: row nowrap;
  261. justify-content: flex-start;
  262. .navbar-nav {
  263. flex-direction: row;
  264. .dropdown-menu {
  265. position: absolute;
  266. }
  267. .nav-link {
  268. padding-right: @navbar-nav-link-padding-x;
  269. padding-left: @navbar-nav-link-padding-x;
  270. }
  271. }
  272. // For nesting containers, have to redeclare for alignment purposes
  273. // LESS PORT: Unfortunately we have to use an actual selector here in order to be able
  274. // to `:extend()` it later. This means that the selector is output in the compiled CSS,
  275. // creating a small disparity between the Less and Sass versions.
  276. // LESS PORT: The `-@{breakpoint}` suffix is omitted from the selector here since it’s
  277. // not needed with the `:extend()` workaround we’re using. We also have to prefix with
  278. // a `>` so that the immediate decendant selector will be included when we `:extend()`.
  279. > \%container-nesting {
  280. flex-wrap: nowrap;
  281. }
  282. // LESS PORT: The `-@{breakpoint}` suffix is omitted from the since the
  283. // \%container-nesting-@{breakpoint} {
  284. // flex-wrap: nowrap;
  285. // }
  286. // LESS PORT: Because of the way `:extend()` works in Less (and the workaround we’re
  287. // using to emulate Sass’ placeholder selectors) we include this selector at the root,
  288. // instead. (We also omit the `-@{breakpoint}` suffix since it’s not needed.)
  289. // > .container,
  290. // > .container-fluid {
  291. // &:extend(\%container-nesting-@{breakpoint});
  292. // }
  293. // LESS PORT: Since we `&:extend(.container-fluid all)` in `_grid.less` we don’t need to
  294. // output the container-max-width selectors here. Using the `all` means the
  295. // container-max-width selectors will already be attached to all instances of
  296. // `.container-fluid`.
  297. // each(@container-max-widths, #(@container-max-width, @size) {
  298. // // LESS PORT: A variable is required here to do the selector interpolation, since an
  299. // // expression cannot be interpolated like in the Sass version.
  300. // @infix: breakpoint-infix(@size, @container-max-widths);
  301. // > .container@{infix} {
  302. // &:extend(\%container-nesting-@{breakpoint});
  303. // }
  304. // });
  305. .navbar-collapse {
  306. display: flex !important;
  307. // Changes flex-bases to auto because of an IE10 bug
  308. flex-basis: auto;
  309. }
  310. .navbar-toggler {
  311. display: none;
  312. }
  313. });
  314. }
  315. }
  316. });
  317. // Navbar themes
  318. //
  319. // Styles for switching between navbars with light or dark background.
  320. // Dark links against a light background
  321. .navbar-light {
  322. .navbar-brand {
  323. color: @navbar-light-brand-color;
  324. #hover-focus({
  325. color: @navbar-light-brand-hover-color;
  326. });
  327. }
  328. .navbar-nav {
  329. .nav-link {
  330. color: @navbar-light-color;
  331. #hover-focus({
  332. color: @navbar-light-hover-color;
  333. });
  334. &.disabled {
  335. color: @navbar-light-disabled-color;
  336. }
  337. }
  338. .show > .nav-link,
  339. .active > .nav-link,
  340. .nav-link.show,
  341. .nav-link.active {
  342. color: @navbar-light-active-color;
  343. }
  344. }
  345. .navbar-toggler {
  346. color: @navbar-light-color;
  347. border-color: @navbar-light-toggler-border-color;
  348. }
  349. .navbar-toggler-icon {
  350. background-image: escape-svg(@navbar-light-toggler-icon-bg);
  351. }
  352. .navbar-text {
  353. color: @navbar-light-color;
  354. a {
  355. color: @navbar-light-active-color;
  356. #hover-focus({
  357. color: @navbar-light-active-color;
  358. });
  359. }
  360. }
  361. }
  362. // White links against a dark background
  363. .navbar-dark {
  364. .navbar-brand {
  365. color: @navbar-dark-brand-color;
  366. #hover-focus({
  367. color: @navbar-dark-brand-hover-color;
  368. });
  369. }
  370. .navbar-nav {
  371. .nav-link {
  372. color: @navbar-dark-color;
  373. #hover-focus({
  374. color: @navbar-dark-hover-color;
  375. });
  376. &.disabled {
  377. color: @navbar-dark-disabled-color;
  378. }
  379. }
  380. .show > .nav-link,
  381. .active > .nav-link,
  382. .nav-link.show,
  383. .nav-link.active {
  384. color: @navbar-dark-active-color;
  385. }
  386. }
  387. .navbar-toggler {
  388. color: @navbar-dark-color;
  389. border-color: @navbar-dark-toggler-border-color;
  390. }
  391. .navbar-toggler-icon {
  392. background-image: escape-svg(@navbar-dark-toggler-icon-bg);
  393. }
  394. .navbar-text {
  395. color: @navbar-dark-color;
  396. a {
  397. color: @navbar-dark-active-color;
  398. #hover-focus({
  399. color: @navbar-dark-active-color;
  400. });
  401. }
  402. }
  403. }