html - 使用具有固定边框的背景图像覆盖 body

标签 html css background margin

我有一个小元素,但它给我带来了很多麻烦......

如何使图像和白色边框覆盖视口(viewport),并且边框始终相等?

这是我想要的布局的屏幕转储,使用 Photoshop 创建。

enter image description here

到目前为止我尝试过的 CSS。

body {
    background-repeat: no-repeat;
    background-position: center center fixed;
    background-attachment: fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
    background-image: url(../img/bg_border.jpg);
}

如果您有线索,我们将不胜感激!谢谢!

最佳答案

类似这样的吗?

html, body {
  margin: 0; padding: 0; height: 100%;
}
.wrapper {
    box-sizing: border-box;
    background-repeat: no-repeat;
    background-position: center center fixed;
    background-attachment: fixed;
    background-size: cover;
    background-image: url(http://lorempixel.com/output/nature-q-c-1000-600-1.jpg);
    border: 50px solid white;
    height: 100%;
}
<div class="wrapper"></div>

关于html - 使用具有固定边框的背景图像覆盖 body ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33111125/

相关文章:

javascript - Node.js 和 requirejs 未定义

javascript - `mailto:`在没有邮件客户端的时候有什么作用?

html - 位置和大小

android - 带广告 : It is not recommended to show an interstitial when app is not in foreground

html - 如何防止垂直溢出但允许水平溢出

html - 如何使 "image banner"100% 的视口(viewport)没有边距,以及页面中心的其余部分

html - 用于显示内容的 CSS float 可扩展菜单

html - CSS - 如何设置背景 : position for 2 images beneath it for hover effect?

objective-c - 每十秒检查一次后台状况并发送通知

javascript - javascript/html 中的 Chrome 和 Apple iphone 表情符号