Advertisement
Udoro

Sticky/Overlay header CSS

Feb 5th, 2022 (edited)
751
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 2.11 KB | None | 0 0
  1. :root{
  2.     --header-height: 120px;
  3.     --header-bg-color: brown;
  4.     --hero-top-padding: 75px;
  5.     --sticky-height: 80px;
  6.     --sticky-bg-color: green;
  7.     --sticky-shadow: 0px 5px 20px -10px rgb(0,0,0,0.39);
  8.     /* --scroll-distance: 400; this is no longer necessary, set value in JavaScript (scrollDistance)*/
  9.     --animation-name: slide; /* fade or slide */
  10.     --animation-duration: 0.6s;
  11.     --animation-easing: ease;
  12.     /*--overlay-header: false; this is no longer necessary, set value in JavaScript (checkOverlay) */
  13.     /*--sticky-header: true; this is no longer necessary, set value in JavaScript (checkSticky) */
  14.  
  15.  
  16. }
  17.  
  18.  
  19.  
  20. .header {
  21.     height: var(--header-height);
  22.     transition: height 1s ease;
  23. }
  24.  
  25.  
  26. /*hide sticky row by default*/
  27. .header .header-row[data-sticky-header]{
  28.     transform:translateY(-500%)
  29. }
  30.  
  31. /*unhide when sticky */
  32. .header.sticky .header-row[data-sticky-header]{
  33.     transform:translateY(0)
  34. }
  35.  
  36.  
  37.  
  38. .header.sticky .header-row:not([data-sticky-header]){
  39.     display: none;
  40. }
  41.  
  42. /*overlay properties*/
  43. .header.overlay {
  44.     position: absolute;
  45.     top: 0;
  46.     background-color: transparent;
  47. }
  48.  
  49. /*offset top padding for overlay hero section*/
  50.  
  51. .has-overlay #hero {
  52.     padding-top: var(--hero-top-padding)
  53. }
  54.  
  55.  
  56. /*sticky header properties*/
  57. .header.sticky {
  58.     padding-top: 0;
  59.     position: fixed;
  60.     top: 0;
  61.     background-color: var(--sticky-bg-color);
  62.     height: var(--sticky-height);
  63.     box-shadow: var(--sticky-shadow);
  64.     animation: var(--animation-name) var(--animation-duration) var(--animation-easing);
  65. }
  66.  
  67. body.has-sticky{
  68.     margin-top: var(--sticky-height)  /*use only if scroll distance is greater than or equal to header height, don't use in overlay header*/
  69. }
  70.  
  71. /*initial logo size for sticky header*/
  72.  
  73. .header-row[data-sticky-header] .logo {
  74.     width: 80px;
  75.     transition: width 1s;
  76. }
  77.  
  78.  
  79. /*logo size for sticky */
  80.  
  81. .header.sticky .logo{
  82.     width: 50px
  83. }
  84.  
  85. /*reduce padding of menu item  (optional) */
  86.  
  87. .sticky #split_menu_2 a{
  88.     padding-top: 0.5rem;
  89. }
  90.  
  91. /*animations*/
  92.  
  93. @keyframes fade{
  94.     from {opacity:0}
  95.     to {opacity:1}
  96. }
  97.  
  98. @keyframes slide{
  99.     from{transform: translateY(-100px)}
  100.     to {transform: translateY(0)}
  101. }
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement