I have created a border around the website by using
#top,
#bottom,
#left,
#right {
background: #a5ebff;
position: fixed;
}
#left,
#right {
top: 0;
bottom: 0;
width: 15px;
}
#left {
left: 0;
}
#right {
right: 0;
}
#top,
#bottom {
left: 0;
right: 0;
height: 15px;
}
#top {
top: 0;
}
#bottom {
bottom: 0;
}
<div id="left"></div>
<div id="right"></div>
<div id="top"></div>
<div id="bottom"></div>
Now this is probably a little bit outdate – is there a better, more optimized way to do this?
6
Answers
I would suggest creating a div with the border you need so to avoid creating 4 elements just for this.
This is a lot less code for the same result.
As a sidenote, avoid using css on ids, its better to use a class.
You could simply give the body a border or a wrapping div, no need for four separate elements. Also add
box-sizing: border-box;
.See a simple example below:
Here is a more modern approach using CSS
box-shadow
on thebody
or a containerdiv
.This will create an inset shadow on all four sides of your website, making it look like a border around your content. This way, you don’t need extra
div
elements for the borders. Adjust the pixel values as necessary.This is often called a "holy grail" layout or similar with 5 main sections. Keep or remove those you need. Ugly here just to show what is where.
Using grid layout we can either use names or as I did
grid-column
to put stuff in the grid.I put a comment where the border specific to the question was placed. Note using grid like this avoids the challenges with layout seen by using fixed or other positioning which gets out of hand quickly as the layout grows and this is more responsive on phones etc.
How about this one?
(I’d also like to read comments why this might be no good solution)