我必须像第一个图像一样设置块角。



我使用两个块的:: before和:: after伪元素在额外的内部块的帮助下完成了此操作:

<div class="header__text">
  <p>
    Lorem ipsum
  </p>
</div>




.header__text {
  display: inline-block;
  vertical-align: top;
  margin: 0 auto;
  position: relative;
}

.header__text::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 12px;
  height: 12px;
  border-top: 1px solid rgba(0, 0, 0, 1);
  border-left: 1px solid rgba(0, 0, 0, 1);
}

.header__text::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 12px;
  height: 12px;
  border-top: 1px solid rgba(0, 0, 0, 1);
  border-right: 1px solid rgba(0, 0, 0, 1);
}

.header__text p {
  margin: 0;
  padding: 10px 20px;
  font-family: Arial, sans-serif;
  font-size: 21px;
  line-height: 1.2em;
  font-weight: 400;
  color: #000;
  text-transform: none;
  text-decoration: none;
  letter-spacing: .07em;
  text-align: center;
  position: relative;
}

.header__text p::before {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 12px;
  height: 12px;
  border-bottom: 1px solid rgba(0, 0, 0, 1);
  border-left: 1px solid rgba(0, 0, 0, 1);
}

.header__text p::after {
  content: '';
  position: absolute;
  bottom: 0;
  right: 0;
  width: 12px;
  height: 12px;
  border-bottom: 1px solid rgba(0, 0, 0, 1);
  border-right: 1px solid rgba(0, 0, 0, 1);
}


jsbin link

有没有更好的方法来仅使用css对其样式设置,而无需额外的块,图像或其他辅助功能?只是纯CSS。

谢谢。

最佳答案

您可以使用多个渐变背景图像:



div {
  display: inline-block;
  background-image:
    linear-gradient(90deg, black 12px, transparent 12px, transparent calc(100% - 12px), black calc(100% - 12px)),
    linear-gradient(90deg, black 12px, transparent 12px, transparent calc(100% - 12px), black calc(100% - 12px)),
    linear-gradient(black 12px, transparent 12px, transparent calc(100% - 12px), black calc(100% - 12px)),
    linear-gradient(black 12px, transparent 12px, transparent calc(100% - 12px), black calc(100% - 12px));
  background-size: 100% 1px, 100% 1px, 1px 100%, 1px 100%;
  background-repeat: no-repeat;
  background-position: 0 0, 0 100%, 0 0, 100% 0;
}

p {
  margin: 0;
  padding: 10px 20px;
}

<div><p>Lorem Ipsum</p></div>

关于html - 造型块的四个 Angular ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37537299/

10-09 22:36