带边框的透明三角形
transparent triangle with border
正在尝试创建一个带有彩色边框的透明三角形 div。
css
#down {
display: block;
position: fixed;
left: 0; right: 0;
width: 0; height: 0;
margin: 0 auto;
border-left: 55px solid transparent;
border-right: 55px solid transparent;
z-index: 20;
bottom: 0;
border-bottom: 55px solid rgba(250,250,250,0.75);
}
将一个 div 放在另一个 div 之上会破坏透明度
这通常是通过边框技巧完成的,而这些技巧对此并没有多大帮助
为此你需要其他技巧。
例如,看这个CSS
body {
background: linear-gradient(90deg, lightblue, yellow)
}
.trapezoid {
left: 50px;
top: 50px;
position: absolute;
height: 100px;
width: 500px;
background-color: transparent;
}
.trapezoid:before {
content: '';
width: 57%;
height: 100%;
left: -4%;
position: absolute;
border-color: red;
border-style: solid;
border-width: 3px 0px 3px 3px;
-webkit-transform: skewX(-20deg);
}
.trapezoid:after {
content: '';
width: 59%;
height: 100%;
right: -4%;
position: absolute;
border-color: red;
border-style: solid;
border-width: 3px 3px 3px 0px;
-webkit-transform: skewX(20deg);
}
也可以使用渐变and/or变换:
- 左边:正方形+border-top/left+变换+渐变绘制下边框:
- 中间:你的
- 右侧:border-bottom + 三角形顶部边框的渐变
both extra example can hold content 如字体图标/文字/图片.
body {
background:tomato;
}
#rotate {
position:fixed;
border:solid turquoise;
border-bottom:none;
border-right:none;
bottom:7px;
left:calc(50% - 180px);
height:75px;
width:75px;
transform-origin: bottom left;
transform:rotate(45deg);
background:linear-gradient(to bottom right, transparent calc(50% - 3px), turquoise calc(50% - 3px), turquoise 50%, transparent 50% );
}
#bg-gradient {
position:fixed;
bottom:5px;
left: calc(50% + 70px) ;
border-bottom:solid turquoise;
background:linear-gradient(to bottom right, transparent 50%, turquoise 50%, turquoise calc(50% + 3px), transparent calc(50% + 3px) ),linear-gradient(to bottom left, transparent 50%, turquoise 50%, turquoise calc(50% + 3px), transparent calc(50% + 3px) ) right
;
background-repeat:no-repeat;
background-size:50% 100%;
height:55px;
width:110px;
}
#down {
display: block;
position: fixed;
left: 0; right: 0;
width: 0; height: 0;
margin: 0 auto;
border-left: 55px solid transparent;
border-right: 55px solid transparent;
z-index: 20;
bottom: 5px;
border-bottom: 55px solid rgba(250,250,250,0.75);
}
<div id="down"></div>
<div id="rotate"></div>
<div id="bg-gradient"></div>
请注意,底部旋转的正方形可以隐藏一半
这是一个非常简单的解决方案,但它使用 CSS transform
,IE 低于 9.0 不支持。
请记住,这个三角形位于页面的最底部,因此可以使用旋转的正方形。
#down {
display: block;
position: fixed;
left: 0; right: 0;
bottom: -47px;
width: 80px;
height: 80px;
margin: 0 auto;
border: 0;
z-index: 20;
background-color: rgba(250,250,250,0.75);
-ms-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
border: 3px solid #ffaa33;
}
#down-inner { /* Must be rotated back */
width: 100%;
height: 100%;
-ms-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
}
body {
background-color: #e7e7e7;
color: #444444;
font-family: Arial, sans-serif;
}
<div id="down">
<div id="down-inner">A rotated square</div>
</div>
我能够用更少的代码行解决这个问题。
body {
background: url(https://images.unsplash.com/photo-1500390365106-166bb67248d6?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2434&q=80) no-repeat top; background-size: cover;
min-height: 300px;
}
.triangle {
position: absolute;
top: 25%;
left: 30%;
height: 158px;
width: 182px;
background: white;
clip-path: polygon(50% 0%, 0% 100%, 1.75% 100%, 50% 3%, 97.5% 98.35%, 1.75% 98.35%, 1.75% 100%, 100% 100%);
}
<div class="triangle"></div>
这里也展示了六边形版本:
https://codepen.io/smeyer/pen/gOPmxqm
您可以使用数字来改变边框宽度。
正在尝试创建一个带有彩色边框的透明三角形 div。
css
#down {
display: block;
position: fixed;
left: 0; right: 0;
width: 0; height: 0;
margin: 0 auto;
border-left: 55px solid transparent;
border-right: 55px solid transparent;
z-index: 20;
bottom: 0;
border-bottom: 55px solid rgba(250,250,250,0.75);
}
将一个 div 放在另一个 div 之上会破坏透明度
这通常是通过边框技巧完成的,而这些技巧对此并没有多大帮助
为此你需要其他技巧。
例如,看这个CSS
body {
background: linear-gradient(90deg, lightblue, yellow)
}
.trapezoid {
left: 50px;
top: 50px;
position: absolute;
height: 100px;
width: 500px;
background-color: transparent;
}
.trapezoid:before {
content: '';
width: 57%;
height: 100%;
left: -4%;
position: absolute;
border-color: red;
border-style: solid;
border-width: 3px 0px 3px 3px;
-webkit-transform: skewX(-20deg);
}
.trapezoid:after {
content: '';
width: 59%;
height: 100%;
right: -4%;
position: absolute;
border-color: red;
border-style: solid;
border-width: 3px 3px 3px 0px;
-webkit-transform: skewX(20deg);
}
也可以使用渐变and/or变换:
- 左边:正方形+border-top/left+变换+渐变绘制下边框:
- 中间:你的
- 右侧:border-bottom + 三角形顶部边框的渐变
both extra example can hold content 如字体图标/文字/图片.
body {
background:tomato;
}
#rotate {
position:fixed;
border:solid turquoise;
border-bottom:none;
border-right:none;
bottom:7px;
left:calc(50% - 180px);
height:75px;
width:75px;
transform-origin: bottom left;
transform:rotate(45deg);
background:linear-gradient(to bottom right, transparent calc(50% - 3px), turquoise calc(50% - 3px), turquoise 50%, transparent 50% );
}
#bg-gradient {
position:fixed;
bottom:5px;
left: calc(50% + 70px) ;
border-bottom:solid turquoise;
background:linear-gradient(to bottom right, transparent 50%, turquoise 50%, turquoise calc(50% + 3px), transparent calc(50% + 3px) ),linear-gradient(to bottom left, transparent 50%, turquoise 50%, turquoise calc(50% + 3px), transparent calc(50% + 3px) ) right
;
background-repeat:no-repeat;
background-size:50% 100%;
height:55px;
width:110px;
}
#down {
display: block;
position: fixed;
left: 0; right: 0;
width: 0; height: 0;
margin: 0 auto;
border-left: 55px solid transparent;
border-right: 55px solid transparent;
z-index: 20;
bottom: 5px;
border-bottom: 55px solid rgba(250,250,250,0.75);
}
<div id="down"></div>
<div id="rotate"></div>
<div id="bg-gradient"></div>
请注意,底部旋转的正方形可以隐藏一半
这是一个非常简单的解决方案,但它使用 CSS transform
,IE 低于 9.0 不支持。
请记住,这个三角形位于页面的最底部,因此可以使用旋转的正方形。
#down {
display: block;
position: fixed;
left: 0; right: 0;
bottom: -47px;
width: 80px;
height: 80px;
margin: 0 auto;
border: 0;
z-index: 20;
background-color: rgba(250,250,250,0.75);
-ms-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
border: 3px solid #ffaa33;
}
#down-inner { /* Must be rotated back */
width: 100%;
height: 100%;
-ms-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
}
body {
background-color: #e7e7e7;
color: #444444;
font-family: Arial, sans-serif;
}
<div id="down">
<div id="down-inner">A rotated square</div>
</div>
我能够用更少的代码行解决这个问题。
body {
background: url(https://images.unsplash.com/photo-1500390365106-166bb67248d6?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2434&q=80) no-repeat top; background-size: cover;
min-height: 300px;
}
.triangle {
position: absolute;
top: 25%;
left: 30%;
height: 158px;
width: 182px;
background: white;
clip-path: polygon(50% 0%, 0% 100%, 1.75% 100%, 50% 3%, 97.5% 98.35%, 1.75% 98.35%, 1.75% 100%, 100% 100%);
}
<div class="triangle"></div>
这里也展示了六边形版本: https://codepen.io/smeyer/pen/gOPmxqm
您可以使用数字来改变边框宽度。