Position a div in the center both horizontally and vertically within a section, ensuring that each section expands to fill the entire page when scrolling

I'm currently working on coding a page layout where each section takes up the entire screen. My goal is to have the content within each section centered both vertically and horizontally. I'm unsure if this is achievable, so any guidance or advice would be much appreciated. Additionally, I'd like to know if it's possible for the page to automatically scroll to the next section as the user scrolls down. I hope that explanation is clear enough.

Below is the CSS code snippet:

.presta .container {
  width: 100%;
  position: relative;
}

.presta .h1 {
  font-size: 80px;
  font-weight: bold;
}

.presta card {
  padding: 30px;
  margin: 0 auto;
}

.logoPresta:hover {
  transition: transform 0.3s ease-in;
  transform: translateY(-10px);
}

.prestaShow {
  text-align: center;
}

.wrapper {
  min-height: 100%;
}
<div class="navbar ">
  <div class="container flex">
    <div class="logo" data-aos="fade-right">
      <a href="index.html"><img src="images/linko_bg_transp.png" alt="" /></a>
    </div>
    <nav data-aos="fade-in">
      <ul>
        <li><a href="index.html">Home</a></li>
        <li><a href="aboutus.html">About Us</a></li>
        <li><a href="services.html">Our Services</a></li>
        <li><a href="contact.html">Contact Us</a></li>
      </ul>
    </nav>
  </div>
</div>

<section class="presta bg-light wrapper">
  <div class="container">
    <div class="text-center">
      <h1>Our Areas of Expertise</h1>
    </div>
    <div class="grid grid-4">
      <div class="logoPresta card">
        <img src="images/1.jpg" alt="">
      </div>
      <div class="logoPresta card">
        <img src="images/2.jpg" alt="">
      </div>
      <div class="logoPresta card">
        <img src="images/3.jpg" alt="">
      </div>
      <div class="logoPresta card">
        <img src="images/4.jpg" alt="">
      </div>
    </div>
  </div>
</section>

<section class="prestaShow wrapper">
  <div class="container info">
    <div class="text-center">
      <h2>Information Technology</h2>
    </div>
    <div class="textePresta card">
      Web application design & development
    </div>
    <div class="textePresta card">
      Database creation & enhancement
    </div>
    <div class="textePresta card">
      Network infrastructure deployment
    </div>

  </div>
</section>

Check out the images of the page: https://i.stack.imgur.com/Mrqs2.png https://i.stack.imgur.com/4p5Yd.png

Answer №1

To make a section full page height, replace 100% with 100vh

Check out the CSS section for details on centering wrapper content (expand Code snippet to view differences).

UPD: .snap-wrapper allows scrolling through full sections, see Code snippet in full-screen mode.

.presta .container {
  width: 100%;
  position: relative;
}

.presta .h1 {
  font-size: 80px;
  font-weight: bold;
}

.presta card {
  padding: 30px;
  margin: 0 auto;
}

.logoPresta:hover {
  transition: transform 0.3s ease-in;
  transform: translateY(-10px);
}

.prestaShow {
  text-align: center;
}

.wrapper {
  /* centering wrapper content */
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}

/* use .snap-wrapper to scroll page by full sections */
.snap-wrapper {
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  scroll-snap-type: y mandatory;
  overflow: auto;
  height: 100vh;
}

.snap-wrapper > .wrapper {
  scroll-snap-align: center;
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cba9a4a4bfb8bfb9aabb8bfee5fae5f8">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">


<div class="navbar ">
  <div class="container flex">
    <div class="logo" data-aos="fade-right">
      <a href="index.html"><img src="images/linko_bg_transp.png" alt="" /></a>
    </div>
    <nav data-aos="fade-in">
      <ul>
        <li><a href="index.html">Accueil</a></li>
        <li><a href="pres.html">Présentation</a></li>
        <li><a href="Presta.html">Nos Prestations</a></li>
        <li><a href="form.html">Nous contacter</a></li>
      </ul>
    </nav>
  </div>
</div>

<div class="snap-wrapper">
  <section class="presta bg-light wrapper">
    <div class="container">
      <div class="text-center">
        <h1>Nos domaines d'expertises</h1>
      </div>
      <div class="grid grid-4">
        <div class="logoPresta card">
          <img src="images/1.jpg" alt="">
        </div>
        <div class="logoPresta card">
          <img src="images/2.jpg" alt="">
        </div>
        <div class="logoPresta card">
          <img src="images/3.jpg" alt="">
        </div>
        <div class="logoPresta card">
          <img src="images/4.jpg" alt="">
        </div>
      </div>
    </div>
  </section>

  <section class="prestaShow wrapper">
    <div class="container info">
      <div class="text-center">
        <h2>Informatique</h2>
      </div>
      <div class="textePresta card">
        Conception & développement d'applications web
      </div>
      <div class="textePresta card">
        Création & amélioration de bases de données
      </div>
      <div class="textePresta card">
        Déploiement d'infrastructures réseaux
      </div>

    </div>
  </section>
</div>

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

Display issue with ul and li elements in Safari browser causing menu to appear incorrectly

Although I am new to CSS, I managed to create a menu on my website that hovers over the background video successfully. It is a basic menu using a ul with li elements and it appears as intended in all browsers except Safari. In Safari, the menu items stack ...

I'm struggling to understand why the jQuery find() method isn't functioning as expected

UPDATE: In a twist of events not caused by syntax errors, but rather by a loading issue with the html template, it turns out that the checkbox update was happening prematurely. So if you're searching for an element that seems to be missing, it may sim ...

Enhance your view of the iFrame's CONTENT by zooming in

I'm attempting to magnify (without altering the dimensions) an iFrame containing a SWF file. <iframe src="http://ray.eltania.net/TEST/swf-play/swf/testMotion.swf" width="600px" height="500px" frameBorder="0"></iframe> http://jsfiddle.net ...

Retrieving a PHP variable from HTML without using a form

Is there a way to pass a variable from HTML to PHP without using a form and the traditional post or get methods? I have tried using the code provided, but I am unable to access the value of the 'buy1' variable in PHP. Is there a way to achieve th ...

Angular 8 fails to retain data upon page refresh

I have a property called "isAdmin" which is a boolean. It determines whether the user is logged in as an admin or a regular user. I'm using .net core 2.2 for the backend and Postgre for the database. Everything works fine, but when I refresh the page, ...

Tips for animating input width as the size value changes during an ajax query transformation

This is my JavaScript code: function updatePriceDisplay() { $.ajax({ url:"query.php?currency=<?=$currencycode;?>" }).done(function(data) { $("value").attr("value", data).attr("size", data.length - 2); }); } updatePriceDi ...

What is the recommended Vue js lifecycle method for initializing the materialize dropdown menu?

https://i.stack.imgur.com/cjGvh.png Upon examining the materialize documentation, it is evident that implementing this on a basic HTML file is straightforward: simply paste the HTML code into the body and add the JavaScript initializer within a script tag ...

Reset input value when adding or removing inputs dynamically

Currently, I have an input element that has the capability to clear its value when a button is clicked. Additionally, this input can dynamically add or remove input elements. However, I am facing an issue where after adding an input element, the clear butt ...

how to enable drag and drop functionality based on names in angularjs

In my project using angular js, I have implemented a drag and drop feature that allows items to be dragged between cells in two directions. I now want to enhance this functionality by allowing members with 'a's (e.g. 1a, 2a, etc.) to be dragged ...

Ways to enlarge a YouTube thumbnail upon loading using JavaScript

I recently found a solution to my question on how to prevent YouTube videos from repeating even when different embedded codes are used. I have a specific need to resize the thumbnail image of my YouTube video to width:146px and height:124px when the page l ...

Designing rows and columns using Angular CSS within an ngFor loop

Is there a way to align items in a row or column based on conditions within an *ngFor loop? I want the input type to display on the next line if it is textarea, and on the same line otherwise. Check out this Stackblitz Demo for dynamically generated HTML ...

Differentiate between minimum and maximum values on ion-range sliders with discrete color options

I am currently working on customizing the theme of my ionic app, specifically trying to assign different colors to the min and max knobs on an ion-range component. At the moment, I am only able to apply a single HTML property called "color" to the selector ...

The resizing of the background image is contingent upon the size of the

I am facing an issue with my bootstrap carousel. One of the items only contains a background image without any content. I have set a height for it so that it is still visible even without content. However, when viewing on mobile devices, I can only see a p ...

Page returning causing tabs to refresh improperly

Today I want to discuss two different pages: VelocityMicro.com/Cruz.php and VelocityMicro.com/PC.php, which I am currently viewing in Firefox. The issue I am experiencing is with Cruz.php. When you click on a tab like "R100 Series" and then select an acce ...

Modify the navbar background color in bootstrap-vuejs

As per the information provided in the documentation, the instructions for setting styles for the navigation bar are as follows: <b-navbar toggleable="lg" type="dark" variant="info"> <!-- Or --> <b-navbar toggleable="lg" type="dark" variant ...

url-resettable form

Currently, I am working on an HTML form that includes selectable values. My goal is to have the page load a specific URL when a value is selected while also resetting the form back to its default state (highlighting the "selected" code). Individually, I c ...

Convert Python strings into HTML JavaScript blocks using Jinja2

Having trouble passing a string to an HTML page in the "<script>" block. I am currently using Python, Flask, and Jinja2. Python code: def foo(): return myString #"[{title: 'Treino 7-Corrida',start: '2015-12-08',color: '#d ...

Is it possible to share deep links with just a hashtag?

I am currently developing a web application and I want to include social media buttons such as Facebook Like. I have tried using the HTML code/API provided by Facebook, AddThis, Shareaholic, ShareThis, but none of them seem to properly handle my deep link ...

CSS <ul> <li> spacing issue in Internet Explorer 7

My CSS <ul> <li> nested menu is functioning perfectly in IE 8 and Firefox, but in IE7 it is creating a small gap between the elements. Here is my CSS: #nav, #nav ul { margin: 0; padding: 0; list-style-type: none; list-style-po ...

Is there a way to remove the initial number entered on a calculator's display in order to prevent the second number from being added onto the first one?

I am currently in the process of developing a calculator using HTML, CSS, and JavaScript. However, I have encountered an issue with my code. After a user inputs a number and then clicks on an operator, the operator remains highlighted until the user inputs ...