Entering in full screen mode

Is there a way to create a first screen appearance that spans the entire screen? I want the whole page to be fullscreen and when someone scrolls down, it transitions to a new screen. I am struggling to find a solution for this.

body {
  margin: 0 0 0 0;
}

#sample_img_1 {
  height: 900px;
  width: absolute;
  background-image: linear-gradient(to right, green, blue);
}

#sample_img_2 {
  height: 200px;
  width: absolute;
  background-image: linear-gradient(to right, red, orange);
}
<p id="sample_img_1"></p>
<p id="sample_img_2"></p>

Answer №1

Initially, let's address the issues in your current code:

body {
  /* Margin values can be more concise: */
  margin: 0;
}

#sample_img_1 {
  height: 900px;
  /* Invalid property value for "width": */
  width: absolute;
  background-image: linear-gradient(to right, green, blue);
}

#sample_img_2 {
  height: 200px;
  /* Also an invalid property value for "width": */
  width: absolute;
  background-image: linear-gradient(to right, red, orange);
}

To fix this and make the background-images of the <p> elements span the full width of the page:

body {
  padding: 0;
  margin: 0;
}

p {
  margin: 0;
  width: 100%;
}

#sample_img_1 {
  height: 900px;
  background-image: linear-gradient(to right, green, blue);
}

#sample_img_2 {
  height: 200px;
  background-image: linear-gradient(to right, red, orange);
}

Instead of the above, consider this approach with detailed comments in the code:

/* Resetting all elements including pseudo-elements: */
*,
::before,
::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  block-size: 100%;
  inline-size: 100%;
  scroll-snap-type: y mandatory;
}

body {
  counter-reset: sectionCount;
}

section {
  background-image: linear-gradient(to right, var(--gradientColor1), var(--gradientColor2));
  display: grid;
  place-content: center;
  block-size: 100vh;
  inline-size: 100vw;
  scroll-snap-align: start;
}

section::before {
  border: 3px solid currentColor;
  color: #fff;
  counter-increment: sectionCount;
  content: counter(sectionCount, decimal-leading-zero);
  font-size: 6em;
  padding: 1em;
}

.page:nth-child(odd) {
  --gradientColor1: green;
  --gradientColor2: blue;
}

.page:nth-child(even) {
  --gradientColor1: red;
  --gradientColor2: orange;
}

JS Fiddle demo.

References:

Bibliography:

Answer №2

Set the height of each section to occupy 100% of the viewport;

body {
  margin: 0;
}

#sample_img_1 {
  height: 100vh;
  width: 100%;
  background-image: linear-gradient(to right, green, blue);
}

#sample_img_2 {
  height: 100vh;
  width: 100%;
  background-image: linear-gradient(to right, red, orange);
}

Next, refer to this stackoverflow post;

Achieve a 100vh scroll down effect on page scroll

Answer №3

One way to make your elements responsive is by utilizing the vw and vh CSS units, which correspond to viewport width and viewport height respectively. These units allow you to size elements based on the screen dimensions of the device. Here's an example:

CSS

.responsive-box {
  width: 100vw;
  height: 100vh;
  position: absolute;
  top: 0;
  left: 0;
  background-color: lightblue;
}

For more information, check out this resource from W3schools.

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

Efficient Ways to Utilize Global CSS in an Angular Project Without CLI

I am utilizing ASP.NET MVC as the server and Angular as the client application. Instead of a static index.html file, I have index.cshtml. The styles I am using are global styles rather than component-scoped. My query revolves around working with a bunch ...

Exploring ways to display featured posts within specific category sections

I have 2 featured posts in 1 div id, one with a big class and the other with a small class. I want the big featured div to display posts based on categories. The code for the big featured post is shown below: <div class="main_feat"> ...

Use jQuery to automatically update a variable every 5 seconds

For the first time, I am using django to build a webpage and facing a challenge in fetching the value of a variable from a .py file every 5 seconds. Here is the HTML code snippet: <!DOCTYPE html> <html> <head> <title&g ...

Issue with long text in a resizable table using jQuery tablesorter 2.31.1

My issue is that when I try to resize the columns in tablesorter, they snap back into place. The column width set with resizable_widths does not apply correctly until a column is manually resized. Despite setting the width of all cells to 120px, any cells ...

The multi-line declaration prettier indicates that a newline is expected after the colon

When using Prettier to format code in a scss file, it is formatting this specific part: @font-face { font-family: 'Encode Sans Condensed'; src: url('/pf/resources/fonts/EncodeSansCondensed/EncodeSansCondensed-Thin.ttf') format('tr ...

Obtaining Beverage Overall with Loop

I am currently using a function to calculate the total of each drink, with a total of 5 drinks: var totalEstimate = 0; var locoCost = 0; var blackCost = 0; function calcLoco() { totalEstimate -= locoCost; locoCost = docume ...

Currently working on enhancing the responsiveness of the login form

I am encountering difficulties while trying to make the page responsive. I've checked my basic code, but something seems off. Could you please take a look at the plnkr link below and give me some feedback on where I might have gone wrong? Here's ...

How can I add divs to an HTML page with a Javascript animated background?

I am currently facing an issue with my JavaScript animated background, consisting of just 3 pictures. I am trying to display some Div elements on it with content inside. Here is the code snippet I have right now: In my CSS file, I have defined styles for ...

Optimal Procedure for New Users Form (Jade / Angular) in HTML

I'm currently working on integrating a form into my app for users to create tasks. This form should only appear the first time a user attempts to create a task. As someone who is not very experienced with frontend development, I find myself wondering ...

There was a problem compiling bootstrap.scss due to an error found in _root.scss

I've encountered an issue while compiling my bootstrap sass file. The error message I'm receiving is shown below. Although I can make it work by commenting out lines 4 and 8 of _root.scss, that is not the optimal solution. Can someone please expl ...

Guide to utilizing SVG animations for line drawing rather than just outlines

I've been experimenting with animating an SVG file to resemble the gif below, and I'm getting pretty close, but I seem to be encountering an issue where the outlines are drawn before being filled. I want the entire lines to be animated as shown i ...

What methods can be used to accomplish this effect using CSS and/or Javascript?

Is there a way to achieve the desired effect using just a single line of text and CSS, instead of multiple heading tags and a CSS class like shown in the image below? Current Code : <h2 class="heading">Hi guys, How can i achieve this effect using j ...

Creating a new web application, I require a loading overlay to appear during transitions between pages

I've checked high and low, but I can't seem to find the solution! My webapp has a page that is bogged down with data causing it to load slowly. Is there a way to display a loading div while transitioning to the next page? Perhaps something like ...

What methods are available for updating the href color of an element using the DOM?

I am looking to update the color of a tab (Mathematics-tab) based on the value of 'aria-selected' changing to true in Bootstrap. I have multiple tabs, including one for mathematics, and I want to visually differentiate between selected and unsele ...

Switch the design and save it in the browser's cache

Exploring the possibility of having two themes, "dark" and "light," that toggle when a checkbox is clicked. To implement the theme change, I used the following JavaScript code: document.documentElement.setAttribute('data-theme', 'dark&apos ...

How can I prevent users from using the inspect element feature in Angular 4?

I have a collection of elements that I need to selectively display on a webpage. To achieve this, I am utilizing the following code snippet: [style.display]="!student.selected?'none':'block'" However, upon inspecting the element, a ...

Creating a custom backdrop for your kaboom.js webpage

I created a kaboom.js application and I'm having trouble setting a background for it. I've searched online extensively and attempted different methods on my own, but nothing seems to be working. (StackOverflow flagged my post as mostly code so I ...

Attempting to include a standard VAT rate of 5% on the invoice

/* The code format is correct and I don't see any issues on my end, I hope it works well for you. */ I need assistance in adding a fixed VAT (tax) rate of 5%. The tax amount should be displayed on the row, while the total tax should reflect the sum o ...

Use Javascript's JQuery library to apply functionality to a newly inserted and cloned

I am facing an issue while trying to implement JQueryUI's DatePicker on a node. It works perfectly fine for all the existing nodes, but when I use the clone function to add new nodes, it doesn't seem to apply as expected. Here is the function th ...

Incorporating PHP variables within JavaScript

As a beginner in web development, I am working on creating an application that heavily relies on JavaScript but also includes PHP/MySQL to prevent users from viewing quiz answers by inspecting the page source. The key pages involved in this project are: in ...