gpt4 book ai didi

jquery - CSS折 Angular 效果透明背景

转载 作者:太空狗 更新时间:2023-10-29 13:10:09 26 4
gpt4 key购买 nike

我有使用 CSS 的折 Angular 代码:

body {
background-color: #e1e1e1
}
.note {
position: relative;
width: 480px;
padding: 1em 1.5em;
margin: 2em auto;
color: #fff;
background: #97C02F;
overflow: hidden;
}
.note:before {
content: "";
position: absolute;
top: 0;
right: 0;
border-width: 0 16px 16px 0;
/* This trick side-steps a webkit bug */
border-style: solid;
border-color: #fff #fff #658E15 #658E15;
/* A bit more verbose to work with .rounded too */
background: #658E15;
/* For when also applying a border-radius */
display: block;
width: 0;
/* Only for Firefox 3.0 damage limitation */
/* Optional: shadow */
-webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, 0.3), -1px 1px 1px rgba(0, 0, 0, 0.2);
-moz-box-shadow: 0 1px 1px rgba(0, 0, 0, 0.3), -1px 1px 1px rgba(0, 0, 0, 0.2);
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.3), -1px 1px 1px rgba(0, 0, 0, 0.2);
}
.note.red {
background: #C93213;
}
.note.red:before {
border-color: #fff #fff #97010A #97010A;
background: #97010A;
}
.note.blue {
background: #53A3B4;
}
.note.blue:before {
border-color: #fff #fff transparent transparent;
background: transparent;
}
.note.taupe {
background: #999868;
}
.note.taupe:before {
border-color: #fff #fff #BDBB8B #BDBB8B;
background: #BDBB8B;
}
<div class="note">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris pulvinar rhoncus risus, vel ornare lacus sagittis sit amet. Duis vel sem magna. Proin pulvinar velit eleifend ligula ultrices vestibulum. Nunc posuere dolor eu mauris feugiat dignissim.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris pulvinar rhoncus risus, vel ornare lacus sagittis sit amet. Duis vel sem magna. Proin pulvinar velit eleifend ligula ultrices vestibulum. Nunc posuere dolor eu mauris feugiat dignissim.</p>
</div>

现在,在真正的行动中,这是有效的,但在顶 Angular 我看到了 white 背景。如何删除白色背景并替换为透明

演示 HERE

最佳答案

使用当前方法可以实现(或模仿)透明度的唯一方法是将 border-color 设置为与页面的 background-color 相同。这是因为代码使用边框技巧来创建折叠效果。但是,当页面背景本身是图像或渐变(基本上不是纯色)时,这种方法不是很有用。

在这种情况下,可以使用 linear-gradient 背景的组合来创建此效果,如下面的代码片段所示。这里使用了三个linear-gradient的组合,它们如下:

  • 一个线性渐变(向左下角倾斜)以产生折叠效果。此渐变具有固定的 16px x 16px 大小。 (注意:我们可以将这个线性渐变移动到一个伪元素,就像在这个答案底部的 box-shadow 版本中一样,但将它保留在父元素中会留下一个伪元素-用于其他用途的元素。)
  • 一个线性渐变,为三 Angular 形左侧提供纯色,从而产生折叠效果。我们正在使用渐变,即使它会产生纯色,因为我们只能在使用图像或渐变时控制背景的大小。此渐变位于 X 轴上的 -16px 处(基本上意味着它将在折叠三 Angular 形所在的位置之前结束)。
  • 另一个类似于上面的渐变,它再次产生纯色,但位于 Y 轴下方 16 像素处(再次忽略折叠三 Angular 形占据的区域)。

这非常复杂,但它可以响应,也可以支持多种颜色和非纯色背景。要为容器或折叠区域使用不同的颜色,只需修改渐变的颜色即可。第一个形成折叠区域,其余形成容器的颜色。

body {
background-image: radial-gradient(circle, #3F9CBA 0%, #153346 100%);
}
.note {
position: relative;
width: 320px;
padding: 1em 1.5em;
margin: 2em auto;
color: #fff;
background: linear-gradient(to bottom left, transparent 50%, #658E15 50%), linear-gradient(to right, #97C02F 99.9%, transparent 99.9%), linear-gradient(to right, #97C02F 99.9%, transparent 99.9%);
background-size: 16px 16px, 100% 100%, 100% 100%;
background-position: 100% 0%, -16px 0%, 100% 16px;
background-repeat: no-repeat;
overflow: hidden;
}
/* Just for demo */

.note {
transition: all 1s;
}
.note:hover {
width: 480px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<div class="note">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris pulvinar rhoncus risus, vel ornare lacus sagittis sit amet. Duis vel sem magna. Proin pulvinar velit eleifend ligula ultrices vestibulum. Nunc posuere dolor eu mauris feugiat dignissim.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris pulvinar rhoncus risus, vel ornare lacus sagittis sit amet. Duis vel sem magna. Proin pulvinar velit eleifend ligula ultrices vestibulum. Nunc posuere dolor eu mauris feugiat dignissim.</p>
</div>


仅供说明:

在下面的代码片段中,我为每个渐变赋予了不同的颜色来说明整个效果是如何实现的。

body {
background-image: radial-gradient(circle, #3F9CBA 0%, #153346 100%);
}
.note {
position: relative;
width: 320px;
padding: 1em 1.5em;
margin: 2em auto;
color: #fff;
background: linear-gradient(to bottom left, transparent 50%, aqua 50%), linear-gradient(to right, chocolate 99.9%, transparent 99.9%), linear-gradient(to right, beige 99.9%, transparent 99.9%);
background-size: 16px 16px, 100% 100%, 100% 100%;
background-position: 100% 0%, -16px 0%, 100% 16px;
background-repeat: no-repeat;
overflow: hidden;
}
/* Just for demo */

.note {
transition: all 1s;
}
.note:hover {
width: 480px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<div class="note">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris pulvinar rhoncus risus, vel ornare lacus sagittis sit amet. Duis vel sem magna. Proin pulvinar velit eleifend ligula ultrices vestibulum. Nunc posuere dolor eu mauris feugiat dignissim.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris pulvinar rhoncus risus, vel ornare lacus sagittis sit amet. Duis vel sem magna. Proin pulvinar velit eleifend ligula ultrices vestibulum. Nunc posuere dolor eu mauris feugiat dignissim.</p>
</div>


多个主题:

这是一个版本,其中包含问题中提供的所有主题(颜色)的示例。

body {
background-image: radial-gradient(circle, #3F9CBA 0%, #153346 100%);
}
.note {
position: relative;
width: 320px;
padding: 1em 1.5em;
margin: 2em auto;
color: #fff;
background-size: 16px 16px, 100% 100%, 100% 100%;
background-position: 100% 0%, -16px 0%, 100% 16px;
background-repeat: no-repeat;
overflow: hidden;
}

.note{
background-image: linear-gradient(to bottom left, transparent 50%, #658E15 50%), linear-gradient(to right, #97C02F 99.9%, transparent 99.9%), linear-gradient(to right, #97C02F 99.9%, transparent 99.9%);
}
.note.red{
background-image: linear-gradient(to bottom left, transparent 50%, #97010A 50%), linear-gradient(to right, #C93213 99.9%, transparent 99.9%), linear-gradient(to right, #C93213 99.9%, transparent 99.9%);
}
.note.blue{
background-image: linear-gradient(to bottom left, transparent 50%, #53A3E7 50%), linear-gradient(to right, #53A3B4 99.9%, transparent 99.9%), linear-gradient(to right, #53A3B4 99.9%, transparent 99.9%);
}
.note.taupe{
background-image: linear-gradient(to bottom left, transparent 50%, #BDBB8B 50%), linear-gradient(to right, #999868 99.9%, transparent 99.9%), linear-gradient(to right, #999868 99.9%, transparent 99.9%);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<div class="note">
<p>Lorem ipsum dolor sit amet </p>
</div>
<div class="note red">
<p>Lorem ipsum dolor sit amet </p>
</div>
<div class="note blue">
<p>Lorem ipsum dolor sit amet </p>
</div>
<div class="note taupe">
<p>Lorem ipsum dolor sit amet </p>
</div>


box-shadow:

如果 box-shadow 还需要折叠区域的效果,我们可以将第一个渐变(创建折叠 Angular 的那个)移动到一个单独的伪元素(:before ) 并向其添加 box-shadow

body {
background-image: radial-gradient(circle, #3F9CBA 0%, #153346 100%);
}
.note {
position: relative;
width: 320px;
padding: 1em 1.5em;
margin: 2em auto;
color: #fff;
background-position: -16px 0%, 100% 16px;
background-repeat: no-repeat;
overflow: hidden;
}
.note:before {
position: absolute;
content: '';
height: 16px;
width: 16px;
top: 0px;
right: 0px;
box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.3), -1px 1px 1px rgba(0, 0, 0, 0.3);
}
.note:before {
background-image: linear-gradient(to bottom left, transparent 50%, #658E15 50%)
}
.note {
background-image: linear-gradient(to right, #97C02F 99.9%, transparent 99.9%), linear-gradient(to right, #97C02F 99.9%, transparent 99.9%);
}
.note.red:before {
background-image: linear-gradient(to bottom left, transparent 50%, #97010A 50%)
}
.note.red {
background-image: linear-gradient(to right, #C93213 99.9%, transparent 99.9%), linear-gradient(to right, #C93213 99.9%, transparent 99.9%);
}
.note.blue:before {
background-image: linear-gradient(to bottom left, transparent 50%, #53A3E7 50%)
}
.note.blue {
background-image: linear-gradient(to right, #53A3B4 99.9%, transparent 99.9%), linear-gradient(to right, #53A3B4 99.9%, transparent 99.9%);
}
.note.taupe:before {
background-image: linear-gradient(to bottom left, transparent 50%, #BDBB8B 50%)
}
.note.taupe {
background-image: linear-gradient(to right, #999868 99.9%, transparent 99.9%), linear-gradient(to right, #999868 99.9%, transparent 99.9%);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<div class="note">
<p>Lorem ipsum dolor sit amet</p>
</div>
<div class="note red">
<p>Lorem ipsum dolor sit amet</p>
</div>
<div class="note blue">
<p>Lorem ipsum dolor sit amet</p>
</div>
<div class="note taupe">
<p>Lorem ipsum dolor sit amet</p>
</div>

关于jquery - CSS折 Angular 效果透明背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32996454/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com