Udoro

Sticky/Overlay header CSS - single row

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