【问题标题】:How do you make a transparent border (with CSS) that goes over a background image?你如何制作一个覆盖背景图像的透明边框(使用 CSS)?
【发布时间】:2015-04-01 22:14:51
【问题描述】:

我想在我的 div 周围制作一个透明的边框。我希望背景图像通过透明边框显示。在我的图片中,您可以看到我的代码创建了一个透明边框,但白色显示通过而不是背景图像。无论我制作什么尺寸的边框,它基本上都会增加空白以适应边框。

以下是我的代码,包括 .mainbody 的边框和背景图片。我在想,也许是我的代码干扰了背景图像上的边框透明度。

.mainbody {
    max-width: 1500px;
    height: auto;
    background: white;
    margin-top: -27px;
    border: 10px dashed rgba(236, 200, 236, .5);
    }

body {
    background: url("https://scenesfromphiladelphia.files.wordpress.com/2010/02/026.jpg");
    background-size: cover;
    background-position: center;
    text-align: left;
    text-indent: 50px;
    color: 000000;
    font-family: Bree Serif;
    max-width: 800px;
    margin: auto;
}

【问题讨论】:

标签: css border background-image transparency


【解决方案1】:

也许对你有帮助

* {
    box-sizing: border-box;
}
.mainbody {
    position: relative;
    max-width: 1500px;
    height: auto;
    padding: 10px;
}
.other {
    border: 10px dashed rgba(236, 200, 236, .5);
    position: absolute;
    background: transparent;
    opacity: .5;
    width: 100%;
    height: 100%;
    left: 0;
    top: 0;
}

body {
    background: url("https://scenesfromphiladelphia.files.wordpress.com/2010/02/026.jpg");
    background-size: cover;
    background-position: center;
    text-align: left;
    text-indent: 50px;
    color: 000000;
    font-family: Bree Serif;
    max-width: 800px;
    margin: auto;
}

还有 HTML:

<body>
  <div class="mainbody">Hello<div class="other"></div></div>
</body>

【讨论】:

  • 这也会影响.mainbody中元素的不透明度。
  • 我不太明白你想要什么,我认为它现在可以工作
猜你喜欢
  • 1970-01-01
  • 2013-02-25
  • 1970-01-01
  • 1970-01-01
  • 2018-10-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多