创建对角线 border-radius
Creating diagonal border-radius
在为此寻找解决方案一段时间后,我想到了 none。我想做的是在第一个 li
元素的 top left
角上创建对角线边框。我尝试使用涉及 background
属性 的解决方案,但它没有给我我想要的。此外,它不允许对稍后需要的颜色进行任何操作。
浅蓝色应该是被剪切的边框(而不是被剪切的背景),深灰色应该是 li
的背景。
如何通过 CSS 实现此目的? JS/Jquery 解决方案也可以。
编辑: 看到很多对我的问题的错误解释后,我会稍微澄清一下:
左图是我现在的,右图应该是结果。
.cal-scheme {
width: 100%;
li {
width: calc(100% / 6);
height: 150px;
margin: 0;
padding: 0;
border: $thin-blue;
box-sizing: border-box;
float: left;
&:first-child {
background: linear-gradient(135deg, transparent 20px, $light-blue 0);
border: 0;
}
}
}
如果我理解问题,你需要类似 this
HTML:
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
CSS:
body {
background: darkgrey;
}
li {
display: block;
list-style: none;
width: 200px;
height: 50px;
background: lightblue;
position: relative;
border: 10px solid lightblue;
margin-top: 5px;
}
li:first-child:after {
content: '';
display: block;
width: 0;
height: 0;
border: 15px solid transparent;
border-right-color: darkgrey;
position: absolute;
top: -15px;
left: -15px;
transform: rotate(45deg);
}
更新:
您无法使用 border-radius 实现。只需使用 css 形状,或像这样 updated fiddle
HTML:
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
CSS:
body {
background: darkgrey;
}
li {
display: block;
list-style: none;
width: 200px;
height: 50px;
background: darkgrey;
position: relative;
border: 2px solid lightblue;
margin-top: 5px;
}
li:first-child:after {
content: '';
display: block;
width: 30px;
height: 30px;
background: darkgrey;
border-right: 2px solid lightblue;
position: absolute;
top: -17px;
left: -17px;
transform: rotate(45deg);
}
这样实现怎么样?没有 border-radius
属性
WORKING FIDDLE
还可以查看 The Shapes of CSS 中的 css-tricks。
HTML
<div class="square">
<div class="cut-fold"></div>
</div>
CSS
body {
background: #2D2D2D;
}
.square {
background: #5E9EE8;
position: relative;
width: 300px;
height: 300px;
}
.cut-fold {
background: #2d2d2d;
height: 75px;
position: absolute;
top: -34px;
transform: rotate(45deg);
width: 30px;
}
在为此寻找解决方案一段时间后,我想到了 none。我想做的是在第一个 li
元素的 top left
角上创建对角线边框。我尝试使用涉及 background
属性 的解决方案,但它没有给我我想要的。此外,它不允许对稍后需要的颜色进行任何操作。
浅蓝色应该是被剪切的边框(而不是被剪切的背景),深灰色应该是 li
的背景。
如何通过 CSS 实现此目的? JS/Jquery 解决方案也可以。
编辑: 看到很多对我的问题的错误解释后,我会稍微澄清一下:
左图是我现在的,右图应该是结果。
.cal-scheme {
width: 100%;
li {
width: calc(100% / 6);
height: 150px;
margin: 0;
padding: 0;
border: $thin-blue;
box-sizing: border-box;
float: left;
&:first-child {
background: linear-gradient(135deg, transparent 20px, $light-blue 0);
border: 0;
}
}
}
如果我理解问题,你需要类似 this
HTML:
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
CSS:
body {
background: darkgrey;
}
li {
display: block;
list-style: none;
width: 200px;
height: 50px;
background: lightblue;
position: relative;
border: 10px solid lightblue;
margin-top: 5px;
}
li:first-child:after {
content: '';
display: block;
width: 0;
height: 0;
border: 15px solid transparent;
border-right-color: darkgrey;
position: absolute;
top: -15px;
left: -15px;
transform: rotate(45deg);
}
更新:
您无法使用 border-radius 实现。只需使用 css 形状,或像这样 updated fiddle
HTML:
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
CSS:
body {
background: darkgrey;
}
li {
display: block;
list-style: none;
width: 200px;
height: 50px;
background: darkgrey;
position: relative;
border: 2px solid lightblue;
margin-top: 5px;
}
li:first-child:after {
content: '';
display: block;
width: 30px;
height: 30px;
background: darkgrey;
border-right: 2px solid lightblue;
position: absolute;
top: -17px;
left: -17px;
transform: rotate(45deg);
}
这样实现怎么样?没有 border-radius
属性
WORKING FIDDLE
还可以查看 The Shapes of CSS 中的 css-tricks。
HTML
<div class="square">
<div class="cut-fold"></div>
</div>
CSS
body {
background: #2D2D2D;
}
.square {
background: #5E9EE8;
position: relative;
width: 300px;
height: 300px;
}
.cut-fold {
background: #2d2d2d;
height: 75px;
position: absolute;
top: -34px;
transform: rotate(45deg);
width: 30px;
}