Skip to content
TheChatArchiveThe Chat Archive
Qwenqwen3-30b-a3b· Alibaba (Qwen)Hugging Face LMArena Human Preference 140K

how to implement using html and scss a website header which has a height of a whole…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Googlegemma-3-27b-it’s answer.
  1. User

    how to implement using html and scss a website header which has a height of a whole screen but it smoothly collapses on scroll to the slim version on the top

  2. Qwen Assistant

    To implement a full-screen header that smoothly collapses into a slim version when the user scrolls, we can use HTML, SCSS, and JavaScript. Below is a clean and functional implementation that ensures a smooth transition and proper layout adjustments.


    ✅ Features

    • Header starts at full screen height (100vh)
    • Smooth collapse to a smaller height (e.g., 60px) on scroll
    • Content is adjusted to avoid overlap
    • Responsive and lightweight

    🧩 HTML Structure

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      <title>Collapsible Header</title>
      <link rel="stylesheet" href="styles.css" />
    </head>
    <body>
      <header class="hero-header">
        <div class="hero-content">
          <h1>Welcome to My Site</h1>
        </div>
      </header>
    
      <main>
        <p>Scroll down to see the header collapse.</p>
        <div style="height: 2000px;">Scroll down...</div>
      </main>
    
      <script src="script.js"></script>
    </body>
    </html>
    

    🎨 SCSS (styles.scss)

    body {
      margin: 0;
      font-family: sans-serif;
    }
    
    .hero-header {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100vh;
      background: #333;
      color: white;
      transition: height 0.3s ease;
    
      &.collapsed {
        height: 60px;
      }
    
      .hero-content {
        display: flex;
        align-items: center;
        justify-content: center;
        height: 100%;
        text-align: center;
      }
    }
    
    main {
      padding-top: 100vh;
      transition: padding-top 0.3s ease;
    }
    

    🧠 JavaScript (script.js)

    const header = document.querySelector('.hero-header');
    const main = document.querySelector('main');
    
    window.addEventListener('scroll', () => {
      if (window.scrollY > 0) {
        header.classList.add('collapsed');
        main.style.paddingTop = '60px';
      } else {
        header.classList.remove('collapsed');
        main.style.paddingTop = '100vh';
      }
    });
    

    🔍 How It Works

    1. Header is fixed at the top with height: 100vh.
    2. Main content has padding-top: 100vh to prevent overlap.
    3. When the user scrolls down (window.scrollY > 0), the header collapses to 60px, and the main content's padding-top is updated to match the new height.
    4. The transition on the header and main content ensures smooth animation.

    💡 Optional Enhancements

    • Scroll direction tracking: Collapse only when scrolling down, expand when scrolling up.
    • Mobile responsiveness: Adjust the collapsed height or add media queries.
    • Debouncing: Improve performance for frequent scroll events.

    📦 Final Notes

    • This approach uses position: fixed for the header, which is ideal for full-screen headers that remain visible while scrolling.
    • The transition on both the header height and main content padding ensures a smooth visual effect.
    • You can customize the 60px height to suit your design needs.

    Let me know if you'd like a version with scroll direction tracking or animations! 🚀

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.