CSS多重边框,类似图像。

huangapple go评论62阅读模式
英文:

CSS multi border like image

问题

请为我建议一个CSS样式,以制作如下边框,非常感谢。

CSS多重边框,类似图像。

英文:

Please suggest me a CSS to make border like below, many thanks

CSS多重边框,类似图像。

答案1

得分: 1

以下是翻译好的部分:

body {
  padding: 30px;
}

.container {
  position: relative;
  padding: 20px;
}

.content-container {
  text-align: center;
  border: 1px solid black;
  padding: 30px;
  position: relative;
  z-index: 2;
}

.box {
  position: absolute;
  z-index: 1;
}

.box-a {
  border-top: 1px solid black;
  border-bottom: 1px solid black;
  top: 0;
  left: 40px;
  right: 40px;
  bottom: 0;
}

.box-b {
  border-left: 1px solid black;
  border-right: 1px solid black;
  top: 40px;
  left: 0;
  right: 0;
  bottom: 40px;
}

.corner {
  width: 40px;
  height: 40px;
}

.corner-top-left {
  top: 0;
  left: 0;
  border-right: 1px solid black;
  border-bottom: 1px solid black;
}

.corner-top-right {
  top: 0;
  right: 0;
  border-left: 1px solid black;
  border-bottom: 1px solid black;
}

.corner-bottom-left {
  bottom: 0;
  left: 0;
  border-right: 1px solid black;
  border-top: 1px solid black;
}

.corner-bottom-right {
  bottom: 0;
  right: 0;
  border-left: 1px solid black;
  border-top: 1px solid black;
}
<div class="container">
  <div class="box box-a"></div>
  <div class="box box-b"></div>
  <div class="box corner corner-top-left"></div>
  <div class="box corner corner-top-right"></div>
  <div class="box corner corner-bottom-left"></div>
  <div class="box corner corner-bottom-right"></div>
  <div class="content-container">
    在这里插入所有您的内容
  </div>
</div>
英文:

This is what I guess, not sure if it is the best way:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

body {
padding: 30px;
}
.container {
position: relative;
padding: 20px;
}
.content-container {
text-align: center;
border: 1px solid black;
padding: 30px;
position: relative;
z-index: 2;
}
.box {
position: absolute;
z-index: 1;
}
.box-a {
border-top: 1px solid black;
border-bottom: 1px solid black;
top: 0;
left: 40px;
right: 40px;
bottom: 0;
}
.box-b {
border-left: 1px solid black;
border-right: 1px solid black;
top: 40px;
left: 0;
right: 0;
bottom: 40px;
}
.corner {
width: 40px;
height: 40px;
}
.corner-top-left {
top: 0;
left: 0;
border-right: 1px solid black;
border-bottom: 1px solid black;
}
.corner-top-right {
top: 0;
right: 0;
border-left: 1px solid black;
border-bottom: 1px solid black;
}
.corner-bottom-left {
bottom: 0;
left: 0;
border-right: 1px solid black;
border-top: 1px solid black;
}
.corner-bottom-right {
bottom: 0;
right: 0;
border-left: 1px solid black;
border-top: 1px solid black;
}

<!-- language: lang-html -->

&lt;div class=&quot;container&quot;&gt;
&lt;div class=&quot;box box-a&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;box box-b&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;box corner corner-top-left&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;box corner corner-top-right&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;box corner corner-bottom-left&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;box corner corner-bottom-right&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;content-container&quot;&gt;
insert here all your content
&lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年5月11日 09:32:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76223565.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定