You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为网页body添加固定边框:现有方案的优化问询及最终实现

网页边框实现方案优化

我最初用以下代码,通过四个定位固定的div给网页添加边框:

原始实现代码

CSS 代码

#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;
}

HTML 代码

<div id="left"></div>
<div id="right"></div>
<div id="top"></div>
<div id="bottom"></div>

但这个方案略显过时,请问有没有更优的实现方式?


编辑补充:最终采纳方案

由于其他方案存在副作用或不适用于我的站点,我采纳了@Mark Schultheiss的建议,使用如下代码:

基础边框代码

body{
      border: 10px solid black
}

同时为确保上下边框始终可见,添加了如下代码:

body:before{
            top:0
}
body:after{
            bottom:0
}

内容的提问来源于stack exchange,提问作者maw

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 13:10:08