Please ensure there is space reserved for the header above the content

Currently, I am working on creating a webpage with a unique banner design. My goal is for the content to scroll from the bottom and remain fixed directly under the upper portion of the banner.

Initially, my idea was to have the content box take up the size of the screen, include a large margin-top, and set overflow-y: scrolling. However, I found this method to be unattractive and not ideal for what I want to achieve.

My primary challenge now is figuring out how to accomplish this while maintaining just one scroll bar. I believe that setting the header to position: fixed may be necessary... but does anyone have a CSS or more mobile-friendly approach?

UPDATE:

To further illustrate, here is a JSFiddle link for experimentation: http://jsfiddle.net/r2gbyjcs/

Answer №1

Let's get started

Keep in mind that when it comes to coding, there's no such thing as "fancy" or "unfancy". If we were to define "fancy", it would simply mean unnecessary. So, instead of putting in extra effort for the sake of fanciness, focus on creating a fast and efficient implementation without adding complexity.

The Solution

To achieve the desired result, divide the header into 2 parts: Top and Bottom. Both parts should have the same background color to appear seamless, but set the top part with z-index: 0 and the bottom part with z-index: -1. Then, distribute the height between the two parts and adjust the margin-top of the content accordingly.

HTML:

<header>
    <div id="top">Hotel</div>
    <div id="bottom">Bottom half</div>
</header>
// The rest of your HTML content...

CSS:

body {
    margin: 0px;
}
header #top{
    height: 100px;
    background-color: #fb3f26;
    position: fixed;
    top: 0px;
    left:0px;
    right: 0px;
}
#content {
    background-color: #e0ecf3;
    padding: 20px;
    margin-top: 200px;
}

header #bottom{
    height: 200px;
    background-color: #fb3f26;
    position: fixed;
    z-index: -1;
    top: 0px;
    left:0px;
    right: 0px;
}

Check out the JSFiddle Demo here

Answer №2

To create a fixed header, you can set its position:absolute property to remove it from the layout flow. Afterwards, adjust the content box by adding padding-top to accommodate the height of the header.

Answer №3

Here's a suggestion for a simple HTML and CSS setup:

HTML

<header id="header1">
    <div>Hotel</div>
</header>
<header id="header2">
</header>
<div id="content">
...

CSS

#header1 {
    height: 25px;
    background-color: #fb3f26;
    position: fixed;
    top: 0px;
    left:0px;
    right: 0px;
    z-index: 1;
}
#header2 {
    height: 300px;
    background-color: #fb3f26;
    position: fixed;
    top: 0px;
    left:0px;
    right: 0px;
    z-index: -1;
    min-height: 25px;
}

Answer №4

In my opinion, a simple solution would be to apply the CSS property position:fixed to the header/banner. Then adjust the z-index values so that the banner appears behind the content box while the header remains above it. You can also utilize margin-top to adjust for the height of the header/banner.

http://jsfiddle.net/someuser/abc123def/9/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to achieve a XNOR-like response with necessary input?

I'm currently working with a form that looks like this: <form> <input type="text" name="input1"> <input type="text" name="input2"> <button type="submit"> ...

The res.sendFile() function quickly delivers a 204 no content response

Currently, I am facing an issue with using Express' sendFile() function to send an image. The function does not seem to read my file at all and instead returns a 204 no-content response. Below is the code for my function/endpoint: @httpGet('/pri ...

Loop through the JSON array and append every value to the list within AngularJS

I'm just starting to learn about Angular JS and I have a question. I receive a JSON array as an AJAX response from a PHP page. I want to iterate through this JSON array and push each value into a list like this: angular.forEach($scope.companies.area, ...

Tips for creating a centered Reindeer

My reindeer code seems to be a bit off-center. Even though I followed a tutorial, my reindeer is not aligning properly as shown in the tutorial. Here is all the CSS code for the reindeer: .reindeer { height: 510px; width: 350px; position: ab ...

Tips for transferring information to a node server

Currently, I am working with Express and facing the challenge of dynamically sending data to the app.get() method. Specifically, on my index page, there is a list of topics, and upon clicking one, I need to send the name of that element as the required dat ...

simultaneous image hover effect for all images

I am experiencing an issue with my CSS and Bootstrap hover effect. The overlay tags are enclosed within a div class, but they all hover simultaneously. Each overlay belongs to a different Bootstrap grid, yet the effect extends even to the empty spaces betw ...

Leverage PHP to retrieve information from a JSON file and integrate it into a dropdown menu on an HTML

I've been given a task to develop a PHP routine that will extract the ISO code and name from a geojson file for use in a dropdown list of countries on a website. This is completely new to me and I'm finding it difficult to understand the documen ...

Creating a new list by grouping elements from an existing list

I have successfully received data from my API in the following format: [ {grade: "Grade A", id: 1, ifsGrade: "A1XX", ifsType: "01XX", points: 22, type: "Type_1"}, {grade: "Grade B", id: 2, ifsGrade: &quo ...

Setting up routes in VueJS and NodeJS Express for API integration: a comprehensive guide

My API routes always return HTML instead of JSON, despite trying numerous solutions that have all failed. Here is my current setup: // app.js const express = require("express"); const app = express(); const history = require("connect-history-api-fallback ...

Return a response from the controller method without using the express response object

When attempting to handle the scenario where a fetch for an item does not return anything from another method that lacks the express response, I encounter an issue. I invoke this method from another one that has the express response: const updateItem = asy ...

Dynamically load WordPress content using ajax and incorporate CSS3 animations for added visual appeal

It's time for a new challenge to push my learning curve. I've never ventured into the world of ajax before, but it seems like a skill I need to acquire. What better opportunity to learn than by implementing it on a fresh portfolio site. The main ...

What is the process for saving information to a database with JavaScript?

I am currently utilizing the Google Maps API for address translation, primarily through the use of a geocoder. I am interested in saving these results to a local database for future reference, as there are limitations on the total number and frequency of ...

Managing data flow in React and Reflux: Utilizing a single component duplicated in the DOM

Imagine this Tree scenario: <Homepage> <HeaderSection> <Navbar> <ShoppingCartComponent> </Navbar> </HeaderSection> <MainContent> <ShoppingCartComponent> &l ...

Utilize the Bootstrap column push-pull feature on the mobile version of

https://i.stack.imgur.com/yTBIt.png When viewing the desktop version, div A is displayed at the top of the page. However, I would like to move it to the bottom when viewing on a mobile device (col-xs). I have attempted to solve this issue myself without s ...

What's the best way to use the like query in Mongoose?

Struggling with applying a Like query using Mongoose in the MEAN stack. Despite trying various solutions found online, nothing seems to work for me. Here is the model schema: const mongoose = require('mongoose'); const ItemTransactionSchema = ...

Images in CSS not copied to the output directory when using Webpack

Using Webpack to bundle various javascript and css files on a website includes bundling bootstrap.css and chosen.css as part of the bundles. To achieve this, there is a main.js file serving as an entry point for importing all necessary files. The process i ...

Opting for CSS3 transitions over jQuery animate

Currently, I am working on animating a block of HTML that involves fading in (opacity) and slightly moving from the left (margin-left)... $('.latest-stats').delay(1000).animate({ opacity: 1, marginLeft: '55px' }, 1000, function () { ...

Issues with inline display not being rendered properly in HTML/CSS

I've been attempting to place an image and an h1 element on the same line. After researching online, I attempted using display:inline; for both the parent div element as well as each individual element. This is my current code: <div style="displa ...

Removing characters from a string with regular expressions

I need to eliminate instances of << any words #_ from the given text. stringVal = "<<Start words#_ I <<love#_ kind <<man>>, <<john#_ <<kind man>> is really <<great>> <<end words#_ "; The d ...

"Adjusting the position of series data container in Highcharts JS to optimize

Currently, I am utilizing highcharts along with highcharts-ng. My goal is to adjust the position of the container for series Data (where the number 80 is displayed below) slightly higher as it is currently overlapping with the numbers 200 and -200 in the t ...