Unfixed body border encircling my entire webpage

My goal is to have a border around all the content on my page, but I am facing issues with the positioning of the bottom border. I want it to always be at the bottom of the page.

html,
body {
  min-height: 100%;
  height: 100%;
}

body {
  margin: 0;
  padding: 45px;
  min-height: 100%;
  z-index: 1;
}

#barTop,
#barLeft,
#barBottom,
#barRight {
  display: block;
  position: absolute;
  background-color: #f8ee53;
  z-index: 2;
}

#barTop,
#barBottom {
  right: 20px;
  left: 20px;
  height: 25px;
}

#barTop {
  top: 20px;
}

#barBottom {
  bottom: 20px;
}

#barLeft,
#barRight {
  top: 20px;
  bottom: 20px;
  width: 25px;
}

#barLeft {
  left: 20px;
}

#barRight {
  right: 20px;
}
<div id="barTop"></div>
<div id="barRight"></div>
<div id="barBottom"></div>
<div id="barLeft"></div>

Issue: The border on my page does not encompass all of the content. https://i.sstatic.net/2f8Gk.png

Answer №1

discard this :

html,
body {
  min-height: 100%;
  height: 100%;
}

replace it with the following:

body {
    margin: 0;
    padding: 45px;
    min-height: 100%;
    z-index: 1;
}

#barTop, #barLeft, #barBottom, #barRight {
    display: block;
    position: absolute;
    background-color: #f8ee53;
    z-index: 2;
}
#barTop, #barBottom {
    right: 20px;
    left: 20px;
    height: 25px;
}
#barTop {
top: 20px;
}
#barBottom {
    bottom: 20px;
}
#barLeft, #barRight {
    top: 20px;
    bottom:20px;
    width: 25px;
}
#barLeft {
    left: 20px;
}

#barRight {
    right: 20px;
}

Answer №2

To resolve this issue, simply include the following code snippet within your existing body selector:

body {
    box-sizing: border-box;
}

I have created a jsfiddle example to showcase this solution, featuring a black background on the body for better visualization:

Check out the JS Fiddle

Answer №3

The issue stems from the padding applied to the body element. The height calculation does not take this into consideration when set to 100%. To resolve this, you can either remove the padding or follow mtr web's suggestion of adding box-sizing: border-box; to the CSS. Try running the snippet below to see the solution in action.

html,
body {
  min-height: 100%;
  height: 100%;
}

body {
  margin: 0;
  padding: 45px;
  min-height: 100%;
  z-index: 1;
  box-sizing: border-box; 
}

#barTop,
#barLeft,
#barBottom,
#barRight {
  display: block;
  position: absolute;
  background-color: #f8ee53;
  z-index: 2;
}

#barTop,
#barBottom {
  right: 20px;
  left: 20px;
  height: 25px;
}

#barTop {
  top: 20px;
}

#barBottom {
  bottom: 20px;
}

#barLeft,
#barRight {
  top: 20px;
  bottom: 20px;
  width: 25px;
}

#barLeft {
  left: 20px;
}

#barRight {
  right: 20px;
}
<div id="barTop"></div>
<div id="barRight"></div>
<div id="barBottom"></div>
<div id="barLeft"></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

Center the background image and adjust it vertically up or down as needed

I am experiencing an issue with a slider div that has a background image on it. The background image is too large, so it is currently centered. You can see the issue here: http://jsfiddle.net/s5qvY/ <div id="slider"></div><hr><hr>& ...

Develop a dynamic animation using gradient and opacity properties

I'm still getting the hang of HTML, JavaScript, and CSS but I recently made some changes to someone else's code to animate a gradient. The original code used background: rgb, but I switched it to background: rgba. It seems to be working fine, but ...

What methods does DevTools offer for identifying the font used in an SVG?

Can anyone help me identify the font used in an SVG marker displayed on a Google Maps surface? I am specifically referring to the number 9 on a blue marker in this codepen. The label has these properties: label: { text: "9", color: "white", f ...

Darkening the background of HTML and CSS text to black

I'm having trouble removing the black background from the navigation. It doesn't appear to be styled in black when I inspect each element individually. Here is an image showing the issue: https://i.stack.imgur.com/gvbn8.png @charset "UTF-8"; ...

How can I trigger a function by clicking on a link that was generated dynamically with jQuery?

I am dynamically creating multiple <a href="#"></a> elements with dynamically assigned id attributes like <a href="#" id='delete"+id+"'></a>. The IDs generated will be like delete01, delete02, .... I want to trigger a func ...

Separate Your Navbar with Bootstrap 4 Separators

I'm facing a challenge in adding separators within a navigation bar between the navigation items. I am unsure how to evenly space out the padding on these separators next to each navigation item. https://i.sstatic.net/vjYti.png Another issue I encou ...

Find a solution for displaying custom product badges

Having some issues with a custom product badge on my website. I tried adding a new badge (besides "Sale"), but it seems to be displaying in the wrong position. The badge should display as "Choice" on the featured products, so I added this code to the chil ...

Adding spacing breakpoints in Material-UI 5 sx properties

Currently in the process of updating my components to utilize the latest MUI version. I have been converting old classes into the sx props and I find this new styling method to be more readable in my opinion. However, one thing that concerns me is handl ...

Manipulate your table data with jQuery: add, update, delete, and display information with ease

When adding data dynamically to the table and attempting to edit, the checkbox value is not updating. This issue needs to be resolved. You can view the code in action on jsFiddle here on JSFiddle ...

Avoid Scroll Below Stuck Navigation

I've been searching for a solution to my issue for some time now, and while I've come across many articles discussing similar problems, none of them seem to address my specific problem. In my React app, I have a mobile version where users can ta ...

Incorporating various elements within a single column of a table

I have been attempting to include multiple table cells elements beneath each of my heading cells, but I am facing issues in getting it to work properly. For better understanding, this is a screenshot: https://i.sstatic.net/kg2XR.png My goal is to have o ...

Having Trouble with the Background Video Scaling on My HTML Bootstrap Page for Mobile Devices

I have been working on an HTML background video page, and everything seems to be working perfectly on desktop. However, when it comes to mobile, the video does not cover the full screen. Only half of the video is visible on the mobile screen. Here is the ...

Displaying an array of data from a list of arrays in AngularJS' session storage

Whenever a button is clicked, the data will be pushed into an array list and stored in session storage. var data = [ 'name':"name", 'id'=1 ]; var arrayList = new Array; arrayList.push(data); sess ...

Enhancing VueDraggable (sortable.js) with drag out feature

I am currently utilizing VueDraggable for effortless and efficient sorting of elements. However, I am in need of a feature that detects when a dragged element leaves its parent so that a particular function can be executed. To provide some context, think o ...

Highlighted top and bottom borders accenting a vertical list

I am working on a list that contains four items. Each item should have top and bottom borders set to 1px solid grey by default. There is a JavaScript rotator in place that adds a 'highlighted' class to the selected list element, which should have ...

Removing lines of text from the output of a JavaScript retrieval

Currently, I have a working script that retrieves a complete address block to be inserted into a selected field. However, I am now attempting to remove unnecessary parts of the generated text block for better display. This is the code snippet: <script ...

Click the button to add content to the top section of the div using jQuery

Looking for some assistance with a web development issue I'm facing. Here's the scenario: I have two sections on my webpage - TOP and BOTTOM. In the bottom section, there are 3 list records each with a checkbox and button. What I need help with ...

Ways to avoid Parents Click Event from triggering during a Child's (Grandchild's) click event

My parent div has a unique feature where clicking on it reveals one of the child divs, and clicking again toggles the visibility of the child div. Inside this child div, there is a switch toggle that functions as a hidden checkbox. The issue I'm facin ...

Incorporating a hamburger symbol into an established menu for easy navigation

I have come across a tutorial on creating a navigation menu with a logo positioned to the left. However, I now wish to incorporate a hamburger icon for mobile devices and I am unsure about the process. Despite my efforts to find a suitable tutorial onlin ...

Achieving uniform distribution of items within a flex container

I have been struggling since yesterday to make this work. I just can't seem to get these flex items to fill the container equally in width and height. No matter what I try, it's not cooperating. <html> <meta charset="utf-8"> ...