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

What steps can I take to maintain the width while implementing jQuery's slideUp function?

I am facing a scenario where: http://www.jsfiddle.net/kPBbb/ After adding content to .content, the .wrapper shrinks itself, possibly due to the fact that the .content is set to display: none. I want the .wrapper to maintain its original size even after t ...

Guide to counting the number of image tags within a parent div and selectively removing them starting from a specific position

My dynamic image tag <img> is generated inside a div from the database using fetching. Here is how my HTML looks: <div class='forimgbox'> <p class='palheading'>Pals</p> <img src='userpic/2232323.p ...

"Looking to swap out the Angular theme's CSS stylesheet for your entire application? Here's

I was initially facing an issue while trying to import CSS through index.html as I kept getting a MIME type error: enter image description here The browser refused to apply the stylesheet from 'http://localhost:4200/css/pink-bluegrey.css' because ...

Difficulty adjusting table heights in Dreamweaver, Struggling to set table height with <p style declarations

I'm currently designing an email signature in Dreamweaver using a table. However, I encountered an issue when I added the <p=style tag to customize my font size and color - it caused my table heights to change unexpectedly. Despite trying various s ...

Modifying the div based on the color it is positioned in front of

I am attempting to create a sticky, transparent div that changes its color based on the background behind it. I have both dark and light colored divs, and I want the sticky div to adjust its text color accordingly (white on dark backgrounds, black on light ...

Creating Scalable Vector Graphics without utilizing identifiers

For instance, if we have defs and rect defined separately, we would typically use an ID. <defs> <linearGradient id="MyGradient"> <stop offset="0%" stop-color="#000" /> <stop offset="100%" stop-color="#fff" /> ...

Styling and Script Files on a JQuery Mobile Website

Is it necessary to include CSS and JS files in every HTML page for a mobile site developed with JQueryMobile? <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" /> <script src="http://code.jquery.com/jqu ...

Using React to Dynamically Display JSON Data as HTML

Struggling to incorporate HTML rendering from JSON data into my React component without relying on dangerouslySetInnerHTML. I want to include other React components within the rendered HTML, but facing challenges when trying to render multiple elements or ...

Tips for creating a star program using Angular 2+

Create an Angular 2+ code snippet that will print asterisks (*) in a list on button click. When the button is clicked, it should add one more asterisk to the list each time. For example: Button Click 1 - Output: * Button Click 2 - Output: ** Button Cl ...

Substitute placeholders in the HTML code with Angular syntax

Lately, I have been encountering some issues with AngularJS. I have defined multiple scopes like this: app.controller('mainController', function($scope) { $scope.siteURL = "my website url"; }); When using the {{siteURL}} variable in ...

What could be causing my website icon to not appear?

I'm having trouble displaying my website icon after uploading it to Favic-o Matic's Website and implementing the HTML code I received. Despite trying various troubleshooting steps, such as clearing the cache and saving the site as a bookmark, the ...

Interactive Sidebar Navigation Content

On my website, I have a navigation sidebar that contains links to all of the main site pages. Each page has the same links, except the link to the current page is not included, making it easy to visually identify which page you are on. Currently, I manuall ...

Executing Array.prototype.filter() results in an empty array being returned

I have a list of jQuery elements that I collected using the .siblings() method, and now I am trying to filter them. Here is the HTML code: <div> <div> <label for="username">Username</label> <input class="form ...

Improved AJAX Dependency

A few days ago, a question was posted with messy code and other issues due to my lack of experience (please forgive the form handling as well). However, I have made some improvements and added context. The main problem now lies in the second AJAX call. Ch ...

Ways to align text and horizontal rule perfectly within a div container?

I need to add some text to my <div> container and make sure it is centered. .hr { background: green; height: 50px; margin: 65px 0; width: 3000px; } <div class="hr"></div> This is an illustration of my project: A picture showing m ...

Hide elements in hidden divs until the page is fully loaded to reduce initial page

www.prismasites.com I am creating a unique world map by using SVG DIVs shaped like Continents. Upon clicking on a continent on the world map, it conceals the world map DIV and displays the respective continent DIV with SVG. I have successfully achieved ...

Sending a variable to an AngularJS factory

I am currently working on a select list that looks like this: <select name="make" class="form-control" ng-model="selectCity"> <option value="Kannur">Kannur</option> <option value="Agra">Agra</option> <option va ...

Is there a restriction on the number of stylesheets per page in Internet Explorer 8?

Discussing the limitations of CSS in a forum thread, a user shared insights: A user mentioned that Internet Explorer has is known to have a restriction of 4096 CSS rules per file. For more information, check out this source. Additionally, there might be ...

Build a photo carousel similar to a YouTube channel

Is there a way to create an image slider similar to the one on YouTube channels? I've noticed that when there are multiple videos on a channel, YouTube displays them in a slider with back and forth buttons to navigate through the videos that aren&apos ...

Scrolling to a specific position on a page when a Vue 3 component appears is a must-do for

When I click a button, my basic form component appears without using the router. I would like the scroll position of the form to automatically move down slightly (for example, on the y-axis at 40) once it is displayed. However, I am unsure of how to achi ...