html - 如何在偏移量处向跨度添加边框

标签 html css

我正在努力实现这一目标

enter image description here

但到目前为止我设法做到了这一点

enter image description here

我无法将转换后的正方形定位到左侧,而且我不知道如何创建外边框。

我想给它加一个边距,但没有用。

:root {
  --primary: #0098fa;
  --accent: #effaff;
  --dark: #394e67;
  --darker: #2f3640;
}

.ts-divider {
  position: absolute;
  z-index: 1;
  width: 21px;
  height: 21px;
  transform: translateY(100%);
  color: var(--primary);
}

.ts-divider:after {
  content: '';
  position: absolute;
  z-index: 1;
  width: 100px;
  height: 1px;
  top: 10px;
  background-color: currentColor;
  opacity: .6;
}

.ts-divider span:before {
  width: 70.75%;
  height: 70.75%;
  left: 3px;
  top: 3px;
  border: 1px solid var(--darker);
}

.ts-divider span::after {
  width: 41%;
  height: 41%;
  left: 6px;
  top: 6px;
  background-color: var(--darker);
  content: '';
  position: absolute;
  z-index: 1;
  transform: rotate3d(0, 0, 1, 45deg);
  border: 1px solid var(--primary);
}
<span class="ts-divider">
                    <span></span>
</span>

最佳答案

您可以使用 box-shadow属性有多个边框。您还可以删除 :after 伪元素上的 z-index。我已通过评论突出显示更改。

:root {
  --primary: #7a6450;
  --accent: #effaff;
  --dark: #7a6450;
  --darker: #7a6450;
}

body {
  background: #0e1317;
  display: flex;
  justify-content: center;
}

.ts-divider {
  position: absolute;
  z-index: 1;
  width: 63px;
  height: 63px;
  transform: translateY(100%);
  color: var(--primary);
}

.ts-divider:after {
  content: '';
  position: absolute;
  /* z-index: 1; Removed */
  width: 100px;
  height: 5px;
  top: 17.5px; /* Manual adjustment according to your code */
  background-color: currentColor;
  opacity: .6;
}

.ts-divider span:before {
  width: 70.75%;
  height: 70.75%;
  left: 3px;
  top: 3px;
  border: 1px solid var(--darker);
}

.ts-divider span::after {
  width: 41%;
  height: 41%;
  left: 6px;
  top: 6px;
  background-color: var(--darker);
  content: '';
  position: absolute;
  z-index: 1;
  transform: rotate3d(0, 0, 1, 45deg);
  border: 1px solid var(--primary);
  box-shadow: 0 0 0 5px #0e1317, 0 0 0px 10px var(--darker); /* First box-shdoaw with the background color and second one with the box color. 5 and 10 are values of their spread radius so you can make use of the offset using that. */
}
<span class="ts-divider">
     <span></span>
</span>

关于html - 如何在偏移量处向跨度添加边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67457119/

相关文章:

html - 缩小我的信息框

html - 使用 twitter bootstrap 固定 <code> 元素的宽度

带有百分比 + 静态值的 css

javascript - 根据选择的下拉框更改div

javascript - 从 .html() 中排除一些元素;在 jQuery 中

html - Bootstrap 模式框中的关闭按钮不起作用

css - 试图在谷歌地图搜索 : difficulty align using css and bootstrap 旁边添加一个按钮

css - 使转换仅以一种方式工作

html - 在同一行上使用 SELECT 和图标进行引导

HTML Div高度问题