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

Learn the process of creating a unique item layout to suit your preferences

Exploring the use of div to create the desired layout but struggling to achieve my goal .skills-container { height:50px; /* aiming for around 50px */ padding:5px; } .skill-pic { width:48px; height:48px; } .skill-content { } .skill-content p { } .progres ...

Tips for incorporating a multimedia HTML/JavaScript application within C++ programming

I possess the source code for a JavaScript/HTML5 application that operates on the client-side and manages the transmission/reception of audio and video data streams to/from a server. My objective is to develop a C++ application that fully integrates the c ...

``In JavaScript, the ternary conditional operator is a useful

I am looking to implement the following logic using a JavaScript ternary operation. Do you think it's feasible? condition1 ? console.log("condition1 pass") : condition2 ? console.log("condition2 pass") : console.log("It is different"); ...

When using jQuery to select elements of a specific class, make sure to exclude the element that triggered the

A dynamic number of divs are generated from a data source. Each div contains an image button and another div with text. While the actual scenario is more complex, we can present a simplified version: <div id="main"> <div id="content_block_1" ...

Which is better for creating a gradual moving background: Javascript or CSS?

I'm attempting to discover how to create a background image that scrolls at a slower pace than the page contents. I'm currently unsure of how to achieve this effect. A great example of what I'm aiming for can be seen here Would this require ...

What is the best way to remove the box-model from an element?

Within my VueJS project, I am faced with nested elements that are generated dynamically like this: <container> <outerElement class="outer" v-for="obj in objects"> <innerElement class="inner" v-for="el ...

Having trouble uploading images using ReactJS on the web platform

I am currently in the process of developing a portfolio website using react js, but I'm experiencing an issue where the image I intended to display is not showing up on the live site. Despite thoroughly checking my code, I can't seem to identify ...

Leveraging ng-click and ng-hide/show directives within ng-repeat in Angular

I have a simple Single Page Website built with Angular. I utilized ng-repeat to generate content on the main page, where each item is an image. I am looking to create an alternate view for each image to display more details. I have implemented this feature ...

Is there a proper method for populating an HTML text with values from a form?

As a newcomer, I could really use some guidance here :) I'm trying to populate text with various words, numbers, and calculation results from a form. This is my initial attempt for just one field/word, and it appears to be functioning correctly. Do y ...

The alignment of inline-block elements is not being maintained on the same line

Here's a question I have about my embedded form. Why does the display property of inline-block make the "submit" and "terms" elements appear higher than the email field? And more importantly, how can I fix this issue? I've attempted to use the t ...

The default values for CSS filters

I have a keen interest in various CSS filters: blur brightness contrast grayscale hue-rotate invert opacity saturate sepia Could someone provide the default values for each filter (preferably as a % value, where applicable)? The MDN documentation does no ...

Showing the values of two distinct select boxes in a URL

Here are both select boxes, the goal is to display selected values from both in the URL. This can be achieved by displaying them like this: e.g www.example.com#135+#140 OR www.example.com#135&140 (The order of values doesn't matter as long as bot ...

Discovering the initial element with a data attribute above zero using JQuery

I am working with a set of divs that have the class .item-wrap. At the moment, I am able to select the first div using this code snippet: $(".item-wrap:first").trigger( "click" ); Each .item-wrap element comes with a data-amount attribute. My challenge ...

Sending radio button value via AJAX request

Greetings and thank you for taking the time to hear out my query. I am aware that this question has been asked numerous times before (as informed by SO) but my case is slightly unique. I currently have a functional AJAX script that utilizes a dropdown menu ...

Designing a loading animation with rotating lines converging towards the center to form a circular motion

Check out my code snippet below: .circle { border: 1px solid transparent; border-radius: 50%; width: 100px; overflow: hidden; } .div7 { width: 100px; height: 10px; background: red; color: white; font-weight: bold; positi ...

Tips for organizing AJAX code to show images and videos in HTML with a switch case approach

I have 2 tables, one for images and one for videos. Within my HTML code, I have three buttons: slide_image, video, and single_image. Using iframes, I am able to load images and videos on the same page. When I click on the slide_image button, it displays im ...

What is the CSS/HTML code to position text at the bottom of an image overlay in a card design?

I've been attempting to modify the justify-content in the CSS class to "flex-end" and "end," however the text is not relocating to the bottom. My suggestion is that we concentrate on the img-overlay class, as that's where we adjust the position ...

Transfer certain options to another selection except for the one currently chosen in the first one

My task is to use jQuery to generate multiple select elements. Each new select should copy the options from the previous one, excluding any that have already been selected by the user. This process should occur every time an option is changed. Select opti ...

Ensure the browser stays anchored at the bottom of the page while employing jQuery to reveal a div

This piece of code allows me to toggle the visibility of a div: <a href="#" class="show_hide">Show/hide</a> <div class="slidingDiv"> My content...... <a href="#" class="show_hide">hide</a></div> <script src="http:// ...

What could be causing my UI Bootstrap datepicker-popup to suddenly stop functioning?

After updating to UI Bootstrap 0.11.0, I encountered an issue where my datepickers were no longer appearing correctly. To demonstrate this problem, I have created a plunker which can be viewed here. Essentially, the code snippet causing the problem is as f ...