当前位置:  开发笔记 > 前端 > 正文

CSS3 - 特殊的边界半径

如何解决《CSS3-特殊的边界半径》经验,为你挑选了1个好方法。

我正在尝试用CSS3制作独特的形状.我正在使用Bootstrap 3网格系统来制作元素的布局.我已经构建了这个形状的大部分,但我不能让border-radius属性在元素内部转动.

形状 : 特别

我已经做了什么:

codepen

CSS:

.test-midbox{
    height: 170px;
    background-color: white ;
    padding-left: 0px;
    padding-right: 0px;
    margin-right: 0;
    margin-left: 0;
    border: solid black 1px;
    top: 20px;

}
.test-inbox{
    margin-right: 0;
    margin-left: 0;
    background-image: url("../images/linux.jpg") !important;
    background-repeat: no-repeat;
    background-position: center;
    background-size: auto 80%;
    height: 170px;
    padding-top:10px;
    padding-left:10px;
    padding-right:10px;
    padding-bottom:40px;
}
.monitor-name:before{
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    z-index: -2;
    display: block;
    height: 100%;
    background: black;
    opacity: 0.7;
    border-bottom-right-radius: 20px;
    border-top-right-radius: 20px;
}
.monitor-name{
    z-index: 100;
    position: absolute;
    height: 40px;
    bottom: 20px;
    text-align: center;
    color: white;
    border:black 1px solid;
    border-left: none;
    border-bottom-right-radius: 20px;
    border-top-right-radius: 20px;
}
.monitor-name-text{
    top:1px;
    text-align: center;
}
.test-puls{
    position: absolute;
    height: 20px;
    padding-left: 0px;
    padding-right: 0px;
    margin-right: 0;
    margin-left: 0;
    border-top: 1px black solid;
    bottom: 15px;
}
.btn-plus{
    border-radius: 0;
}
.btn-cir{
    border: 1px solid black;
    position: absolute;
    height: 40px;
    bottom: 20px;
    padding-left: 0px;
    padding-right: 0px;
}

HTML:

tsdsds

k

Harry.. 5

border-radius会始终只产生一个向外的曲线,它永远不会向内弯曲.因此,单靠它不能用于产生您需要的效果.以下是产生所需效果的几种方法.您可以选择最适合您案例的那个.

我没有使用基于Twitter Bootstrap的标记,但它应该是直接的转换.


使用z-index:

如果所有项目都具有不透明背景(即没有alpha值),则为no.元素是有限的固定数,然后用于z-index将元素定位在彼此的顶部,使得第一个元素位于第二个元素的顶部,而第二个元素依次位于第三个的顶部,依此类推.margin-right还将负数设置为所有元素以产生重叠效果.由于背景是不透明的,因此第一个元素上的边框看起来好像第二个元素具有向内弯曲的边界,依此类推.

注意:根据提供的图像,这似乎不适合您的情况但添加了完整性.

.items {
  position: relative;
  float: left;
  height: 50px;
  width: 200px;
  margin-right: -60px;
  line-height: 50px;
  text-align: center;
  border: 1px solid brown;
}
.elongated-border-curve .items {
  border-radius: 0% 35% 35% 0% / 0% 50% 50% 0%;
}
.shorter-border-curve .items {
  border-radius: 0% 20% 20% 0% / 0% 50% 50% 0%;
}
.items:nth-of-type(n+2) {
  border-left: 0;
  background: wheat;
}
.items:first-of-type {
  background: sandybrown;
  color: white;
  z-index: 3;
}
.items:nth-of-type(2) {
  z-index: 2;  /* lower z-index than first */
}
.items:nth-of-type(3) {
  z-index: 1;  /* lower z-index than second */
}
.items:last-of-type {  /* default z-index 0 */
  border-radius: 0%;
}

/* just for demo */
h3 {
  clear: both;
}
.elongated-border-curve, .shorter-border-curve {
  padding-bottom: 50px;
}
body {
  background: radial-gradient(circle at 50% 50%, aliceblue, mediumslateblue);
  min-height: 500px;
}

With Elongated Border Curves

Item 1
Item 2
Item 3
Item 4

With Shorter Border Curves

Item 1
Item 2
Item 3
Item 4

动态宽度示例:

.items {
  position: relative;
  float: left;
  height: 50px;
  width: 32%;
  margin-right: -10%;
  line-height: 50px;
  text-align: center;
  border: 1px solid brown;
}
.elongated-border-curve .items {
  border-radius: 0% 35% 35% 0% / 0% 50% 50% 0%;
}
.shorter-border-curve .items {
  border-radius: 0% 20% 20% 0% / 0% 50% 50% 0%;
}
.items:nth-of-type(n+2) {
  border-left: 0;
  background: wheat;
}
.items:first-of-type {
  background: sandybrown;
  color: white;
  z-index: 3;
}
.items:nth-of-type(2) {
  z-index: 2;  /* lower z-index than first */
}
.items:nth-of-type(3) {
  z-index: 1;  /* lower z-index than second */
}
.items:last-of-type {  /* default z-index 0 */
  border-radius: 0%;
}

/* just for demo */
h3 {
  clear: both;
}
.elongated-border-curve, .shorter-border-curve {
  padding-bottom: 50px;
}
body {
  background: radial-gradient(circle at 50% 50%, aliceblue, mediumslateblue);
  min-height: 500px;
}

With Elongated Border Curves

Item 1
Item 2
Item 3
Item 4

With Shorter Border Curves

Item 1
Item 2
Item 3
Item 4


使用Box Shadow:

如果所有项目都具有纯色背景(不透明或透明)但是没有.元素要么不是有限的要么是大的(因此使得先前的方法难以采用),box-shadow在伪元素上使用大的扩展半径,如下面的代码片段所示.

当元素具有渐变或图像作为背景时,此方法将不起作用.

.items {
  float: left;
  height: 50px;
  width: 200px;
  margin-right: -60px;
  line-height: 50px;
  text-align: center;
  border: 1px solid brown;
}
.elongated-border-curve .items {
  border-radius: 0% 35% 35% 0% / 0% 50% 50% 0%;
}
.shorter-border-curve .items {
  border-radius: 0% 20% 20% 0% / 0% 50% 50% 0%;
}
.items:first-of-type {
  z-index: 3;
}
.items:nth-of-type(n+2) {
  position: relative;
  border-left: 0;
  overflow: hidden;
}
.items:nth-of-type(n+2):after {
  position: absolute;
  content: '';
  height: 100%;
  width: 100%;
  top: 0px;
  left: -140px;  /* -(parent's margin-right) - width of element */
  z-index: -1;
}
.elongated-border-curve .items:nth-of-type(n+2):after {
  border-radius: 0% 35% 35% 0% / 0% 50% 50% 0%;
}
.shorter-border-curve .items:nth-of-type(n+2):after {
  border-radius: 0% 20% 20% 0% / 0% 50% 50% 0%;
}
.items:last-of-type {
  border-radius: 0%;
}
.opaque-bg .items:first-of-type {
  background: sandybrown;
  color: white;
}
.semi-transparent-bg .items:first-of-type {
  background: rgba(0, 0, 0, 0.5);
  color: white;
}
.opaque-bg .items:nth-of-type(n+2):after {
  box-shadow: 0px 0px 0px 200px wheat;
}
.semi-transparent-bg .items:nth-of-type(n+2):after {
  box-shadow: 0px 0px 0px 200px rgba(127, 127, 127, 0.5);
}

/* just for demo */
h3 {
  clear: both;
}
.opaque-bg, .semi-transparent-bg {
  padding-bottom: 50px;
}
body {
  background: radial-gradient(circle at 50% 50%, aliceblue, mediumslateblue);
  min-height: 500px;
}

Items have a solid opaque background + Elongated Border Curves

Item 1
Item 2
Item 3
Item 4

Items have a solid semi-transparent background + Elongated Border Curves

Item 1
Item 2
Item 3
Item 4

Items have a solid opaque background + Shorter Border Curves

Item 1
Item 2
Item 3
Item 4

Items have a solid semi-transparent background + Shorter Border Curves

Item 1
Item 2
Item 3
Item 4

动态宽度示例:

.items {
  float: left;
  height: 50px;
  width: 32%;
  margin-right: -10%;
  line-height: 50px;
  text-align: center;
  border: 1px solid brown;
}
.elongated-border-curve .items {
  border-radius: 0% 35% 35% 0% / 0% 50% 50% 0%;
}
.shorter-border-curve .items {
  border-radius: 0% 20% 20% 0% / 0% 50% 50% 0%;
}
.items:first-of-type {
  z-index: 3;
}
.items:nth-of-type(n+2) {
  position: relative;
  border-left: 0;
  overflow: hidden;
}
.items:nth-of-type(n+2):after {
  position: absolute;
  content: '';
  height: 100%;
  width: 100%;
  top: 0px;
  left: -69%;  /* -(parent's margin-right) - width of element */
  z-index: -1;
}
.elongated-border-curve .items:nth-of-type(n+2):after {
  border-radius: 0% 35% 35% 0% / 0% 50% 50% 0%;
}
.shorter-border-curve .items:nth-of-type(n+2):after {
  border-radius: 0% 20% 20% 0% / 0% 50% 50% 0%;
}
.items:last-of-type {
  border-radius: 0%;
}
.opaque-bg .items:first-of-type {
  background: sandybrown;
  color: white;
}
.semi-transparent-bg .items:first-of-type {
  background: rgba(0, 0, 0, 0.5);
  color: white;
}
.opaque-bg .items:nth-of-type(n+2):after {
  box-shadow: 0px 0px 0px 999px wheat;
}
.semi-transparent-bg .items:nth-of-type(n+2):after {
  box-shadow: 0px 0px 0px 999px rgba(127, 127, 127, 0.5);
}

/* just for demo */
h3 {
  clear: both;
}
.opaque-bg, .semi-transparent-bg {
  padding-bottom: 50px;
}
body {
  background: radial-gradient(circle at 50% 50%, aliceblue, mediumslateblue);
  min-height: 500px;
}

Items have a solid opaque background + Elongated Border Curves

Item 1
Item 2
Item 3
Item 4

Items have a solid semi-transparent background + Elongated Border Curves

Item 1
Item 2
Item 3
Item 4

Items have a solid opaque background + Shorter Border Curves

Item 1
Item 2
Item 3
Item 4

Items have a solid semi-transparent background + Shorter Border Curves

Item 1
Item 2
Item 3
Item 4

我认为这种box-shadow方法适用于您的情况.如果没有,则唯一的另一种选择是使用SVG.clip-path可以帮助实现这一目标而不使用SVG,但它目前的浏览器支持很差.



1> Harry..:

border-radius会始终只产生一个向外的曲线,它永远不会向内弯曲.因此,单靠它不能用于产生您需要的效果.以下是产生所需效果的几种方法.您可以选择最适合您案例的那个.

我没有使用基于Twitter Bootstrap的标记,但它应该是直接的转换.


使用z-index:

如果所有项目都具有不透明背景(即没有alpha值),则为no.元素是有限的固定数,然后用于z-index将元素定位在彼此的顶部,使得第一个元素位于第二个元素的顶部,而第二个元素依次位于第三个的顶部,依此类推.margin-right还将负数设置为所有元素以产生重叠效果.由于背景是不透明的,因此第一个元素上的边框看起来好像第二个元素具有向内弯曲的边界,依此类推.

注意:根据提供的图像,这似乎不适合您的情况但添加了完整性.

.items {
  position: relative;
  float: left;
  height: 50px;
  width: 200px;
  margin-right: -60px;
  line-height: 50px;
  text-align: center;
  border: 1px solid brown;
}
.elongated-border-curve .items {
  border-radius: 0% 35% 35% 0% / 0% 50% 50% 0%;
}
.shorter-border-curve .items {
  border-radius: 0% 20% 20% 0% / 0% 50% 50% 0%;
}
.items:nth-of-type(n+2) {
  border-left: 0;
  background: wheat;
}
.items:first-of-type {
  background: sandybrown;
  color: white;
  z-index: 3;
}
.items:nth-of-type(2) {
  z-index: 2;  /* lower z-index than first */
}
.items:nth-of-type(3) {
  z-index: 1;  /* lower z-index than second */
}
.items:last-of-type {  /* default z-index 0 */
  border-radius: 0%;
}

/* just for demo */
h3 {
  clear: both;
}
.elongated-border-curve, .shorter-border-curve {
  padding-bottom: 50px;
}
body {
  background: radial-gradient(circle at 50% 50%, aliceblue, mediumslateblue);
  min-height: 500px;
}

With Elongated Border Curves

Item 1
Item 2
Item 3
Item 4

With Shorter Border Curves

Item 1
Item 2
Item 3
Item 4
推荐阅读
跟我搞对象吧
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有