Ian*_*n J 38 html css css-shapes
我想在这张图片上创建形状:
我在这张照片上创建了三角形,并将边距设置为右上角,但我不知道如何让它看起来像左边的div一样,如图所示.
我是否必须"剪切"左侧div以保持其灰色边框并且看起来与绿色三角形分开?
有什么想法怎么做?
编辑:
Dav*_*mas 55
鉴于以下加价,我建议:
#box {
width: 10em;
height: 6em;
border: 4px solid #ccc;
background-color: #fff;
position: relative;
}
#box::before,
#box::after {
content: '';
position: absolute;
top: 0;
right: 0;
border-color: transparent;
border-style: solid;
}
#box::before {
border-width: 1.5em;
border-right-color: #ccc;
border-top-color: #ccc;
}
#box::after {
border-radius: 0.4em;
border-width: 1.35em;
border-right-color: #0c0;
border-top-color: #0c0;
}
Run Code Online (Sandbox Code Playgroud)
CSS:
<div id="box"></div>
Run Code Online (Sandbox Code Playgroud)
您可以将旋转伪元素与overflow:hidden
父元素上的an 结合使用。
从这里您可以使用将伪定位到右上角position:absolute
,您应该很高兴!
div {
height: 250px;
width: 300px;
background: lightgray;
border-radius: 10px;
border: 5px solid dimgray;
position: relative;
overflow: hidden;
margin: 30px auto;
}
div:before {
content: "";
position: absolute;
top: -60px;
right: -60px;
height: 100px;
width: 100px;
background: green;
border: 5px solid dimgray;
transform: rotate(45deg);
}
/***********FOR DEMO ONLY*******************/
html, body {
margin:0;
padding:0;height:100%;
vertical-align:top;overflow:hidden;
background: rgb(79, 79, 79);
background: -moz-radial-gradient(center, ellipse cover, rgba(79, 79, 79, 1) 0%, rgba(34, 34, 34, 1) 100%);
background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%, rgba(79, 79, 79, 1)), color-stop(100%, rgba(34, 34, 34, 1)));
background: -webkit-radial-gradient(center, ellipse cover, rgba(79, 79, 79, 1) 0%, rgba(34, 34, 34, 1) 100%);
background: -o-radial-gradient(center, ellipse cover, rgba(79, 79, 79, 1) 0%, rgba(34, 34, 34, 1) 100%);
background: -ms-radial-gradient(center, ellipse cover, rgba(79, 79, 79, 1) 0%, rgba(34, 34, 34, 1) 100%);
background: radial-gradient(ellipse at center, rgba(79, 79, 79, 1) 0%, rgba(34, 34, 34, 1) 100%);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#4f4f4f', endColorstr='#222222', GradientType=1);
}
Run Code Online (Sandbox Code Playgroud)
<div></div>
Run Code Online (Sandbox Code Playgroud)
在位置相对的容器div中放置两个绝对定位的div。然后使三角形的外部三角形比内部三角形稍大。然后将这些元素放置在容器的右上角。
的HTML
<div class="container">
<div class="inner-triangle"></div>
<div class="outer-triangle"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
的CSS
.container{
border: 2px solid gray;
position: relative;
height: 100px;
}
.inner-triangle{
border-left: 20px solid transparent;
border-right: 20px solid green;
border-bottom: 20px solid transparent;
height: 0;
width: 0;
position: absolute;
right: 0px;
z-index: 2;
}
.outer-triangle{
border-left: 22px solid transparent;
border-right: 22px solid gray;
border-bottom: 22px solid transparent;
height: 0;
width: 0;
position: absolute;
right: 0px;
z-index: 1;
}
Run Code Online (Sandbox Code Playgroud)
JS小提琴: http : //jsfiddle.net/u8euZ/1
归档时间: |
|
查看次数: |
42540 次 |
最近记录: |