Ensure that the initial section of the page spans the full height of the browser, while all subsequent sections have a

I have a website composed of various blocks with different heights, all extending to full width. My goal is to make the first block the full height and width of the browser window, while keeping the other blocks at a set height as seen on this site:

After numerous attempts, I managed to make the first block div fullscreen but encountered an issue where the subsequent blocks stacked under the first one and were not visible. I aim for the first block to occupy the full screen's dimensions while allowing users to scroll through the rest of the blocks below.

Initially, I tried achieving this using pure CSS but became uncertain if it was feasible, so I am also considering JavaScript.

You can view my JSfiddle demonstrating the problem here: https://jsfiddle.net/kff1swjf/

Here is the HTML markup:

<div id="section1">Section 1</div><!--this one should open full height and width of the browser window-->
<div id="section2">Section 2</div>
<div id="section3">Section 3</div>
<div id="section4">Section 4</div>
<div id="section5">Section 5</div>

This is my CSS:

#section1 {
    background: red;
    position: absolute;
    top: 0; right: 0; bottom: 0; left: 0;
}

#section2 {
    background: blue;
    height: 150px;
}

#section3 {
    background: yellow;
    height: 300px;
}

#section4 {
    background: green;
    height: 200px;
}

#section5 {
    background: purple;
    height: 175px;
}

Answer №1

To change the appearance of #section1, all you have to do is update the CSS like this:

#section1 {
    background: red;
    width:100%;
    height:100vh;
}

By using 100vh for the height, you are setting it to be equivalent to 100% of the viewport's height.

Check out the demonstration after making this modification here: https://jsfiddle.net/bf70h42y/

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

Removing dropdown lists from input forms can be achieved without using jQuery by utilizing vanilla JavaScript

Looking to build a custom HTML/JavaScript terminal or shell. Interested in utilizing an input box and form to interact with JavaScript functions/commands. Unsure of how to eliminate the drop-down menu that appears after previous inputs. Pictured terminal: ...

Requesting the json data through an Ajax call

I am currently working on implementing an AJAX call to handle the response received from a JSON file. Here is the HTML snippet: <div id = "tabs"> <ul> <li><A href="#ed_pro">Product Category</A> </li> <li><A hr ...

Achieving full coverage of cell content within a cell area by utilizing align-items in CSS Grid

Is it possible to achieve two conflicting goals using CSS Grid? In my design, I want the content in each cell to be vertically centered using align-items: center; At the same time, I need the entire area of the cell to be filled with color. However, ...

Having difficulty adjusting the margin-top for the menu div

Why am I unable to apply margin to my a links within the div identified by id="menu". I can successfully implement margin-left, but when attempting to use margin-top or margin-bottom, it does not work as expected. I wish to adjust the position o ...

What steps can I take to enable search functionality in Ckeditor's richcombo similar to the regular search feature in

I am currently developing a custom dropdown menu using the rich combo feature in CKEDITOR. One of my goals is to include a search functionality within the dropdown, such as a key press search or an input textbox search. This is how my dropdown box appear ...

How should a successful post request be properly redirected in React?

I am in the process of learning React and currently working on a small project. I have set up a NodeJS server to handle my requests, and now I am facing an issue with redirecting the user after a successful login. I successfully dispatch an action and upda ...

AngularJS animation fails to activate

I've been working on a simple AngularJS application and I'm trying to add animations between my views. However, for some reason, the animation is not triggering despite following the tutorial on the AngularJS website. There are no errors in the c ...

When the text in a Material UI Textfield is updated using setState in React, the Hinttext may overlap with the newly set

How can I fix the issue of default hintText and floatingLabelText overlapping with text in a textfield when using setState to autofill the textfield upon clicking on an edit button? Here is an image showing the textfield overlap: Below is the code for th ...

Tips on tallying the frequency of items in a state array

I'm currently working on an application in which clicking a button adds the item's value to the state. The button is clickable multiple times, allowing the same item to be added multiple times in the state array. My current code snippet: export ...

Converting a string into an array of JSON objects

I am currently attempting to send data to my NodeJS server using the HTTP protocol (vue-resource). The goal is to send an array of JSON objects structured like this : [{"name":"Charlotte","surname":"Chacha","birth":"2000-04-02"},{"name":"Michael","surname ...

Tips for resolving the 'node is not defined' error in the case of passing a default value

Attempting to incorporate the Trie data structure into JavaScript has presented a challenge. Within the print function, which displays an array of all words in the Trie, there is a search function that looks for words within the Trie and adds them to the a ...

Improving Modal Closure on Form Submission Suggestions

Seeking Assistance with Modal Closure After Form Submission I understand that this inquiry may have been posed by someone else before, but I require guidance specifically for my code pertaining to handling form submission with AJAX. As a newcomer to AJAX, ...

What is the best way to retrieve an ng-model parameter within a controller?

I'm working on implementing a PUT method in my controller and need to bind the new value back to it. I've tried: <div ng-app="myApp" ng-controller="personCtrl"> <form> First Name: <input type="text" ng-mod ...

Choosing the open status of an HTML list

Is there a way to determine which containers in a list are currently open and which ones are still closed? Currently, I am utilizing the slideDown(), slideDown(), and addClass functions on divs with the specific class="section_hdl_aktiv". However, I want ...

CSS and JavaScript dropdown malfunctioning due to a position swap in internal CSS

This example demonstrates functionality .c1 { background-color:red; position:relative; } .c2 { background-color:blue; position:absolute; height:50px; width:100px; display:none;} .show { display:block; } <body> <button ...

What is the best way to update the state by either adding to it or replacing it if the key

I'm currently working on a project involving radio buttons and I need to create dynamic state by setting the initial state on the first click, then updating it with subsequent clicks by either concatenating the new value onto the existing state or rep ...

Incorporating database coordinates into Marker React Leaflet: A Step-by-Step Guide

When I retrieve coordinates from the database, they are structured as "lat" and "lon" fields. In my mapping application, I have multiple markers to display. How can I combine these two fields to pass coordinates (coord.lat and coord.lon) to the Marker comp ...

Encountering a Django Ajax HTTP 500 Error

I'm struggling to integrate Django with AJAX requests, and I keep getting an HTTP 500 error related to MultiValueDictKeyError even though everything seems fine? I passed in 3 variables: sendEmail, username, error When accessing request.POST on the 3 ...

What is the best way to display and conceal elements depending on the chosen option using jQuery?

Can you help me figure out why this code isn't working as expected? <Script> $('#colorselector').change(function() { $('.colors').hide(); $('#' + $(this).val()).show(); }); </Script> < ...

Transferring information to modal without using AngularUI

I'm currently working on an Angular application and facing an issue with passing data from my controller to a modal. Here is the HTML code on my index page: <!DOCTYPE html> <html lang="en" ng-app="myApp"> <head> ... </head> & ...