Ways to create a gap between a div and the bottom of a webpage

My div is extending beyond the page height and causing the white spacing underneath to disappear. How can I fix this issue and restore the white spacing?

div {
  background-color: grey;
  position: relative;
  top: 136px;
}
<div>
  <p>Lorem Ipsum<br>Lorem Ipsum<br>Lorem Ipsum<br>Lorem Ipsum<br>Lorem Ipsum<br>Lorem Ipsum<br>Lorem Ipsum<br>Lorem Ipsum<br>Lorem Ipsum<br>Lorem Ipsum<br>Lorem Ipsum<br>Lorem Ipsum<br>Lorem Ipsum<br>Lorem Ipsum</p>
</div>

Please click here for a screenshot showing the issue with the div.

Answer №1

To achieve the desired effect, simply replace the top property with margin-top. This will add space at the top of the element rather than moving the entire div by a certain distance. By using this approach, the positioning is relative to the original flow of the document and does not affect the height of the parent element.

div {
  background-color: grey;
  position: relative;
  margin-top: 136px;
}
<div>
  <p>Lorem Ipsum<br>...</p>
</div>

Answer №2

Simply include 'bottom' and 'top' to position the element absolutely

div {
  background-color: grey;
  position: absoulote;
 bottom: 100px;
top:100px;
}
<div>
  <p>Lorem Ipsum<br>Lorem Ipsum<br>Lorem Ipsum<br>Lorem Ipsum<br>Lorem Ipsum<br>Lorem Ipsum<br>Lorem Ipsum<br>Lorem Ipsum<br>Lorem Ipsum<br>Lorem Ipsum<br>Lorem Ipsum<br>Lorem Ipsum<br>Lorem Ipsum<br>Lorem Ipsum</p>
</div>

Answer №3

By adjusting the top value of an element, you are essentially moving it vertically on the page without affecting its other positioning properties. So, if you have an element that originally had some white space around it and then apply a top value, it will likely shift downwards to cover the empty space. In the provided code snippet, it seems like the element has been moved so far down that it now aligns with the bottom.

The challenge in proposing a solution lies in understanding how your question relates to the screenshot attached. The image displays a div that spans the full height of the window and does not seem to have any top setting at all. Additionally, the properties of #Content are shown in a popup while the Inspector panel highlights the body element selection.

As an initial suggestion, consider inserting a spacer div at the bottom of your content div to create a visible white block there.

div {
  position: relative;
}

.content {
  background-color: grey;
  position: relative;
  top: 136px;
}

.spacer {
  background-color: white;
  height: 60px;
}
<div class="content">
  <p>Lorem Ipsum1<br>Lorem Ipsum2<br>...</p>
  <div class="spacer"></div>
</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

Change the Background of Your Body?

Here's the deal. I'm looking to create a cool effect where the background of the body slowly fades out and changes periodically in a loop using CSS and jQuery. Any suggestions on how I can make this happen? Appreciate your help! ...

Step-by-step guide to implementing a floating action button on the bottom-right corner of a screen using Material-UI in a React application

I have been attempting to place the FloatingActionButton on the bottom right corner of the screen. To achieve this, I am utilizing the following library: http://www.material-ui.com/#/components/floating-action-button import React, { Component } from "reac ...

Repositioning with Flexbox: shifting the middle element to a new line

I have a flex item that contains three divs. ┌────────────────────────────────────────┐ | WRAPPER | | ┌─────────┬─ ...

The functionality of jquery .serialize is not effective when used on forms that are generated dynamically

Currently, I am utilizing Java/Spring within a .jsp file. The issue arises when attempting to dynamically load a form (including form tags) from myForm.jsp into a div in myPage.jsp and making an ajax post call with the data. Upon using jQuery .serialize a ...

What causes absolute positioning to separate each word onto its own line? Is there a solution to this issue?

Why does each word in a child element (class .second) get wrapped onto a new line when using absolute positioning? Is there a way to keep the parent element (class .first) as a round shape, while also ensuring the child element is centered below it and has ...

Styling with CSS: Utilize flexbox to adjust the layout of two elements, ensuring they

Trying to float an image to the right side of a paragraph is proving to be more challenging than anticipated. 100px +-------------------------+ +------------+ | | | | | ...

Is it important that the end date does not exceed the start date?

In my request, the end date cannot be later than the start date. For example, if the start date is 24/4/2017 and the end date is 23/4/2017, the search function should be disabled for the calendar date 23/4/2017. Only dates from 24/4/2017 onwards should be ...

Utilizing /deep/ and the triple greater than symbol (>>>) within Angular 2

After researching the /deep/ and ::shadow selectors, I've come across conflicting information. In a discussion on Stack Overflow: What do /deep/ and ::shadow mean in a CSS selector? It was noted that Chrome has deprecated the /deep/ combinator and i ...

Adding a plethora of HTML using jQuery

Struggling to create a single-page website, I've found myself relying heavily on jQuery's .append function. But surely, there has to be a more efficient method for appending large chunks of code (like tables, graphs, etc.) onto a page. Take this ...

What could be causing my click() function to only work properly after resizing?

It's driving me crazy. The code snippet below works perfectly, but not in my project. Only the code in the resize() function seems to work. When I resize the window, everything functions as expected - I can add and remove the 'open' class by ...

What is the best way to determine the width of tables - in the HTML code or using a CSS class?

I recently came across some advice suggesting that a website should still be able to function properly even if the CSS files are not loaded. What approach do you think would work best in this situation? Would it be more effective to use <table width=50 ...

What is the best way to add a gradient color to the bottom of your content?

Seeking assistance in replicating the unique UI design featured in the image below, taken from a course description section on udemy.com. The goal is to create a gradient effect on specific parts of the content, similar to what is shown in the image. http ...

Achieve a disabled scroll bar feature on Firefox

I am experiencing an issue with a Javascript tabbed dialog where the pages have varying heights. Some of them are larger than the browser window. In Internet Explorer, there is always a scrollbar present on the right side. When it is not needed, it appear ...

Tips for implementing parallax effects in an HTML form

I'm planning to incorporate parallax effects in my web application. I've already tried the link below and it's working well according to my needs. Now, I'm interested in learning how to use an HTML form instead of a background image in ...

Ensure that selected options are unique across multiple selections

Could you help me with a question that involves matching pairs of words in both Russian and English? <div class="form-group" id="question4"> <label for="q4FirstSelectEN">4</label> <div class="row"> <div class="col-lg ...

`A dynamically captivating banner featuring animated visuals created with JQuery`

I am currently in the process of designing a banner for the top of my webpage, but I have yet to come across any code that meets all my requirements. To provide clarification, I have attached an illustration showcasing what I am aiming to achieve. 1) The ...

The first div should be hidden when the toggle is activated

I am currently working on a CRUD project and incorporating some Javascript/JQuery into it. I have a button labeled "Add", which, when clicked, displays a specific div element. However, I'm facing an issue where the div is already visible before the us ...

The components/elements are misaligned and causing interference with each other

Currently, I am in the process of constructing a homepage that requires the display of an image alongside text, paragraphs, buttons, and icons. Here is my goal: https://i.sstatic.net/ib6Xq.png However, this is what I have managed to accomplish so far: h ...

how can I modify the css style of an html element only when a specific sibling is present?

After searching through the MDN CSS documentation, I was unable to find any Combinators that can target the specific element I want to style. /* second-span red when first-span is present */ [first-span] ~ [second-span] { color: red; } /* firs ...

Utilize webdriver to auto-scroll through a list of div tags

Incorporated within this page is a drop-down list created using div tags. When utilizing Selenium, it encounters difficulty discerning elements that are not being displayed and consequently generates an error message. The utilization of a JS code snippet t ...