CSS: Maintain rounded corners on body border even when scrolling

I am attempting to create a body border on my webpage with rounded corners at the top to simulate the MacOS interface in the browser, similar to the image shown here:

https://i.sstatic.net/ECSU9.jpg

The issue arises when I scroll, and the top corners vanish: https://i.sstatic.net/JoVKX.jpg

This is the HTML (although it's in React) that I have:

body:before,
body:after {
  content: "";
  position: fixed;
  background: #900;
  left: 0;
  right: 0;
}

body:before {
  border-top-left-radius: 5px;
  border-top-right-radius: 5px;
  height: 20px;
  top: 0;
}

body:after {
  bottom: 0;
  height: 10px;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  border-left: 10px solid #900;
  border-right: 10px solid #900;
  border-top-left-radius: 5px;
  border-top-right-radius: 5px;
}
<div class="App">
  <div class="App-header">
    <span class="term-name">
          Header Title
        </span>
  </div>
  <div class="container">
    <p></p>
  </div>
</div>

CSS is not my strong suit, and I am having difficulty figuring out how to achieve this...

Answer №1

To achieve an elegant border effect on both sides of a webpage, you can utilize linear gradient backgrounds and set them as fixed to prevent scrolling:

body:before,
body:after {
  content: "";
  position: fixed;
  background: #900;
  left: 0;
  right: 0;
}

body:before {
  border-top-left-radius: 5px;
  border-top-right-radius: 5px;
  height: 20px;
  top: 0;
}

body:after {
  bottom: 0;
  height: 10px;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  border-top-left-radius: 5px;
  border-top-right-radius: 5px;
  background: linear-gradient(to right, #900 10px, transparent 10px, transparent calc(100% - 10px), #900 calc(100% - 10px)) no-repeat fixed;
  background-position: 0 10px;
}

.container {
  height: 200vh;
  padding: 0 2em;
}
<div class="App">
  <div class="App-header">
    <span class="term-name">
          Header Title
        </span>
  </div>
  <div class="container">
    (Content here)
  </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

The justify-content-sm-center behavior in Bootstrap seems to be malfunctioning

I am facing an issue with justify-content-sm-center in Bootstrap 5. It is not functioning as intended when trying to center a specific div on smaller screens (below 578px). I have applied the justify-content-sm-center class to the div, but it does not work ...

How to continuously animate images in HTML using Bootstrap

I want to showcase 7-8 client images in a continuous loop using a <marquee> tag. The issue is that there is a gap between the last and first images. Here is the HTML code I have: <marquee> <ul> <li><a href="#&q ...

How can the hreflang tag be used correctly in a React application that supports multiple languages?

I have a React application with 3 pages(routes) and I support 2 languages (English and Spanish). Should I insert the following code into the <head></head> section of the public\index.html file like this? <link rel="alternate" ...

Exploring the various methods of setting up a Create React App project with TypeScript

One of my old books from a year ago mentioned... npx create-react-app XXX --typescript But looking at the current Create React App documentation, it says... npx create-react-app XXX --template typescript They both seem to yield the same result. Is ther ...

What are some techniques for disguising text on a website to give the illusion of being in English but is actually impossible to read

I am seeking a way to obscure text by rendering it completely unintelligible. While this task is easily accomplished in handwriting, I require a method for achieving this on a webpage using the Verdana font. One idea I had was to create a Verdana-style f ...

The drop-down tabs are being covered by my <div> element

I've been struggling with the layout of my website due to issues with the positioning of my div tags. Whenever I hover over the arcade tab or other drop-down menus, they end up behind the div for my movies. I would like to reverse this behavior so tha ...

Results don't align with search parameters

const searchClientes = (event) => { if (event.target.value === '') { getClientes(); return; } else { const searchTerm = event.target.value; const filteredClients = clientes.filter(cliente => { return cliente.nome ...

The art of CSS Absolute Positioning and the Science of Body Sc

I'm trying to position an absolute div in the bottom right corner of a page. .absolute{ position: absolute; right:0; bottom: 0; } While this code works, I've noticed that when scrolling the page, the right/bottom position is relative t ...

An error occurred when attempting to run the command npm run compile:sass, displaying the message: npm ERR! missing script:

Everything seems to be in place with the sass folders and files, so what could be the issue? I have my package.json file set up correctly with the following code: { "name": "starter", "version": "1.0.0", " ...

"Unlocking the Dialog Box: A Step-by-Step Guide to Programatically Opening Material UI Dialog

Typically, Material UI's Dialog is used as shown below, following the documentation: export default function AlertDialog() { const [open, setOpen] = React.useState(false); const handleClickOpen = () => setOpen(true); const handleClose = () =& ...

Tips on adjusting the size of a Materialize CSS datepicker to perfectly fit within a card

Currently, I am developing a login page in html utilizing the materialize css framework. In my design, I created a card where Login and Register are displayed as tabs within the card. However, one of the forms includes a datepicker from materialize which ...

Avoiding the Maximum update depth exceeded error in ReactjsWays to prevent

Trying to incorporate CSV content into a ReactJS application using the code below. Upon button click, an API call is made to retrieve the response, which needs to be displayed in table format and saved upon submission. Response retrieval and saving functio ...

Using DraftJS to swap text while preserving formatting

Currently, I am implementing Draftjs with draft-js-plugins-editor and utilizing two plugins: draft-js-mathjax-plugin and draft-js-mention-plugin My goal is to replace all mentions with their corresponding values when the user uses '@' to mention ...

I have encountered an issue with my component and I am seeking assistance to identify the problem

Having an issue with my custom "hello world" component. 'Message' is not a valid JSX element type. Its type '() => void' cannot be used as a JSX component. Type '() => void' is not compatible with '(props: any ...

Guide for using JavaScript to obtain the current line position within a contenteditable div during a keypress event

I am in the process of developing a customized editor using a contenteditable div. I require a javascript code that can determine the line position of the current caret position during a keypress event. It should be able to adapt when new lines are added o ...

Ways to fix a proxy issue within a React.js and Express application

My code is showing an error message: Error: Proxy error - Unable to proxy request /AppManager.jsx. Visit https://nodejs.org/api/errors.html#errors_common_system_errors for more details (ECONNREFUSED). react-dom.development.js:199 GET http://localhost ...

Error: Unable to locate module @emotion/react/

While working on my MERN stack project, I faced an issue when proxying the frontend to backend on localhost. Everything was running smoothly until I stopped the react application to install some modules. Upon restarting with the npm start command, a series ...

Can Bootstrap be configured to use a single resolution exclusively?

Uncertain about the feasibility, I am initiating this inquiry. Can Bootstrap be utilized solely with one resolution (Medium desktop)? This question arises from the fact that the design I possess is catered towards Medium desktop (970px wide). My intentio ...

"What is the best way to retrieve the latest state in the produce function of

Take a look at the below reducer: const initialBaseTestState = { oldValue: "String", something: "String two", }; const baseTest = produce((state = initialBaseTestState, action) => { const { type, data } = action; switch (type) { case SET_VALUE: { ...

Attempting to send JSX as a prop value

IMPORTANT UPDATE: Good news - the code is actually functioning correctly! The issue was caused by a header element obstructing the content, leading to confusion. Apologies for any misunderstandings! I am attempting to pass a simple <p> JSX tag as a ...