使用边框的曲线
Curved lines using border
好吧,经过一些调查和寻找解决方案后,我得到了曲线。但它们并不像我想要的那样完美。
想要的效果是这样的:
这是当前效果:
我想知道是否有人对此有更好的解决方案或任何可以达到预期效果的解决方案。
代码如下:
.left-corner-lines {
width: 252px;
float: left;
min-height: 40px;
position: relative;
}
.left-round-line {
border-radius: 0 0 0 100%;
border: 4px solid #fbbc56;
position: absolute;
top: 0;
right: -4px;
}
.left-round-line.yellow-round {
height: 12px;
width: 17px;
border-color: transparent transparent transparent #fbbc56;
}
.left-round-line.blue-round {
height: 21px;
width: 26px;
border-color: transparent transparent transparent #0090d0;
}
.left-round-line.purple-round {
height: 30px;
width: 35px;
border-color: transparent transparent transparent #915da3;
}
.left-round-line.pink-round {
height: 39px;
width: 44px;
border-color: transparent transparent transparent #cc5299;
}
.left-round-line.green-round {
height: 48px;
width: 53px;
border-color: transparent transparent transparent #bed140;
}
<div class="left-corner-lines">
<div class="left-round-line yellow-round"></div>
<div class="left-round-line blue-round"></div>
<div class="left-round-line purple-round"></div>
<div class="left-round-line pink-round"></div>
<div class="left-round-line green-round"></div>
</div>
这是 fiddle:http://jsfiddle.net/84t6w8ca/
必须能够为 4 个可能的方向重新创建所需的效果。
但我现在只需要一个,因为我可以在此基础上重新创建其他的。
我可以为较低版本的浏览器做图像回退,所以不用担心IE8
或更少
有没有人有更好的解决方案可以实现它?
编辑:
我想要更圆润的角效果而不是那么圆..
我想的是 overflow:hidden
正方形,然后将 divs
固定在其中 border-radius
并在 width
和 height
中更大.
我还应该警告您,该行是动态的,具体取决于内容并围绕内容直到页面末尾。此外,它还有来自顶部和底部的线条。像这样:
编辑 2:
@0_o 回答后我尝试使用框阴影,但您会注意到它有点模糊。
示例:
编辑 3:
使用@NileshMahajan 后,我取得了以下成就:
我不知道我的眼睛现在是不是疯了,但这是我最接近的目标。
你也可以使用 box-shadow 来实现这个
.left-corner-lines {
width: 100px;
height: 100px;
position: relative;
overflow: hidden;
}
.left-corner-lines:after {
content: '';
width: 30px;
height: 30px;
right: 0;
margin: -15px -15px 0 0;
border-radius: 50%;
position: absolute;
box-shadow: 0px 0px 0px 5px #fbbc56, 0px 0px 0px 10px #fff, 0px 0px 0px 15px #0090d0, 0px 0px 0px 20px #fff, 0px 0px 0px 25px #915da3, 0px 0px 0px 30px #fff, 0px 0px 0px 35px #cc5299;
}
<div class="left-corner-lines"></div>
请检查更新 fiddle。 https://jsfiddle.net/nileshmahaja/84t6w8ca/3/
我在整个html
中添加了一个容器
<div class="container">
<div class="left-corner-lines">
<div class="left-round-line yellow-round"></div>
<div class="left-round-line blue-round"></div>
<div class="left-round-line purple-round"></div>
<div class="left-round-line pink-round"></div>
<div class="left-round-line green-round"></div>
</div>
</div>
还修改了您的css代码
.container{
position:relative;
width: 200px;
height: 200px;
overflow:hidden;
}
.left-corner-lines {
width: 200px;
left: 50%;
height: 200px;
position: relative;
top:-50%
}
.left-round-line {
border-radius:100%;
border: 5px solid #fbbc56;
position: absolute;
left:0;
right:0;
top:0;
bottom:0;
margin:auto;
}
.left-round-line.yellow-round {
height: 20px;
width: 20px;
border-color:#fbbc56;
}
.left-round-line.blue-round {
height: 40px;
width: 40px;
border-color: #0090d0;
}
.left-round-line.purple-round {
height: 60px;
width: 60px;
border-color: #915da3;
}
.left-round-line.pink-round {
height: 80px;
width: 80px;
border-color: #cc5299;
}
.left-round-line.green-round {
height: 100px;
width: 100px;
border-color: #bed140;
}
如果你想要单色线,你可以在 SVG 中只使用一个路径元素。
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="200" height="200" viewBox="4 5 30 30">
<path d="M5 5 A 25 25 0 0 0 30 30 m0-5 A 20 20 0 0 1 10 5 m5 0 A 15 15 0 0 0 30 20 m0-5 A 10 10 0 0 1 20 5 m5 0 A 5 5 0 0 0 30 10" fill="none" stroke="black" stroke-width="2" />
</svg>
如果你想要不同颜色的段,最好在这里使用圆形元素。
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="100" height="100" viewBox="0 0 30 30">
<defs>
<style>
circle {cx:30; cy:0; stroke-width:2; fill:transparent;}
</style>
</defs>
<circle r="5" stroke="#fbbc56" />
<circle r="10" stroke="#0090d0" />
<circle r="15" stroke="#915da3" />
<circle r="20" stroke="#cc5299" />
<circle r="25" stroke="#bed140" />
</svg>
这里SVG的优点是:
短小精悍
支持所有主流浏览器(和IE8+)对于IE 8-,你可以使用VML作为回退(raphael是一个很好的JS库)
在所有主要浏览器上都没有模糊或锯齿(渐变也是如此)
间隙可以是透明的而不是白色或纯色。这也可以使用渐变来实现
好吧,经过一些调查和寻找解决方案后,我得到了曲线。但它们并不像我想要的那样完美。
想要的效果是这样的:
这是当前效果:
我想知道是否有人对此有更好的解决方案或任何可以达到预期效果的解决方案。
代码如下:
.left-corner-lines {
width: 252px;
float: left;
min-height: 40px;
position: relative;
}
.left-round-line {
border-radius: 0 0 0 100%;
border: 4px solid #fbbc56;
position: absolute;
top: 0;
right: -4px;
}
.left-round-line.yellow-round {
height: 12px;
width: 17px;
border-color: transparent transparent transparent #fbbc56;
}
.left-round-line.blue-round {
height: 21px;
width: 26px;
border-color: transparent transparent transparent #0090d0;
}
.left-round-line.purple-round {
height: 30px;
width: 35px;
border-color: transparent transparent transparent #915da3;
}
.left-round-line.pink-round {
height: 39px;
width: 44px;
border-color: transparent transparent transparent #cc5299;
}
.left-round-line.green-round {
height: 48px;
width: 53px;
border-color: transparent transparent transparent #bed140;
}
<div class="left-corner-lines">
<div class="left-round-line yellow-round"></div>
<div class="left-round-line blue-round"></div>
<div class="left-round-line purple-round"></div>
<div class="left-round-line pink-round"></div>
<div class="left-round-line green-round"></div>
</div>
这是 fiddle:http://jsfiddle.net/84t6w8ca/
必须能够为 4 个可能的方向重新创建所需的效果。
但我现在只需要一个,因为我可以在此基础上重新创建其他的。
我可以为较低版本的浏览器做图像回退,所以不用担心IE8
或更少
有没有人有更好的解决方案可以实现它?
编辑:
我想要更圆润的角效果而不是那么圆..
我想的是 overflow:hidden
正方形,然后将 divs
固定在其中 border-radius
并在 width
和 height
中更大.
我还应该警告您,该行是动态的,具体取决于内容并围绕内容直到页面末尾。此外,它还有来自顶部和底部的线条。像这样:
编辑 2:
@0_o 回答后我尝试使用框阴影,但您会注意到它有点模糊。
示例:
编辑 3:
使用@NileshMahajan 后,我取得了以下成就:
我不知道我的眼睛现在是不是疯了,但这是我最接近的目标。
你也可以使用 box-shadow 来实现这个
.left-corner-lines {
width: 100px;
height: 100px;
position: relative;
overflow: hidden;
}
.left-corner-lines:after {
content: '';
width: 30px;
height: 30px;
right: 0;
margin: -15px -15px 0 0;
border-radius: 50%;
position: absolute;
box-shadow: 0px 0px 0px 5px #fbbc56, 0px 0px 0px 10px #fff, 0px 0px 0px 15px #0090d0, 0px 0px 0px 20px #fff, 0px 0px 0px 25px #915da3, 0px 0px 0px 30px #fff, 0px 0px 0px 35px #cc5299;
}
<div class="left-corner-lines"></div>
请检查更新 fiddle。 https://jsfiddle.net/nileshmahaja/84t6w8ca/3/
我在整个html
中添加了一个容器<div class="container">
<div class="left-corner-lines">
<div class="left-round-line yellow-round"></div>
<div class="left-round-line blue-round"></div>
<div class="left-round-line purple-round"></div>
<div class="left-round-line pink-round"></div>
<div class="left-round-line green-round"></div>
</div>
</div>
还修改了您的css代码
.container{
position:relative;
width: 200px;
height: 200px;
overflow:hidden;
}
.left-corner-lines {
width: 200px;
left: 50%;
height: 200px;
position: relative;
top:-50%
}
.left-round-line {
border-radius:100%;
border: 5px solid #fbbc56;
position: absolute;
left:0;
right:0;
top:0;
bottom:0;
margin:auto;
}
.left-round-line.yellow-round {
height: 20px;
width: 20px;
border-color:#fbbc56;
}
.left-round-line.blue-round {
height: 40px;
width: 40px;
border-color: #0090d0;
}
.left-round-line.purple-round {
height: 60px;
width: 60px;
border-color: #915da3;
}
.left-round-line.pink-round {
height: 80px;
width: 80px;
border-color: #cc5299;
}
.left-round-line.green-round {
height: 100px;
width: 100px;
border-color: #bed140;
}
如果你想要单色线,你可以在 SVG 中只使用一个路径元素。
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="200" height="200" viewBox="4 5 30 30">
<path d="M5 5 A 25 25 0 0 0 30 30 m0-5 A 20 20 0 0 1 10 5 m5 0 A 15 15 0 0 0 30 20 m0-5 A 10 10 0 0 1 20 5 m5 0 A 5 5 0 0 0 30 10" fill="none" stroke="black" stroke-width="2" />
</svg>
如果你想要不同颜色的段,最好在这里使用圆形元素。
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="100" height="100" viewBox="0 0 30 30">
<defs>
<style>
circle {cx:30; cy:0; stroke-width:2; fill:transparent;}
</style>
</defs>
<circle r="5" stroke="#fbbc56" />
<circle r="10" stroke="#0090d0" />
<circle r="15" stroke="#915da3" />
<circle r="20" stroke="#cc5299" />
<circle r="25" stroke="#bed140" />
</svg>
这里SVG的优点是:
短小精悍
支持所有主流浏览器(和IE8+)对于IE 8-,你可以使用VML作为回退(raphael是一个很好的JS库)
在所有主要浏览器上都没有模糊或锯齿(渐变也是如此)
间隙可以是透明的而不是白色或纯色。这也可以使用渐变来实现