如何在选定的列表项上绘制倒圆角?

时间:2016-12-29 07:00:04

标签: html css css3 border css-shapes

让我们假设一组一个在另一个之下,由一些边界隔开。

如果我设置其中一个方框,它应该有左上边框半径和左下边框半径

同样对于上面的框,右下边框半径应该在那里不会扰乱边界的流动,并且所选边框下方的框应该具有右上边界半径,而不会干扰边界的流动。

提供图片。

enter image description here

7 个答案:

答案 0 :(得分:2)

试试这个https://plnkr.co/edit/dN4LqEQGIG6hmegl7DRV?p=preview

                .box:nth-child(even){
              border: 1px solid #000;
              border-top-left-radius: 6px;
              border-bottom-left-radius: 6px;
              border-right:none;
              border-top:none;
              border-bottom:none;
            }

            .box:nth-child(odd){
              border: 1px solid #000;
              border-top-right-radius: 6px;
              border-bottom-right-radius: 6px;
              border-left:none;
              margin-left:4px;
            }

答案 1 :(得分:1)

这可以解决您的问题:

div {
  width: 100px;
  height: 40px;
}
.first {
  border-top: 1px solid #000;
  border-right: 1px solid #000;
  border-bottom: 1px solid #000;
}
.second {
  border-right: 1px solid #000;
  border-bottom: 1px solid #000;
  border-bottom-right-radius: 10px;
  width: 92px;
  margin-left: 8px;
}
.third {
  border-left: 1px solid #000;
  border-bottom: 1px solid #000;
  border-top-left-radius: 10px;
  border-bottom-left-radius: 10px;
  width: 92px;
}
.fourth {
  border-right: 1px solid #000;
  border-bottom: 1px solid #000;
  border-top-right-radius: 10px;
}
<div class="first"></div>
<div class="second"></div>
<div class="third"></div>
<div class="fourth"></div>

答案 2 :(得分:1)

这是一种纯粹的css方法来实现这一目标。

此后需要let reader = new FileReader(); function handleDrop(e) { e.preventDefault(); // post `File.type` window.parent.postMessage( e.dataTransfer.files[0].type , window.parent.location.href ); reader.onload = function() { window.parent.postMessage( reader.result , window.parent.location.href , [reader.result] ); } reader.readAsArrayBuffer(e.dataTransfer.files[0]); } 结构:

HTML

在这个技巧中,我们将使用<ul> <li> <span>1</span> </li> <li> <span>2</span> </li> ..... ..... ..... <li> <span>n</span> </li> </ul> :before伪元素来绘制圆形边框。

输出图片:

Output Image

  

注意:如果列表项的高度固定且相同,此方法将起作用。

&#13;
&#13;
:after
&#13;
body {
  background: linear-gradient(lightgreen, green);
  margin: 0;
  min-height: 100vh;
}
ul {
  overflow: hidden;
  list-style: none;
  width: 30%;
  margin: 20px 1%;
  float: left;
  padding: 0;
}
ul li {
  position: relative;
}
ul li:before,
ul .active:after {
  border: solid black;
  border-width: 0 2px 2px 0;
  position: absolute;
  height: 100%;
  bottom: 100%;
  content: '';
  width: 100%;
  right: 0;
}
ul .active:before {
  border-radius: 0 0 5px 0;
  width: calc(100% - 10px);
}
ul .active:after {
  border-radius: 0 5px 0 0;
  border-width: 2px 2px 0 0;
  width: calc(100% - 10px);
  margin-top: -2px;
  bottom: auto;
  top: 100%;
}
ul li:last-child.active:after {
  border-radius: 0;
}
ul .active + li:before {
  display: none;
}
ul .active + li + li:before {
  height: calc(100% - 10px);
}
ul li span {
  padding: 5px 10px;
  position: relative;
  display: block;
  z-index: 5;
}
ul li:first-child span {
  border-top: 2px solid black;
}
ul li:first-child.active span {
  border-top-left-radius: 5px;
}
ul li:last-child span {
  border: solid black;
  border-width: 0 2px 2px 0;
}
ul li:last-child.active span {
  border-width: 0;
}
ul .active + li:last-child span {
  border-right-width: 0;
}
ul .active span:before {
  border: solid black;
  border-width: 2px 0 2px 2px;
  border-radius: 5px 0 0 5px;
  position: absolute;
  content: '';
  width: 10px;
  top: -2px;
  bottom: 0;
  left: 0;
}
&#13;
&#13;
&#13;

答案 3 :(得分:1)

从列表和单个伪,还有一些事情要做:

(为演示添加tabindex,您可以点击或标签浏览项目以查看边框和背景切换)

项目的高度和填充无关紧要,但如果需要,您需要注意半径值和边框厚度,以更新边距和/或协调以匹配使用的值

ul {
  background: linear-gradient(to left, white, #0F4782, #069ED5, white);
  border-bottom: solid;
  padding: 0;
  margin: 0 1em;
}
li {
  display: block;
  border: solid;
  border-left: none;
  border-bottom: none;
  padding: 0.5em;
}
li:focus,
li:active {
  outline: none;
  border: solid;
  border-right: none;
  position: relative;
  left: -.5em;
  margin-top: 3px;
  margin-bottom: -3px;
  border-radius: 0.5em 0 0 0.5em;
  background: linear-gradient(to right, tomato, white)
}
li:focus + li,
li:active + li {
  border-radius: 0 0.75em;
}
li:focus:before,
li:active:before {
  content: '';
  border-radius: 0.75em;
  border: solid transparent;
  border-bottom: solid;
  position: absolute;
  right: -8px;
  bottom: 100%;
  height: 0.75em;
  width: 0.75em;
  transform: rotate(-45deg);
  ;
}
li:focus i, li:active i {display:none;}
li:focus:after,
li:active:after {
  content: '> focused';
  font-weight:bold;
  }
<ul>
  <li tabindex="0">item <i>click me</i></li>
  <li tabindex="0">item<br/>  <i>click me</i></li>
  <li tabindex="0">item <i>click me</i></li>
  <li tabindex="0">item <i>click me</i></li>
  <li tabindex="0">item <i>click me</i></li>
  <li tabindex="0">item <i>click me</i></li>
</ul>

答案 4 :(得分:0)

&#13;
&#13;
.box{
  width:300px;
  height:30px;
  border:2px solid #000;
  display:block;
  overflow:hidden;
  margin-left:10px;
  }
#one,#two,#four{
  
  border-left:none;
  
  }
#two{
  border-bottom-right-radius:20px;
  }
#one,#three{
  border-bottom:none;
  }
#three{
  border-top:none;
  border-right:none;
  border-bottom-left-radius:20px;
  border-top-left-radius:20px;
  margin-left:0px;
  width:40px;
  }
#four{
  border-top-right-radius:20px;
  }
&#13;
<div id="one" class="box"></div>
<div id="two" class="box"></div>
<div id="three" class="box"></div>
<div id="four" class="box"></div>
&#13;
&#13;
&#13;

答案 5 :(得分:0)

ul {
  list-style: none;
}
li {
  padding:20px;
}
li:nth-child(1) {
  border-right: 1px solid #000;
  border-top: 1px solid;
  border-bottom: 1px solid;
}
li:nth-child(2) {
  border-right: 1px solid #000;
  border-bottom: 1px solid;
  border-bottom-right-radius: 15px;
  margin-left: 13px;
}
li:nth-child(3) {
  border-left: 1px solid;
  border-top-left-radius: 15px;
  border-bottom-left-radius: 15px;
  border-bottom: 1px solid;
  margin-right: 13px;
}
li:nth-child(4) {
  border-right: 1px solid #000;
  border-top-right-radius: 15px;
  border-bottom: 1px solid;
}
<ul>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
</ul>

答案 6 :(得分:0)

亲爱的请查看这个片段,我给你完美的形状。这正是您需要检查的边缘

&#13;
&#13;
.box1 {
	width:300px;
	height:100px;
	border:1px solid #000;
	border-left:0;
	border-right-width:2px;
}
.box2 {
	width:300px;
	height:100px;
	border-right:2px solid #000;
	border-bottom-right-radius:20px;
	border-bottom-left-radius:0px;
	position:relative;
}
.box2::after {
	position:absolute;
	right:-2px;
	width:30px;
	height:30px;
	border-bottom:2px solid #000;
	border-right:2px solid #000;
	border-bottom-right-radius:20px;
	border-bottom-left-radius:0px;
	bottom:0px;
	content:"";
}
.box2::before {
	position:absolute;
	right:16px;
	width:90%;
	height:2px;
	background:#000;
	bottom:0px;
	content:"";
}
.box3 {
	width:281px;
	height:100px;
	border-bottom:2px solid #000;
	border-left:2px solid #000;
	border-top-left-radius:20px;
	border-bottom-left-radius:20px;
	position:relative;
}
.box3::after {
	position:absolute;
	left:-2px;
	width:30px;
	height:30px;
	border-top:2px solid #000;
	border-left:2px solid #000;
	border-top-left-radius:20px;
	border-bottom-left-radius:0px;
	top:-2px;
	content:"";
}
.box4 {
	width:300px;
	height:100px;
	border-bottom:1px solid #000;
	border-right:2px solid #000;
	border-top-left-radius:20px;
	border-top-right-radius:20px;
	position:relative;
}
.box4::after {
	position:absolute;
	right:-2px;
	width:30px;
	height:30px;
	border-top:2px solid #000;
	border-right:2px solid #000;
	border-top-right-radius:20px;
	border-bottom-left-radius:0px;
	top:-2px;
	content:"";
}
&#13;
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
<div class="box4"></div>
&#13;
&#13;
&#13;