【问题标题】:CSS : corner cut div , filled and borderCSS : 切角 div , 填充和边框
【发布时间】:2022-01-24 05:17:27
【问题描述】:

我尝试创建这两个切角 div,一个是填充的,另一个是边框,都带有阴影。

但是我面临一个问题,即边框形状角,我无法创建带有切角的边框。

我很欣赏创建这种填充形状和边框形状的任何其他想法。

.buttongroup {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
      -ms-flex-align: center;
          align-items: center;
}

.buttongroup .gap {
  width: 30px;
  -webkit-box-flex: 0;
      -ms-flex: none;
          flex: none;
}

.neonbutton {
  display: -webkit-inline-box;
  display: -ms-inline-flexbox;
  display: inline-flex;
  width: 100%;
  position: relative;
}

.neonbutton .l {
  width: 100%;
  height: auto;
  background-color: #37E8FC;
}

.neonbutton .r {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
      -ms-flex-direction: column;
          flex-direction: column;
  -webkit-box-align: start;
      -ms-flex-align: start;
          align-items: flex-start;
  width: 30px;
  -webkit-box-flex: 0;
      -ms-flex: none;
          flex: none;
}

.neonbutton .corner {
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 25px 0 0 30px;
  border-color: transparent transparent transparent #37E8FC;
}

.neonbutton .square {
  height: 30px;
  width: 30px;
  background-color: #37E8FC;
}

.neonbutton .value {
  position: absolute;
  width: 100%;
  height: 100%;
  text-align: center;
  color: #000;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
      -ms-flex-align: center;
          align-items: center;
  -webkit-box-pack: center;
      -ms-flex-pack: center;
          justify-content: center;
  font-size: 17px;
  font-weight: bold;
}

.neonbutton.outline .l {
  background-color: transparent;
  border: 2px solid #37E8FC;
  border-right: none;
}

.neonbutton.outline .corner {
  background-color: transparent;
}

.neonbutton.outline .square {
  background-color: transparent;
  border-right: 2px solid #37E8FC;
  border-bottom: 2px solid #37E8FC;
}
<div class="buttongroup">
  <div class="neonbutton">
    <div class="l"></div>
    <div class="r">
      <div class="corner"></div>
      <div class="square"></div>
    </div>
    <div class="value">Lorem</div>
  </div>
  <div class="gap"></div>
  <div class="neonbutton outline">
    <div class="l"></div>
    <div class="r">
      <div class="corner"></div>
      <div class="line"></div>
      <div class="square"></div>
    </div>
    <div class="value">Lorem</div>
  </div>
</div>

【问题讨论】:

  • 你为了得到影子做了什么?
  • @AHaworth 嗨,我没有尝试过阴影,但目前面临的问题是整个形状,我的 sn-p 显示我仍然能够创建填充形状,但是对于边框形状,我不知道制作角落,但如果您有任何建议或简单的方法来创建这两个形状,我很感激,thx
  • 您可以使用单个 div 完成所有这些操作(最初我假设您需要伪前/后内容,但它更简单)stackoverflow.com/a/65759042/1238244
  • @lharby 嗨,我认为大多数示例都无法添加阴影
  • 哦,我明白了,对不起,也许使用伪元素是可能的。但不能 100% 确定,该线程中还有其他答案可能会有所帮助。

标签: html css


【解决方案1】:

我会像下面那样做第一个:

.box {
  --c:20px; /* control the cut */
  font-size: 25px;
  padding: 10px 30px;
  display: inline-block;
  position: relative;
  z-index: 0;
  filter: drop-shadow(0 0 5px #37E8FC)
}

.box:before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0;
  background: #37E8FC;
  clip-path: polygon(0 0, calc(100% - var(--c)) 0, 100% var(--c), 100% 100%, 0 100%);
}

body {
  background: #000;
}
&lt;div class="box"&gt;some text&lt;/div&gt;

第二个:

.box {
  --b:5px;  /* control the border */
  --c:20px; /* control the cut */
  font-size: 25px;
  padding: 10px 30px;
  display: inline-block;
  position: relative;
  color:#fff;
  z-index: 0;
  filter: drop-shadow(0 0 5px #37E8FC)
}

.box:before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0;
  background: linear-gradient(to bottom left, #37E8FC 50%,#0000 50.5%) 100% 0/calc(var(--c) - 0.3*var(--b)) calc(var(--c) - 0.3*var(--b)) no-repeat;
  border:var(--b) solid #37E8FC;
  clip-path: polygon(0 0, calc(100% - var(--c)) 0, 100% var(--c), 100% 100%, 0 100%);
}

body {
  background: #000;
}
&lt;div class="box"&gt;some text&lt;/div&gt;

【讨论】:

    猜你喜欢
    • 2012-01-13
    • 1970-01-01
    • 2021-02-06
    • 2014-03-24
    • 1970-01-01
    • 2016-04-12
    • 2016-12-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多