- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我想要一个如下图所示的 3d 对 Angular 线浮雕按钮:
我的第一个想法是使用阴影,然后使用 ::before
和 ::after
添加两个小三 Angular 形来缩小间隙。
但它总是非常轻微地错位不到 1 个像素(请参见下面的代码片段)。为了更容易编码,我使用了不同的颜色。
.button {
border: 1px solid red;
box-shadow: -10px 10px red;
display: inline-block; margin: 30px; position: relative; outline: none; font-size: 40px;
padding: 10px 30px; background-color: #333; font-weight: 700;
color: white; letter-spacing: 1px;
line-height: 1; text-transform: uppercase; text-align: center;
}
/* create triangle */
.button::before { content: ""; position: absolute;
top: -1px;
left: -11px;
width: 0; height: 0; font-size: 0; line-height: 0%; border-style: solid; border-color: transparent; border-width: 0 0 11px 11px; border-bottom-color: red; }
.button::after { content: ""; position: absolute;
right: -1px;
bottom: -11px;
width: 0; height: 0; font-size: 0; line-height: 0%; border-style: solid; border-color: transparent; border-width: 11px 11px 0 0; border-top-color: red; }
<a class="button">Gallery</a>
有没有比使用三 Angular 形和绝对定位更好的实现方式?
最佳答案
一种解决方案是使用两个成 Angular linear-gradient
strip - 一个在按钮元素的左侧,另一个在按钮元素的底部。
想象一下在伪元素的左上角和右下角放置 10px x 10px 的正方形,这样它的填充在对 Angular 线的一侧是透明的,而在另一侧是彩色的。结果是三 Angular 形。这正是我们在这里使用的方法。
一个伪元素(正方形或矩形)被放置在父元素的后面,三 Angular 形切割是通过使用 Angular 线性渐变产生的。渐变具有 135 度和 315 度的 Angular (这是 45 度线或换句话说正方形/矩形的对 Angular 线)。由于假想正方形的大小为 10px x 10px,对 Angular 线的长度为 14px,因此通过将颜色设置为透明 7px(一半距离)和 hotpink 从 7px(另一半),生成三 Angular 形切割。
以下是执行的步骤:
.button
元素高 10px
和宽 10px
的伪元素,因为投影必须延伸到左侧和底部的元素。左上角
和左下角
上放置 2 个小的linear-gradient
背景条。水平条(左边的那个)的大小设置为 10px 100%
。这是因为左侧浮雕的厚度(只是 strip 的宽度)为 10px
。100% 10px
。同样因为底部的厚度(在本例中,厚度是浮雕的高度)是 10px。135deg
和 315deg
的线性渐变,以便在右下角和左上角看到三 Angular 形切口。梯度内的像素颜色停止点是根据毕达哥拉斯定理计算的。该值为 10px/sqrt(2)。box-shadow: inset 0px 0px 0px 1px hotpink
实现的,因为与额外边框不同,插入阴影不会影响伪元素的定位属性。 .button {
display: inline-block;
margin: 30px;
position: relative;
outline: none;
font-size: 40px;
padding: 10px 30px;
background-color: #333;
font-weight: 700;
color: white;
letter-spacing: 1px;
line-height: 1;
text-transform: uppercase;
text-align: center;
box-shadow: inset 0px 0px 0px 1px hotpink; /* mimics the border */
}
.button:after {
position: absolute;
content: '';
top: 0px;
right: 0px;
height: calc(100% + 10px); /* since projection should extend outside bottom edge */
width: calc(100% + 10px); /* since the projection should extend outside the left edge */
background: linear-gradient(135deg, transparent 7px, hotpink 7px), linear-gradient(315deg, transparent 7px, hotpink 7px);
background-size: 10px 100%, 100% 10px;
background-position: top left, bottom left;
background-repeat: no-repeat;
}
<a class="button">Gallery</a>
<a class="button">Gallery Button Big</a>
注意:同样的方法也可以在没有伪元素的情况下使用,但理解起来会变得更加复杂,因此我将其省略。 Here是一个演示,但可以看出它非常复杂,我建议使用伪元素方法本身。
关于html - CSS - 如何创建对 Angular 线浮雕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37563117/
我正在努力使我的标题具有漂亮的浮雕外观。它在 Chrome 中运行良好,但 Firefox 退出了。我怎样才能使这种效果在两者中都起作用?这是 fiddle : https://jsfiddle.ne
自定义 UIBarButtonItem 有问题。当我通过 创建自定义 UIBarButtonItem 时 [[UIBarButtonItem alloc]initWithImage:[UIImage
在我的 iPhone 应用程序中, 我有一个带有 View 的 ViewController。 请看图片。 这是一个模型。我想要这种弹出式的效果。白色 View 从浅灰色主视图中弹出。我认为这与它的边
我是一名优秀的程序员,十分优秀!