Prevent pseudo elements from increasing the height of the viewport

Unexpected issue arose.

I recently discovered pseudo elements and have been utilizing them to create a skewed header and footer design without affecting the text inside. The header looks good and functions correctly, meeting my expectations. This is what I wanted / envisioned:

https://i.sstatic.net/XbEvr.png

However, this is what actually occurred:

https://i.sstatic.net/C0Yko.png

Any suggestions on how to prevent the pseudo element from impacting the page's height? Alternatively, what is the best approach to achieve the desired outcome shown in the above image?

NOTE: Utilizing a script is an option as I have other JS requirements, but I would prefer not to use it for appearance-related tasks like this if possible. It seems that using a polygon could be a solution, although I find the skew effect more appealing as it allows me to maintain consistency with the angles of other elements on the webpage, which is the primary goal of this endeavor. Below is some relevant code to help you get started:

:root {
  --dark-purple:    hsla(274, 64%, 10%,  1);
  --med-purple:     hsla(274, 45%, 20%,  1);
  ... (long CSS code)
}

... (additional CSS classes)

    <header>
      <div class="angled-top">
        [Header stuff here]
      </div>
    </header>
    
    <main>
      <div style="height: 70vh">... Simulate some large amount of content ...</div>
    </main>

    <footer>
      <div class="angled-bottom">
        <div class="footer--column">
          <h3>Sitemap</h3>

        </div>
        <div class="footer--column">
          <h3>Connect</h3>

        </div>
        <div class="footer--column">
          <h3>Recommended Sites</h3>

        </div>
      </div>
    </footer>

Answer №1

Simply include overflow: hidden in your .angled-bottom class. Another option could be using "contain: content", but keep in mind it's not fully compatible with Safari.

I've also eliminated the bottom padding on that particular element.

:root {
  --dark-purple:    hsla(274, 64%, 10%,  1);
  --med-purple:     hsla(274, 45%, 20%,  1);
  --light-purple:   hsla(274, 45%, 35%,  1);
  --lighter-purple: hsla(274, 45%, 40%,  1);
  --light:          hsla(274, 5%,  95%,  1);
  --grey:           hsla(274, 5%,  55%,  1);
  --dark:           hsla(274, 5%,  5%,   1);
  --vertical-grad:      linear-gradient(180deg, #ff8f3e, #cf132c, #420d6e);
  --vertical-grad-r:    linear-gradient(0deg, #ff8f3e, #cf132c, #420d6e);
  --horizontal-grad:    linear-gradient(90deg, #ff8f3e, #cf132c, #420d6e);
  --horizontal-grad-r:  linear-gradient(270deg, #ff8f3e, #cf132c, #420d6e);
}

body {
  margin: 0;
  z-index: -1;
  margin: 0;
  position: relative;
  background-color: var(--dark-purple);
  font-family: sans-serif;
  font-size: 13pt;
  color: var(--light);
}

.angled-top::before {
  content: '';
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  transform: skewY(-5deg) translateY(-5vw);
  z-index: -1;
  background: linear-gradient(220deg, var(--light-purple), var(--med-purple));
}

.angled-top {
  display: flex;
  padding: 2rem 4rem 9.5vw 4rem;
  justify-content: center;
  position: relative;  
}

.angled-bottom::before {
  content: '';
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  transform: skewY(-5deg) translateY(5vw);
  z-index: -1;
  background: linear-gradient(220deg, var(--light-purple), var(--med-purple));
}

.angled-bottom {
  display: flex;
  padding: 9.5vw 4rem 2rem 4rem;
  justify-content: space-around;
  position: relative;
  
    /* NEW */
  overflow: hidden;
  padding-bottom: 0;
}

.footer--column:nth-child(2) { transform: translate(0px, -2.5vw); }
.footer--column:nth-child(3) { transform: translate(0px, -5vw); }
<header>
      <div class="angled-top">
        [Header stuff here]
      </div>
    </header>
    
    <main>
      <div style="height: 70vh">... Simulate some large amount of content ...</div>
    </main>

    <footer>
      <div class="angled-bottom">
        <div class="footer--column">
          <h3>Sitemap</h3>

        </div>
        <div class="footer--column">
          <h3>Connect</h3>

        </div>
        <div class="footer--column">
          <h3>Recommended Sites</h3>

        </div>
      </div>
    </footer>

Answer №2

To contain the content within the element with a class of .angled-bottom, you can apply the CSS property overflow: hidden;. Additionally, adjusting the height using pseudo elements could also enhance the visual appearance.

:root {
  --dark-purple:    hsla(274, 64%, 10%,  1);
  --med-purple:     hsla(274, 45%, 20%,  1);
  --light-purple:   hsla(274, 45%, 35%,  1);
  --lighter-purple: hsla(274, 45%, 40%,  1);
  --light:          hsla(274, 5%,  95%,  1);
  --grey:           hsla(274, 5%,  55%,  1);
  --dark:           hsla(274, 5%,  5%,   1);
  --vertical-grad:      linear-gradient(180deg, #ff8f3e, #cf132c, #420d6e);
  --vertical-grad-r:    linear-gradient(0deg, #ff8f3e, #cf132c, #420d6e);
  --horizontal-grad:    linear-gradient(90deg, #ff8f3e, #cf132c, #420d6e);
  --horizontal-grad-r:  linear-gradient(270deg, #ff8f3e, #cf132c, #420d6e);
}

body {
  margin: 0;
  z-index: -1;
  margin: 0;
  position: relative;
  background-color: var(--dark-purple);
  font-family: sans-serif;
  font-size: 13pt;
  color: var(--light);
}

.angled-top::before {
  content: '';
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  transform: skewY(-5deg) translateY(-5vw);
  z-index: -1;
  background: linear-gradient(220deg, var(--light-purple), var(--med-purple));
}

.angled-top {
  display: flex;
  padding: 2rem 4rem 9.5vw 4rem;
  justify-content: center;
  position: relative;
}

.angled-bottom::before {
  content: '';
  position: absolute;
  top: 0; right: 0; 
  /* changed */
  bottom: 10vh;
  left: 0;
  transform: skewY(-5deg) translateY(5vw);
  z-index: -1;
  background: linear-gradient(220deg, var(--light-purple), var(--med-purple));
}

.angled-bottom {
  display: flex;
  padding: 9.5vw 4rem 2rem 4rem;
  justify-content: space-around;
  position: relative;

  /* added */
  overflow: hidden;
}

.footer--column:nth-child(2) { transform: translate(0px, -2.5vw); }
.footer--column:nth-child(3) { transform: translate(0px, -5vw); }
<header>
      <div class="angled-top">
        [Header stuff here]
      </div>
    </header>
    
    <main>
      <div style="height: 70vh">... Simulate some large amount of content ...</div>
    </main>

    <footer>
      <div class="angled-bottom">
        <div class="footer--column">
          <h3>Sitemap</h3>

        </div>
        <div class="footer--column">
          <h3>Connect</h3>

        </div>
        <div class="footer--column">
          <h3>Recommended Sites</h3>

        </div>
      </div>
    </footer>

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

Issue with Bootstrap container's max-width not functioning

After implementing the code in the following manner: <link href="css/bootstrap.css" rel="stylesheet" type="text/css"> <link href="css/bootstrap-responsive.css" rel="stylesheet" type="text/css"> <style type="text/css"> .con ...

Updating Django database records with ajax

I'm currently working on a feature that involves filtering table data and updating the table using ajax. Here's what I have so far: Filter Form: <form id="search" method="POST" action="{% url 'article-filter' %}"> <input ...

What's the best way to eliminate letter-spacing only for the final letter of an element using CSS?

Displayed above is the image in question from my HTML page. The text menu is contained within a right-aligned div, with a letter spacing of 1.2em. Is there a way to target this specific element with a pseudo-selector? I'd prefer not to use relative po ...

Embed a static label inside an input field that remains constant even while text is inputted, without using a placeholder. Crafted using HTML,

Take a look at the screenshot below - what you see on the left side is my current setup, while on the right side is the desired outcome achieved without any plugins or HTML5 attributes The left side scenario occurs when I have 2 input fields - one with th ...

Want to learn how to center a webpage only for a specific device width? For example, have your mobile device display the content in the center, while

Hello! I'm new to the world of @media queries and am currently trying to make my webpage responsive by centering it on smaller devices while keeping the display normal on larger screens. My website, mastercontrolunit.com, looks great in deskto ...

What is the best way to center a div vertically inside another div?

Aligning a div element horizontally within another div element is possible by using the margin: 0 auto; property as long as both elements have a specified width other than auto. However, this method does not work for vertical alignment. Is there a way to ...

"Troubleshooting: Difficulty with hover function in jqgrid not functioning on colored rows

My JQGrid setup includes the following: <table id="grid"></table> var data = [[48803, "DSK1", "", "02200220", "OPEN"], [48769, "APPR", "", "77733337", "ENTERED"]]; $("#grid").jqGrid({ datatype: "local", height: 250, colNa ...

The dropdown login form is malfunctioning on my Wordpress website

After reading various tutorials and guides online, I managed to set up a login screen. You can view the code in my jsfiddle: Jsfiddle. Unfortunately, I am facing issues with making the code function correctly. Being new to Jquery, I might have made a begin ...

Replacing elements with preg_replace in HTML including diacritics

Can someone assist me in using preg_replace for the following scenario: <p style="background:white"> <span style="font-size:10.0pt;font-family:&quot;Trebuchet MS&quot;,&quot;sans-serif&quot;"> Coût de la prestation : 43.19 . ...

I would like to create a fixed-position menu similar to Slashdot's comment filtration menu. How can I achieve this?

Have you ever noticed that Slashdot has a cool little feature that lets you adjust your comment threshold to filter out down-modded comments? When you scroll to the top of the page, it stays in one place, but as you continue scrolling down, it eventually s ...

Issue with header background images not showing up in Safari browser

On my website, the top header background and the background of the "Kreation Team" Div are not appearing on Safari for iPads and iPhones, but they are visible on iMacs and MacBooks. The background images do not show up on smaller devices. If you compare C ...

A guide on retrieving all the table data and displaying it in the user interface using templates in Django

I am working on a Django project where I have created a model named "Files" with fields such as Id (auto-generated) and file_name. My goal is to retrieve all file names from the database and display them as a list on the user interface. To achieve this, I ...

The hideCol method does not work on jqGrid

Encountering a problem with the hidecol method in jqGrid. Despite calling the method, nothing seems to happen. Using version 4.5 of jqGrid. The table is created as follows: // Table creation using jqGrid $('#shipTable').jqGrid({ data: tabl ...

Incomplete Loading of Google Maps

Let me clarify that the solutions I have come across so far have not been successful. I am attempting to display a modal alert with a basic Google Maps integration. Problem: Google Maps does not load completely. Snippet from my .js file: var map; functi ...

Annoying div unexpectedly wrapping content after using appendTo

Greetings, esteemed members of the SO community, I am here once again with a question that requires your assistance. Context: I am currently working on a grid system that allows users to drag and drop items onto specific grid fields. When the grid is re ...

Discovering the block's height with the power of Jquery

I have written a piece of code that sets the height of a block of text and then applies that height to an image within the block. However, the size of the image ends up being smaller than the size of the block. https://i.stack.imgur.com/QUFWy.png <scr ...

Switch the designation to Hover Class

I am working with nested divs and have assigned a CSS class to one of the inner divs. How can I trigger the hover effect of the class (class.hover) when the user hovers over the outer div, even if they are not directly over the inner div? I believe this m ...

Guide on how to use JavaScript to swipe through loaded epub files in both lateral directions

Hello everyone, I have a question about implementing swipe functionality on a loaded epub using JavaScript. I successfully loaded the epub into a div and now I need to enable swipe left and right gestures on that div. I found a jQuery script that should a ...

Set the container width to a fixed size, then center a div within it with a dynamic width. Ensure that the left and right div

Arrange three columns with a fixed combined width. The center column will have dynamic content, while the left and right columns should fill out the remaining space equally. For example, see this demonstration: http://jsfiddle.net/htKje/ <div class="c ...

Issue with Bootstrap DIV not extending to full height when applying background-color

I have encountered numerous posts on this topic, but none of the solutions provided have worked for me. I must admit that I struggle to grasp CSS concepts, although I am making an effort to learn. Here is the code I am currently using: <!DOCTYPE html& ...