css 有圆角和三角形的形状

balp4ylt  于 2023-06-25  发布在  其他
关注(0)|答案(2)|浏览(104)

我需要做一个形状像下面的图片使用CSS。角落里会有一个数字,里面会有内容。请告诉我怎么做?

我只能这样做:

.container {
  position: relative;
  width: 200px;
  height: 200px;
  background-color: #f2f2f2;
  border-top-right-radius: 80px;
  border-bottom-left-radius: 80px;
}

.background {
  position: relative;
  top: -20px;
  left: -20px;
  width: 0;
  height: 0;
  border-top: 100px solid red;
  border-right: 100px solid transparent;
}

.number {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  color: #ffffff;
  font-size: 24px;
}
<div class="container">
  <div class="background">
    <span class="number">1</span>
  </div>
</div>
w8rqjzmb

w8rqjzmb1#

试试这个基本上它就是一个有一个圆角的正方形。然后,两个成Angular 的部分是::before::after元素旋转并手动放置。它不是完美的,但它接近。

body{padding:2rem; background-color: #333;}

.container {
  position: relative;
  width: 200px;
  height: 200px;
  background-color: #FCFCFC;
  border-top-right-radius: 80px;
  border-bottom-left-radius: 80px;
}

.shape {
    position: relative;
    left: -20px;
    top: -20px;
    background: #b43b41;
    width: 100px;
    height: 100px;
    border-bottom-right-radius: 100%;
}

.shape::before,
.shape::after {
  display: block;
  content: ' ';
  background: #b43b41;
  width: 30px;
  height: 30px;
  transform: rotate(45deg);
  position: absolute;
  z-index: -1;
}

.shape::before {
  top: 6.5px;
    right: -14px;
}

.shape::after {
  bottom: -14px;
  left: 6.5px;
}

.number {
  position: absolute;
  top: -10px;
  left: -10px;
  color: #fff;
  font-size: 24px;
  width: 35px;
  text-align: center;
}
<div class="container">
  <div class="shape"></div>
  <div class="number">1</div>
</div>
n8ghc7c1

n8ghc7c12#

这是一个相当接近的版本。这里肯定有一些“神奇的数字”,但视觉上非常接近。

body {
  font-family: sans-serif;
  background: #25272b;
  padding: 40px;
}

.shape {
  position: relative;
  width: 380px;
  height: 300px;
  border-radius: 0 140px;
  background: #fff;
}

.shape__accent {
  position: absolute;
  top: -15px;
  left: -15px;
  width: 140px;
  height: 140px;
  border-radius: 0 0 130px 0;
  background: #b43b41;
}
.shape__accent:before, .shape__accent:after {
  position: absolute;
  width: 0;
  height: 0;
  border-top: 11px solid transparent;
  border-bottom: 11px solid transparent;
  transform: rotate(-45deg);
  content: "";
}
.shape__accent:before {
  top: 0;
  right: -9px;
  border-right: 11px solid #b43b41;
}
.shape__accent:after {
  bottom: -15px;
  left: 6px;
  border-left: 11px solid #b43b41;
}

.shape__content {
  position: relative;
  font-size: 30px;
  color: #fff;
}
<div class="shape">
  <div class="shape__accent"></div>
  <span class="shape__content">13</span>
</div>

Codepen版本:https://codepen.io/seanstopnik/pen/ZEmBJrL/e14888d3196306b79a82cfecbcb44eb4

相关问题