Sign Up Form

Sign Up

If You want to implement a “sticky border” so there is a border along the edges of the page, even when you scroll ?

765 482 point-admin
  • 0

To create a “fixed border” that remains visible at the edge of the page while scrolling, you can use a combination of CSS properties such as position:fixed and the ::before/::after pseudo elements. Here’s how to achieve this:

 

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sticky Border Example</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="content">
<!-- Your page content goes here -->
<p>Scroll down to see the sticky border in action...</p>
</div>
</body>
</html>

CSS:

  • The ::before and ::after pseudo-elements create the top and bottom borders.
  • Additional ::before and ::after pseudo-elements create the left and right borders.
  • These elements are fixed in position to ensure they stay in place during scrolling.

 

 

body, html {
margin: 0;
padding: 0;
height: 100%;
overflow: auto;
}

.content {
height: 200vh; /* For demonstration purposes */
padding: 20px;
}

body::before, body::after {
content: '';
position: fixed;
width: 100%;
height: 10px;
background-color: black;
z-index: 9999;
}

body::before {
top: 0;
left: 0;
}

body::after {
bottom: 0;
left: 0;
}

body::before, body::after {
content: '';
position: fixed;
height: 100%;
width: 10px;
background-color: black;
z-index: 9999;
}

body::before {
top: 0;
left: 0;
}

body::after {
top: 0;
right: 0;
}

Explanation:

  1. HTML: A simple structure with a div containing the page content.
  2. CSS:
    • The ::before and ::after pseudo-elements create the top and bottom borders.
    • Additional ::before andĀ ::after pseudo-elements create the left and right borders.
    • These elements are fixed in position to ensure they stay in place during scrolling.

With this setup, you’ll have a border around the edges of the page that remains visible as you scroll. Adjust the background-color and dimensions as needed

Leave a Reply

Your email address will not be published.